我创建了一个有Welcome
个屏幕的项目,导航到MainActivity
个屏幕.我希望当用户点击后退按钮时,它会在MainActivity
而不是Welcome
屏幕上关闭应用程序.我使用react-navigation
库,所以我从Github中寻找一些解决方案.
当我使用https://github.com/react-navigation/react-navigation/issues/295的代码时.我得到了一个错误:
NavigationActions.reset is not a function
我安慰他.日志(log)(导航操作);
显然没有重置.但是为什么其他人都能使用代码呢?
我搞不懂.任何帮助都将不胜感激.提前谢谢.
这是我的欢迎.js:
import React, { Component } from 'react';
import { View, Text, ActivityIndicator } from 'react-native';
import { NavigationActions } from 'react-navigation';
import { connect } from 'react-redux';
import { ColorSetting } from './common/ColorSetting';
import { fetchMainMovieList } from '../actions';
class Welcome extends Component {
static navigationOptions = {
header: null,
};
componentDidMount() {
// call main page data first
this.props.fetchMainMovieList();
this.timer = setTimeout(() => {
this.navigateToMainActivity();
}, 3000);
}
componentWillUnmount() {
// if this.timer existed,then use clearTimeout to remove it.
this.timer && clearTimeout(this.timer);
}
navigateToMainActivity() {
console.log(NavigationActions);
const resetAction = NavigationActions.reset({
index: 1,
actions: [
NavigationActions.navigate({ routeName: 'MainActivity' })
]
});
this.props.navigation.dispatch(resetAction);
}
render() {
return (
<View>
<Text>Three !</Text>
</View>
);
}
}
export default connect(null, { fetchMainMovieList })(Welcome);