简体   繁体   English

在“MaterialTopTabNavigator”选项卡中使用“StackNavigator”。 (反应原生 + 博览会)

[英]using “StackNavigator” inside a “MaterialTopTabNavigator” tab. (React-native + expo)

My application allows my users to move with a simple slide of a finger from one tab to another thanks to "MaterialTopTabNavigator".借助“MaterialTopTabNavigator”,我的应用程序允许我的用户通过简单的手指滑动从一个选项卡移动到另一个选项卡。 I would like to be able to propose also on some tabs redirection buttons using "StackNavigator".我还希望能够使用“StackNavigator”在某些选项卡重定向按钮上提出建议。 I don't understand how to interlock one into the other without breaking everything.我不明白如何在不破坏一切的情况下将一个与另一个互锁。 can you give me a simple example?你能给我一个简单的例子吗? it will be of great help to me.这对我会有很大帮助。

you can run this example on https://snack.expo.io/ : as you can see, the "edit profile" button does not work...您可以在https://snack.expo.io/上运行此示例:如您所见,“编辑配置文件”按钮不起作用...

App.js ->应用程序.js ->

import React from 'react';  
import {StyleSheet, Text, View, Button, TouchableOpacity} from 'react-native';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import { createAppContainer } from 'react-navigation';
import { createMaterialTopTabNavigator } from 'react-navigation-tabs';
import Icon from "react-native-vector-icons/Ionicons";
import IntraAppNavigation from "./navigator"

class HomeScreen extends React.Component {  
 goToEdit = () => this.props.navigation.navigate('EditProfil')

 render() {  
return (  
    <View style={styles.container}>  
      <Text>Home Screen</Text>  
        <TouchableOpacity style={styles.buttons} onPress={this.goToEdit}>
          <Text style={styles.button}>Edite profil</Text>
      </TouchableOpacity>
    </View>  
 );  
}  
}  
class MapScreen extends React.Component {  
render() {  
return (  
    <View style={styles.container}>  
      <Text>Map Screen</Text>  
    </View>  
);  
}  
}  
class SettingsScreen extends React.Component {  
render() {  
    return (  
        <View style={styles.container}>  
            <Text>Settings Screen</Text>  
        </View>  
    );  
    }  
    }  
    const styles = StyleSheet.create({  
container: {  
    flex: 1,  
    justifyContent: 'center',  
    alignItems: 'center'  
},  
button: {
    color: 'blue',
    textDecorationLine: 'underline'
}
});  

const AppNavigator = createMaterialTopTabNavigator(
 {
Home: { screen: HomeScreen },
Map: { screen: MapScreen },
Settings: { screen: SettingsScreen }
},
{
tabBarPosition: 'bottom',
swipeEnabled: true,
animationEnabled: true,
tabBarOptions: {
  activeTintColor: 'green',
  inactiveTintColor: 'white',
  style: {
    backgroundColor: 'black',
  },
  labelStyle: {
    textAlign: 'center',
  },
  indicatorStyle: {
    borderBottomColor: 'green',
    borderBottomWidth: 2,
  },
},
});

export default createAppContainer(AppNavigator); 

navigator.js -> navigator.js ->

import { createStackNavigator } from 'react-navigation-stack'
import EditProfil from './EditProfil'

const IntraAppNavigation = createStackNavigator(
 {
  Edit: { screen: EditProfil}
 },
 {
   initialRouteName: 'Edit',
   headerMode: 'none'
 }
 )

 export default IntraAppNavigation

EditProfil.js -> EditProfil.js ->

import React from 'react'
import { StyleSheet, Text, View } from 'react-native'

export default class EditProfil extends React.Component {
render () {
 return (  
    <View style={styles.container}>  
      <Text>Edit Screen</Text>  
    </View>  
);  
}
}

const styles = StyleSheet.create({
container: {  
    flex: 1,  
    justifyContent: 'center',  
    alignItems: 'center'  
}
})

thanks.谢谢。

import { createStackNavigator } from 'react-navigation-stack'
import EditProfil from './EditProfil'

const IntraAppNavigation = createStackNavigator(
 {
  home: { screen: HomeScreen}
  EditProfil: { screen:  EditProfil}
 },
 {
   initialRouteName: 'home',
   headerMode: 'none'
 }
 )

 export default IntraAppNavigation

and

const AppNavigator = createMaterialTopTabNavigator(
 {
Home: { screen: IntraAppNavigation },
Map: { screen: MapScreen },
Settings: { screen: SettingsScreen }
},
{
tabBarPosition: 'bottom',
swipeEnabled: true,
animationEnabled: true,
tabBarOptions: {
  activeTintColor: 'green',
  inactiveTintColor: 'white',
  style: {
    backgroundColor: 'black',
  },
  labelStyle: {
    textAlign: 'center',
  },
  indicatorStyle: {
    borderBottomColor: 'green',
    borderBottomWidth: 2,
  },
},
});

export default createAppContainer(AppNavigator); 

Might need a little tweaking but should give you a good starting base可能需要一些调整,但应该给你一个良好的起点

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM