I would like to disable navigation based on certain condition in my screen so that user stays in the screen without being able to navigate to other screens untill the specific task in the screen has completed. can anyone guide me how do i achieve disabling and enabling navigation conditionally?
I have looked at the documentation here https://reactnavigation.org/docs/preventing-going-back/ but i cannot disable navigation when
i'm using the state variable as condition .
This way only disables back button navigation. i would like to disable the entire navigation(tab navigation etc)
const [hasRecordingStarted, sethasRecordingStarted] = useState(false);
const navigation = useNavigation();
useEffect(() => {
navigation.addListener('beforeRemove', e => {
if (!hasRecordingStarted) {
return;
}
e.preventDefault();
Alert.alert(
'You cannot leave the screen while recording',
'To leave the screen stop and save or discard the route recording',
);
});
}, []);