如何在 react-native-navigation 中从堆栈完成 SplashScreen
How to finish SplashScreen from stack in react-native-navigation
我是 react-native 的新手,我正在做一个 react-native 项目,我使用 wix[=26 的 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()
的解决方案,或者还有其他问题。提前致谢
你可以试试这个,
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;
}
我是 react-native 的新手,我正在做一个 react-native 项目,我使用 wix[=26 的 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()
的解决方案,或者还有其他问题。提前致谢
你可以试试这个,
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;
}