我是反应原生的新手,我正在研究反应本机项目,我使用 wix 中的react-native-navigation并且没有找到有关如何清除 SplashScreen 的任何解决方案或任何我不需要再次返回的屏幕。
我在2秒后用它来导航。
componentWillMount(){
setTimeout(
() => {
this.props.navigator.push({
screen: 'SampleApp.LoginScreen',
})
}, 2000
);
}
这在我的 index.js
中export function registerScreens() {
Navigation.registerComponent('SampleApp.SplashScreen', () => SplashScreen);
Navigation.registerComponent('SampleApp.LoginScreen', () => LoginScreen);
}
请帮我找到我需要拨打finish()
的解决方案,或者还有别的东西。提前致谢
答案 0 :(得分:1)
你可以试试这个,
import {BackHandler} from 'react-native';
constructor(props) {
super(props)
this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
}
onNavigatorEvent(event) {
switch (event.id) {
case 'willAppear':
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
this.backHandler.remove();
break;
case 'willDisappear':
this.backPressed = 0;
break;
default:
break;
}
}
handleBackPress = () => {
if (this.backPressed && this.backPressed > 0) {
this.props.navigator.popToRoot({ animated: false });
return false;
}
this.backPressed = 1;
this.props.navigator.showSnackbar({
text: 'Press one more time to exit',
duration: 'long',
});
return true;
}