показ нижней панели навигации на экранах, которые не являются частью нижних вкладок в реагировать родной - PullRequest
0 голосов
/ 13 ноября 2018

У меня есть три вкладки и 8 экранов в собственном приложении.Я создал навигатор нижней вкладки следующим образом, и у меня есть еще 5 экранов, которые мне не нужны на вкладках, но на этих экранах требуется обычный навигатор нижней панели с тремя вкладками.Точная помощь приветствуется.

const TabNavigation = createBottomTabNavigator(
{
    Scan: {
        screen: ScanScreen,
        navigationOptions: {                
            tabBarLabel: 'Scan',
            tabBarIcon: () => <Ionicons name="ios-qr-scanner-outline" size={32} color="blue" />
            ,
        },
    },
    Patient: {
        screen: PatientStack,
        navigationOptions: {                
            tabBarLabel: 'Patients',
            tabBarIcon: () => <Ionicons name="ios-people" size={32} color="blue" />
            ,
        },
    },
    Setting: {

        screen: SettingScreen,
        navigationOptions: {            
            tabBarLabel: 'Setting',
            tabBarIcon: () => <Ionicons name="ios-settings" size={32} color="blue" />
            ,
        },
    },        
},
{
    lazyLoad: true,
    animationEnabled: false,
    tabBarPosition: 'bottom',
    tabBarOptions: {

        showIcon: true,
        showLabel: true,
        activeTintColor: '#7117ea',
        inactiveTintColor: '#7117ea',
        style: {
            backgroundColor: '#eff0f1'
        },
        iconStyle: {
            width: 40

        },
        tabStyle: {
            height: 60
        }

    },
},
);

1 Ответ

0 голосов
/ 13 ноября 2018

Это пример кода, который решит вашу проблему.

import React from 'react';
import { Button, Text, View } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { createStackNavigator, createBottomTabNavigator } from 'react-navigation';

class HomeScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Home!</Text>
        <Button
          title="Go to Settings"
          onPress={() => this.props.navigation.navigate('Settings')}
        />
        <Button
          title="Go to Details"
          onPress={() => this.props.navigation.navigate('Details')}
        />
      </View>
    );
  }
}

class SettingsScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Settings!</Text>
        <Button
          title="Go to Home"
          onPress={() => this.props.navigation.navigate('Home')}
        />
        <Button
          title="Go to Details"
          onPress={() => this.props.navigation.navigate('Details')}
        />
      </View>
    );
  }
}

class DetailsScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Details!</Text>
      </View>
    );
  }
}

const HomeStack = createStackNavigator({
  Home: { screen: HomeScreen },
  Details: { screen: DetailsScreen },
});

const SettingsStack = createStackNavigator({
  Settings: { screen: SettingsScreen },
  Details: { screen: DetailsScreen },
});

export default createBottomTabNavigator(
  {
    Home: { screen: HomeStack },
    Settings: { screen: SettingsStack },
  },
  {
    navigationOptions: ({ navigation }) => ({
      tabBarIcon: ({ focused, tintColor }) => {
        const { routeName } = navigation.state;
        let iconName;
        if (routeName === 'Home') {
          iconName = `ios-information-circle${focused ? '' : '-outline'}`;
        } else if (routeName === 'Settings') {
          iconName = `ios-options${focused ? '' : '-outline'}`;
        }

        // You can return any component that you like here! We usually use an
        // icon component from react-native-vector-icons
        return <Ionicons name={iconName} size={25} color={tintColor} />;
      },
    }),
    tabBarOptions: {
      activeTintColor: 'red',
      inactiveTintColor: 'gray',
    },
  }
);
...