首页 文章

如何在react-native-navigation中从堆栈完成SplashScreen

提问于
浏览
2

我是反应原生的新人,我正在 react-native project 工作,我使用react-native-navigationwix 并没有找到任何解决方案如何清除 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() 的解决方案,或者还有别的东西 . 提前致谢

1 回答

  • 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;
    }
    

相关问题