gpt4 book ai didi

android - 在 BottomTabNavigator 上打开一个模态点击 react-native

转载 作者:行者123 更新时间:2023-11-29 23:22:28 28 4
gpt4 key购买 nike

我试图从 bottomnavigator 打开一个模式,正在按照本教程 - https://snack.expo.io/SyJKMkFUM我正在使用 react 导航 -3.0.9

这是我的 app.js 类 App 扩展 React.Component {

 renderItem = (route, index) => {
const {
navigation,
jumpToIndex,
} = this.props;
const isCapture = route.routeName === 'Capture';
const focused = index === navigation.state.index;
return (
<TouchableWithoutFeedback
key={route.key}
onPress={() => isCapture ? this.props.navigation.navigate('CaptureModal') : jumpToIndex(index)}
>
<View >
<Text >{route.routeName}</Text>
</View>
</TouchableWithoutFeedback>
);
};
render() {
const {
navigation,
} = this.props;

const {
routes,} = navigation.state;
return (
<View style={styles.container}>
{routes && routes.map(this.renderItem)}
</View>
);}}
const Screen = (props) => (
<View >
<Text>{props.title} Screen</Text>
</View>
);
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
});
const TabNavigator = createBottomTabNavigator({
Home: {
screen: HomeScreen
},
Link: {
screen: LinksScreen
},
settings: {
screen: View,
},
});
const CaptureStack = createStackNavigator({
Capture: {
screen: (props) => <Screen title="Capture" {...props} />,
navigationOptions: ({ navigation }) => ({
headerTitle: 'Capture',
headerLeft: (
<Button
title="Back"
onPress={() => navigation.goBack(null)}
/>),}),},})

const RootStack1 = createStackNavigator({
Main: {
screen: TabNavigator,
},
CaptureModal: {
screen: CaptureStack,
navigationOptions: {
gesturesEnabled: false,
},
},
}, {
headerMode: 'none',
mode: 'modal',
});

const AppNavigator = createAppContainer(RootStack1); 导出默认 AppNavigator;

谁能解释一下这有什么问题吗?可能是路由版本问题,因为教程使用的是 1.0.0 。

最佳答案

如果有人在这里看到我是如何实现的,我确实解决了我的问题 -

我的目标 ->
单击主屏幕 -> 选项卡式 Activity -> 单击任何选项卡新屏幕

在我的 app.js 中,我创建了如下导航 -

const TabNavigator = createBottomTabNavigator({
HomeScreen: {
screen: HomeScreen
},
LinksScreen: {
screen: LinksScreen
},
LoginScreen: {
screen: SurveyScreen,
},

},
{
initialRouteName : 'HomeScreen' ,
});

const RootStack1 = createStackNavigator({
TabNavigator: {
screen: TabNavigator,
},
CaptureModal: {
screen: LoginScreen,
navigationOptions: {
gesturesEnabled: false,
},
},
}, {
headerMode: 'none',
mode: 'modal',
headerLeft: null
});

const mainStack = createStackNavigator({

InsideApp: {
screen: MainScreen,

},
StartScreen: {
screen: RootStack1,
},
} ,{
headerMode: 'none',
headerLeft: null
},);

const AppNavigator = createAppContainer(mainStack);
export default AppNavigator;

现在我的模态屏幕将在点击第三个选项卡 (SurveyScreen) 时弹出,要在 surveyscreen 中实现这一点,我所要做的就是覆盖 didmount 函数并从那里打开模态 -

 componentDidMount() {
console.log('didmount called.');
this.props.navigation.navigate('CaptureModal')
}

对于从模式到选项卡 Activity 的后退导航,我使用了 stackreset -

const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'TabNavigator' })],
});

然后点击返回 -

onPress={ () => this.props.navigation.dispatch(resetAction)

关于android - 在 BottomTabNavigator 上打开一个模态点击 react-native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54024006/

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