更新时间:2023-01-09 23:38:11
您可以检查之前已经关注的屏幕调用警报而不是从导航中检查 routeName
。
You can check for the screen has been focused prior to call the alert instead of checking the routeName
from navigation.
更新后的代码可能如下所示。
the updated code might look like this.
if (this.props.navigation.isFocused()) {
Alert.alert(
"Exit App",
"Do you want to exit?",
[
{
text: "No",
onPress: () => console.log("Cancel Pressed"),
style: "cancel"
},
{ text: "Yes", onPress: () => BackHandler.exitApp() }
],
{ cancelable: false }
);
}