【问题标题】:Navigating to a new view导航到新视图
【发布时间】:2018-07-24 09:50:59
【问题描述】:

如何正确导航到新视图?

应用:

  • TabNavigator(屏幕顶部)
  • StackNavigator(屏幕底部)

我希望在从 StackNavigator 中选择一个按钮后打开一个新屏幕,该屏幕将覆盖整个应用程序。我不想看到 TabNavigator 和 StackNavigator。

在新窗口中,我希望它是带有返回按钮的 NavBar

我正在观看的所有教程都显示了如何在屏幕之间切换,但我找不到上述情况。

我想从主应用程序打开一个新窗口,然后返回它

已编辑:

const TopNavTabs = TabNavigator({
  General: { screen: General },
  Help: { screen: Help },
  Tips: { screen: Tips },
}
});

export const Navigation = StackNavigator(
  {
    Tab: { screen: TopNavTabs },
    Article: { screen: Article },
  }
);

export default class App extends Component{

  render(){
      return(
          <View>
            <View>
              <Navigation navigation={this.props.navigation} />
            </View>
            <View>
              <View>
                <MCIcon name="account"/>
              </View>
              <View>
                <MIcon name="create" onPress={() => this.props.navigation.navigate('Article')} />
              </View>
              <View>
                <FAIcon name="hashtag" />  
              </View>
              <View>
                <FAIcon name="search" />
              </View>
            </View>
          </View>
      )
  }
}

【问题讨论】:

    标签: react-native react-navigation


    【解决方案1】:

    StackNavigator 中添加TabNavigator 喜欢:

    const TopNavTabs = TabNavigator(
      {
       General: { screen: General },
          Help: { screen: Help },
          Tips: { screen: Tips },
      },
      {
        navigationOptions: ({ navigation }) => ({
          tabBarIcon: ({ focused, tintColor }) => {
            const { routeName } = navigation.state;
            let iconName;
            if (routeName === 'Home') {
              iconName = `ios-information-circle${focused ? '' : '-outline'}`;
            } else if (routeName === 'Settings') {
              iconName = `ios-options${focused ? '' : '-outline'}`;
            }
    
            // You can return any component that you like here! We usually use an
            // icon component from react-native-vector-icons
            return <Ionicons name={iconName} size={25} color={tintColor} />;
          },
        }),
        tabBarOptions: {
          activeTintColor: 'tomato',
          inactiveTintColor: 'gray',
        },
        tabBarComponent: TabBarBottom,
        tabBarPosition: 'bottom',
        animationEnabled: false,
        swipeEnabled: false,
      }
    );
    
        export const Navigation = StackNavigator(
          {
            Tab: { screen: TopNavTabs },
            Article: { screen: Article },
          }
        );
    
    
    
        export default class App extends Component{
    
          render(){
              return(
    
                      <Navigation  />
    
              )
          }
        }
    

    【讨论】:

    • 感谢您的提示,但我现在有一个错误_this2.props.navigation.navigate
    • 你能和我分享一下鳕鱼吗?
    • 你的类 App 不在导航中,所以 this.props.navigation 在这里不可用。
    • 这是否意味着在每个选项卡中我需要再次添加带有按钮的底部栏?第二件事是可以摆脱标题在帖子上显示的栏的第一页吗?一开始没有办法回去,也不需要标题。
    • 目前我在顶部TabNavigator 和使用&lt;View&gt; 创建的面板底部。我是否必须创建一个新的TabNavigator 而不是底部的swipeEnable 关闭?它应该正常工作吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-20
    • 2014-02-24
    • 1970-01-01
    • 2014-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多