未创建React Native标头标题和按钮

时间:2018-08-27 01:47:46

标签: reactjs react-native react-navigation react-native-ios

  

重置堆栈后,不会在标题中创建后退按钮和标题。

     

代码进度如下。

     

StackNavigator-> TabNavigator->重置-> StackNavigator->   TabNavigator-> StackNavigator

     

单击屏幕上的按钮将移至选项卡式屏幕,然后   按下选项卡式屏幕上的按钮将移至其他表格   屏幕。

Navigator.js

const SubScene = createStackNavigator({
 Sub1 = {screen: Sub1},
 Sub2 = {screen: Sub2},
 ...
)

const MainScene = createStackNavigator({
 BottomTab: {screen: BottomTab},
 SubScene: {screen: SubScene},
 ...
)

const SignUpScene = createStackNavigator({
 SignUp: {screen: SignUp},
 }, ...

const SigninScene = createStackNavigator({
 HomeUI: {screen: HomeUI},
 TopTab: {screen: TopTab},
 Screen1: {screen: Screen1},
 SignUpScene: {screen: SignUpScene},
 MainScene: {screen: MainScene},
}, ...

const HomeScene = createStackNavigator({
 SigninScene: {screen: SigninScene},
}, ...

export default class Navigator extends Component {
 render() {
  return(
   <HomeScene />
  );
 }
}

Screen1.js

...
_onPressSubmitButton() {
const resetAction = StackActions.reset({
 index: 0,
 actions: [
  NavigationActions.navigate({routeName: 'MainScene'}))
 ]
})
this.props.navigation.dispatch(resetAction);
...

BottomTab.js

export defaults BottomTab = createMaterialTopTabNavigator({
Sub1: {screen: Sub1, ...}, 
...
})

Sub1.js

...
_onPressBtn(item) {
this.props.navigation.navigate('Sub2', {name: item.name});
...

Sub2.js

...
componentWillMount() {
 const {setParams} = this.props.navigation;
 setParams({name: this.props.name});
}

static navigationOptions = ({navigation}) => {
 const {state} = navigation;
 if (state.params != undefined) {
  return {
   title: state.params.name,
  }
 }
}
...
  

我像sub2.js一样进行,但标题没有改变。另外,搬家   返回this.props.navigation.navigate通常会导致返回   按钮,但不是现在。

0 个答案:

没有答案