gpt4 book ai didi

react-native - 将 React-Native-Paper BottomNavigation 与 StackNavigator 相结合

转载 作者:行者123 更新时间:2023-12-05 07:00:02 24 4
gpt4 key购买 nike

我目前正在使用 React-Native-Paper bottomNavigation。它工作得很好。但是,下一个要求是将 Stack Navigator 添加到各个屏幕。我在常规的底部栏导航上工作,但无法让它与 React-Native-Paper 库一起工作。

const SubjectNavigator = createStackNavigator({
Subjects: SubjectScreen,
Topics: TopicListScreen
}, {
navigationOptions: {}
});

const NavigationController = () => {
const [index, setIndex] = React.useState(0);
const [routes] = React.useState([
{ key: 'home', title: 'Home', icon: 'home', color: '#3F51B5' },
{ key: 'subjects', title: 'Subjects', icon: 'book-open', color: '#009688' },
{ key: 'tournaments', title: 'Tournaments', icon: 'trophy', color: '#795548' },
{ key: 'videos', title: 'Video Feeds', icon: 'video', color: '#607D8B' }
]);

const renderScene = BottomNavigation.SceneMap({
home: HomeScreen,
subjects: SubjectScreen,
tournaments: TournamentScreen,
videos: VideoScreen
});

return (
<BottomNavigation
navigationState={{ index, routes }}
onIndexChange={setIndex}
renderScene={renderScene}
/>
);
};

export default NavigationController;

这样做会给我一个类似 ---- Can't Find Variable: navigation 的错误,当我试图在 subjectNavigator 堆栈中从一个屏幕移动到另一个屏幕时。

请帮助!!

最佳答案

您可以创建一个堆栈导航器组件,用于您的每条路线。然后,传入一个 initialRouteName 属性。

class AppStackScreen extends React.Component {

render(){
return(
<NavigationContainer>
<Stack.Navigator initialRouteName={this.props.initialRouteName}>
<Stack.Screen
name="Home"
component={HomeScreen}
/>
<Stack.Screen
name="Subjects"
component={SubjectScreen}
/>
</NavigationContainer>
);
}
}

然后在你的 BottomNavigation

<BottomNavigation
navigationState={this.state}
onIndexChange={this.handleIndexChange}
renderScene = {({ route, jumpTo }) => {
switch (route.key) {
case 'Home':
return <AppStackScreen initialRouteName="Home" jumpTo={jumpTo} />;
break;
case 'Subjects':
return <AppStackScreen initialRouteName="Subjects" jumpTo={jumpTo} />;
break;

关于react-native - 将 React-Native-Paper BottomNavigation 与 StackNavigator 相结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64211508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com