[英]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.