Kürzlich habe ich ein Navigationslayout mit react-navigation
versucht. Ich habe 4 Tab, die in einer Schubladennavigation verschachtelt sind. Ich habe 3 Schubladenlabel. Ich möchte die Seite einer Registerkarte bedingt rendern, nehmen Sie Home Tab entsprechend der aktiven Schublade Label. Meine Codes sind unten:Bedingtes Rendern des Bildschirms mit Reagierenavigation
Screens.js
import React from 'react';
import { View, Text } from 'react-native';
export const LaptopHome =() => {
return(
<View style={{flex: 1, backgroundColor: '#e3e3e3'}}>
<Text>
This is laptop Home Page.
</Text>
</View>
);
}
export const CameraHome =() => {
return(
<View style={{flex: 1, backgroundColor: 'skyBlue'}} >
<Text>This is Camera Home Page</Text>
</View>
)
}
export const MobileHome =() => {
return(
<View style={{flex: 1}}>
<Text>This is a Mobile Home page</Text>
</View>
);
}
export const Orders =() => {
return(
<View style={{flex: 1}}>
<Text>Orders history details</Text>
</View>
);
}
export const Profile =() => {
return(
<View style={{flex: 1}}>
<Text>Profile details</Text>
</View>
);
}
export const Notification =() => {
return(
<View style={{flex: 1}}>
<Text>List of Notification</Text>
</View>
);
}
Routes.js
import { StackNavigator, TabNavigator } from 'react-navigation';
import { FontAwesome } from '@expo/vector-icons';
import { LaptopHome, CameraHome, MobileHome, Orders, Profile, Notification } from './Screens';
const HomeStack = StackNavigator({
Home: {
screen: LaptopHome //or CameraHome or MobileHome //Render according to active drawer label.
}
});
const OrdersStack = StackNavigator({
Order: {
screen: Orders,
}
});
const ProfileStack = StackNavigator({
Profile: {
screen: Profile,
}
});
const NotificationStack = StackNavigator({
Notification: {
screen: Notification,
}
});
const HomeTab = TabNavigator({
HomeTab: {
screen: HomeStack,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon: ({ tintColor }) => <FontAwesome name="home" size={24} color={tintColor} />,
},
},
OrderTab: {
screen: OrdersStack,
navigationOptions: {
tabBarLabel: 'Orders',
tabBarIcon: ({ tintColor }) => <FontAwesome name="cart-arrow-down" size={24} color={tintColor} />
},
},
ProfileTab: {
screen: ProfileStack,
navigationOptions: {
tabBarLabel: 'Profile',
tabBarIcon: ({ tintColor }) => <FontAwesome name="user" size={24} color={tintColor} />
},
},
NotificationTab: {
screen: NotificationStack,
navigationOptions: {
tabBarLabel: 'Notification',
tabBarIcon: ({ tintColor }) => <FontAwesome name="bell" size={24} color={tintColor} />
},
}
}, {
initialRouteName: 'HomeTab',
tabBarPosition: 'bottom',
swipeEnabled: false,
tabBarOptions: {
activeTintColor: '#4DD1A5',
inactiveTintColor: '#AAADAC',
upperCaseLabel: false,
showIcon: true,
style: {
backgroundColor: '#fff',
},
labelStyle:{
fontSize: 10,
margin: 0,
},
indicatorStyle: {
opacity: 0,
},
},
});
export const AppNavigator = DrawerNavigator({
Laptop: {
screen: HomeTab,
navigationOptions: {
drawerLabel: 'Laptop',
}
},
Camera: {
screen: HomeTab,
navigationOptions: {
drawerLabel: 'Camera',
}
},
Mobile: {
screen: HomeTab,
navigationOptions: {
drawerLabel: 'Mobile',
drawerIcon: ({ tintColor }) => (
<MaterialCommunityIcons name="table-large" size={24} color={tintColor} />
),
}
}
}, {
initialRouteName: 'Laptop',
contentOptions: {
activeTintColor: '#4DD1A5',
inactiveTintColor: '#AAADAC',
activeBackgroundColor: '#ffffff',
}
});
So 363.210App.js
'use strict';
import React, { Component } from 'react';
import {AppNavigator} from './Routes';
export default class App extends Component {
render() {
return (
<AppNavigator />
);
}
}
AppRegistry.registerComponent('SimpleApp',() => App);
möchte ich bedingt die HOME-Tab machen entsprechend dem aktiven Schublade Label. Ich habe versucht, durch den Zugriff auf den Zustand der Reagierenavigation, aber es war keine Hilfe. Hat jemand daran gearbeitet oder fehlt mir etwas.
React-Navigation hat so viele Vorteile gegenüber dem reaktiven nativen Router-Flux. Das reaktive native ändert sich mit der Zeit drastisch. Bitte aktualisieren Sie sich. –
Du musstest mich nicht abstimmen, sondern hättest mich nur darauf hinweisen können, dass ich meine Antwort aktualisieren darf. Was ich versuchte, war eine Alternative, die @hmachahary nützlich finden könnte. Was ich gesagt habe, hat die Eigenschaften der Reaktivnavigation nicht unterschätzt und es gibt hier nichts, was man abstimmen könnte. –