简体   繁体   English

如何在保持底部导航的同时在组件之间导航?

[英]How to navigate between components while keeping bottom navigation still?

I'm new to React Native. 我是React Native的新手。 And for some practice, I'm doing an app. 对于某些练习,我正在做一个应用程序。 I want to navigate between components while keeping the bottom navigation still. 我想在组件之间导航,同时保持底部导航。

I used the logic of the BottomNavigation from https://callstack.github.io/react-native-paper/bottom-navigation.html . 我使用了来自https://callstack.github.io/react-native-paper/bottom-navigation.html的BottomNavigation的逻辑。

Here is what I've done in MyComponent.js which holds Friend component and Chat component: 这是我在MyComponent.js中所做的,它包含了Friend组件和Chat组件:

import * as React from 'react';
import { BottomNavigation, Text } from 'react-native-paper';
import Friend from './friend';
import Chat from './chat';

export default class MyComponent extends React.Component {
  state = {
    index: 0,
    routes: [
      { key: 'friend', title: 'Friend', icon: 'accessibility' },
      { key: 'chat', title: 'Chat', icon: 'message' },
    ],
  };

  _handleIndexChange = index => this.setState({ index });

  _renderScene = BottomNavigation.SceneMap({
    friend: Friend,
    chat: Chat,
  });

  render() {
    return (
      <BottomNavigation
        navigationState={this.state}
        onIndexChange={this._handleIndexChange}
        renderScene={this._renderScene}
        barStyle={{backgroundColor:"#00b5ec"}}
     />
    );
  }
}

My Router.js file is like this: 我的Router.js文件是这样的:

import React from 'react';
import {Scene,Router,Stack} from 'react-native-router-flux';
import MyComponent from './components/myComponent';


const ReactRouter = () => {
    return (
        <Router>
            <Scene key="Pages">
            <Scene key="MyComponent" component={MyComponent} hideNavBar={true} panHandlers={null} ></Scene> 
            </Scene>
        </Router>
    );
}

export default ReactRouter;

In addition to that let's say we have a component named "FriendDetail". 除此之外,假设我们有一个名为“FriendDetail”的组件。 When a friend is clicked in Friend component, it will be navigated to FriendDetail component. 当朋友在Friend组件中单击时,它将被导航到FriendDetail组件。 Although FriendDetail is not in the SceneMap of the MyComponent.js, I want to show the MyComponent in the bottom. 虽然FriendDetail不在MyComponent.js的SceneMap中,但我想在底部显示MyComponent。 How should i do this? 我该怎么办?

here is react-native-router-flux bottom navigation an example here is my App.js ( every page in this file) 这里是react-native-router-flux底部导航这里的一个例子是我的App.js(这个文件中的每一页)

import React, { Component } from "react";
import { Router, Scene,Actions } from "react-native-router-flux";
import ... pages/screens/components

class App extends Component {


render(){
  return (
    <Router>
      <Scene key="root" >

        <Scene key="page1" component={PAGE_1} />

        <Scene
          key="tabbar"
          swipeEnabled
          tabBarPosition="bottom"
          tabs
          hideNavBar
          type="reset"
          titleStyle={{ color: "red" }}
          tabBarStyle={{ backgroundColor:"blue" , padding: 5 }}
        >

          <Scene
           type="reset"
            key="tabPage1"
            component={TAB_ITEM_1}
            title=TAB_ITEM_1
            icon={TabIcon}
            iconName="home"
            hideNavBar
          />

         <Scene
           type="reset"
            key="tabPage1"
            component={TAB_ITEM_1}
            title=TAB_ITEM_1
            icon={TabIcon}
            iconName="home"
            hideNavBar
          />
          <Scene
           type="reset"
            key="tabPage1"
            component={TAB_ITEM_1}
            title=TAB_ITEM_1
            icon={TabIcon}
            iconName="home"
            hideNavBar
          />

        </Scene>

      </Scene>
    </Router>
  )

}
}
export default App;

also, I have a TabIcon class like this it generates each page icons 另外,我有一个这样的TabIcon类,它会生成每个页面图标

import React, { Component } from "react";
import { Text, View } from "react-native";
import {Icon} from 'react-native-elements'; // you can use other libs
import colors from './resource/colors';
function TabIcon(props) {
    return (
    <View style={styles.wrapper}>
      <View style={styles.container}>
        <Icon
           color={colors.t_white_dark}
           name={props.iconName}
           size={30}
          />
      </View>
    </View>
    )
  }

  const styles = {
    container: {
      width: 48,
      height: 42,
      padding: 5,
      justifyContent: 'center',
      alignItems: 'center',
    }
  };

  export default TabIcon;

and I can call like this mean page1 login and tabbar my application other pages in bottom navigations 我可以这样调用这意味着page1登录和tabbar我的应用程序其他页面在底部导航

import React, { Component } from 'react'
import { Text, View } from 'react-native'
import { Actions } from 'react-native-router-flux';

export default class page1 extends Component {
  goTab1(){
    Actions.tabbar_bottom(); // it's render first item in tab stack
  }
  render() {
    return (
      <View>
        <Text> page1 </Text>
      </View>
    )
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter 导航保持上一屏幕在底部可见 - Flutter navigate keeping previous screen visible at the bottom 如何在 React 和新页面中链接 2 个组件仍然有导航栏 - How to link 2 components in React and in a new page still have a navigation bar 如何根据 React Native 中的条件在不同组件之间导航 - How to navigate between different components based on conditions in react native 如何在嵌套屏幕之间导航并防止在React Navigation中返回? - How to navigate between nested screens and prevent going back in React Navigation? React Navigation v5 如何使用 typescript 在选项卡之间导航 - React Navigation v5 how to navigate between tabs with typescript 如何在不使用 navigation.navigate() 的情况下在 React Native 中的屏幕之间导航? - How can I navigate between screens in React Native without using navigation.navigate()? 如何使用反应导航导航到反应原生的新屏幕并且组件位于不同的文件中 - How to navigate to a new screen in react native using react navigation and the components are in a different file 在项目之间共享React组件,同时将源代码保留在其中一个 - Sharing React components between projects while keeping the source code in one of them 使用自己的组件创建底部选项卡导航 - Creating bottom tab navigation with own components Angular 2在滚动的一组组件之间导航 - Angular 2 navigate between a set of components on scroll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM