Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
make physical back button go to Home screen after upload success
Browse files Browse the repository at this point in the history
  • Loading branch information
haveyaseen committed May 4, 2020
1 parent d5c8b13 commit 6a6cf1c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions App/screens/DataUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {StyleSheet, View, Text} from 'react-native';
import React, {useCallback} from 'react';
import {StyleSheet, View, Text, BackHandler} from 'react-native';
import {useFocusEffect} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
import {RootStackParamList} from 'App/App';
import Header from '../components/Header';
Expand Down Expand Up @@ -28,6 +29,18 @@ export const DataUpload: React.FC<{
}> = ({navigation}) => {
const {t} = useTranslation();

useFocusEffect(
useCallback(() => {
const onBackPress = (): boolean => {
navigation.navigate('Home');
return true;
};
BackHandler.addEventListener('hardwareBackPress', onBackPress);
return (): void =>
BackHandler.removeEventListener('hardwareBackPress', onBackPress);
}, [navigation]),
);

return (
<View style={global.container}>
<Header
Expand Down

0 comments on commit 6a6cf1c

Please sign in to comment.