window.addEventListener('beforeunload', function(e) {
// Your logic here
});
window.addEventListener('popstate', function(e) {
// Your logic here
});
import { BackHandler } from 'react-native';
componentDidMount(){
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);
}
componentWillUnmount(){
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
}
handleBackButton(){
// Your custom code...
return true; // This will prevent the regular handling of the back button
}
React.useEffect(
() =>
navigation.addListener('beforeRemove', (e) => {
if (!someCondition) {
// If we don't need to handle the back button, then return
return;
}
// Prevent default behavior of leaving the screen
e.preventDefault();
// Prompt the user before leaving the screen
Alert.alert('Modal title', 'Modal message', [
{ text: "Don't leave", style: 'cancel', onPress: () => {} },
{
text: 'Leave',
style: 'destructive',
onPress: () => navigation.dispatch(e.data.action),
},
]);
}),
[navigation, someCondition]
);
"cmd.exe", "/c"лишние
import subprocess
subprocess.call(["start", '""', "notepad.exe"])
находит в своей необьятной библиотеке подходящий кусок кода и показывает его тебенет, это совершенно не так!
Отсюда, достаточно правильно реализовать выключение питания (правильный порядок отключения пинов - ground, data и power), и все будет нормально.