3

我是 react-native 的新手,我正在做一个react-native 项目,我使用wixreact-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()或者还有其他事情。提前致谢

4

1 回答 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;
}
于 2018-06-11T10:41:49.150 回答