【问题标题】:How to finish SplashScreen from stack in react-native-navigation如何在 react-native-navigation 中从堆栈中完成 SplashScreen
【发布时间】:2018-11-12 14:21:34
【问题描述】:

我是 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() 的解决方案,或者还有其他问题。提前致谢

【问题讨论】:

标签: android react-native react-native-android wix-react-native-navigation


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-19
    • 2020-11-07
    • 2021-05-29
    • 1970-01-01
    相关资源
    最近更新 更多