侧面导航菜单中的主页按钮(React Native应用程序)

时间:2018-07-06 18:56:14

标签: javascript reactjs react-native

我正在努力在侧面导航菜单中创建一个主页按钮,以关闭所有打开的堆栈并返回到第一个屏幕。

我的popToTop()功能仅对我而言在选定的屏幕上有效。 有任何想法吗?在DrawerNavigator中,我使用:

contentComponent: navigation => <Button title="Go to home screen" onPress={() => navigation.popToTop()} />

完整代码:

import React from 'react';
import { Text, View, Button } from 'react-native';
import { createDrawerNavigator, createStackNavigator } from 'react-navigation';

class Home_Screen extends React.Component {
  render() {
    return (
      <View>
        <Text>Home_Screen</Text>
        <Button title="Screens_of_Stack" onPress={() => this.props.navigation.navigate('Screens_of_Stack')} />
      </View>
    );
  }
}

class Screens_of_Stack extends React.Component {
  render() {
    return (
      <View>
        <Text>Screens_of_Stack</Text>
        <Button title="Stack_Screen1" onPress={() => this.props.navigation.navigate('Stack_Screen1')} />
        <Button title="Stack_Screen2" onPress={() => this.props.navigation.navigate('Stack_Screen2')} />
      </View>
    );
  }
}

class Stack_Screen1 extends React.Component {
  render() {
    return (
      <View>
        <Text>Stack_Screen1</Text>
      </View>
    );
  }
}

class Stack_Screen2 extends React.Component {
  render() {
    return (
      <View>
        <Text>Stack_Screen2</Text>
      </View>
    );
  }
}

const Topic_Stack = createStackNavigator({
  Screens_of_Stack,
  Stack_Screen1,
  Stack_Screen2,
});

export default CustomDrawer = createDrawerNavigator({
  Home_Screen,
  Topic_Stack
}, {
    contentComponent: navigation => <Button title="Go to home screen" onPress={() => navigation.popToTop()} />
});

谢谢!

0 个答案:

没有答案