In my messaging application, I have a variable isBiometricSuccessfull
, when it becomes false
, I route to biometrics screen. It is checked in Home component.
const HomeComponent = () => {
const { isBiometricSuccessfull } = useHomeHook();
const navigation: any = useNavigation();
useFocusEffect(() => {
if (!isBiometricSuccessfull && navigation.isReady()) {
navigation.navigate('biometricsScreen');
}
});
return (
<HomeStackNavigator.Navigator
screenOptions={{
headerShown: false,
animation: 'slide_from_right',
}}>
.
.
.
</HomeStackNavigator.Navigator>
);
};
When I am on biometrics screen I have prevented going back.
useEffect(() => {
BackHandler.addEventListener(ANDROID.hardware.event.hardwareBackPress, preventGoingBack);
return () => {
BackHandler.removeEventListener(ANDROID.hardware.event.hardwareBackPress, preventGoingBack);
};
}, [isBiometricSuccessfull]);
function preventGoingBack(): boolean {
return !isBiometricSuccessfull ? true : false;
}
The issue arises when any other screen is pushed in navigation stack from any other hook.
For example, when user is on biometrics screen and clicks on a message notification from notification panel, it will route the user to chat route.
I want to prevent all type of routing from this biometrics screen.
I also want to resume the routing once isBiometricSuccessfull
becomes true
. Which means, continuing the above example, I want to route to chat once variable is true
.
I have tried these react native navigation events, but these also seems not to pause routing.
Please guide me, please also tell if there possible improvement in my logic.
Thanks.