Я пытаюсь заставить мое реагирующее на родство приложение использовать stackNavigator, поэтому, когда люди нажимают кнопку «Назад» на телефоне Android, он переходит на HomeScreen.
Я хочу, чтобы все экраны снизу НавигатораВернитесь на HomeScreen, когда они нажмут кнопку «Назад».Также я создал новый экран (TravelCPHAirportScreen), который не должен быть включен в bottomNavigationbar, и теперь, когда я к нему перехожу, я не могу вернуться снова, потому что кнопка «Назад» выходит из приложения.
Я пробовал несколько вещей, но не могу понять, правильно ли я разместил новый TravelCPHAirportScreen и как сделать stackNavigator, как описано.
import React, {Component} from 'react';
import { createStackNavigator, createBottomTabNavigator } from 'react-navigation';
import { Ionicons } from '@expo/vector-icons';
import AuthScreen from './AuthScreen';
import HomeScreen from './HomeScreen';
import MeetingScreen from './MeetingScreen';
import TripScreen from './TripScreen';
import RateTripScreen from './RateTripScreen';
import ProfileScreen from './ProfileScreen';
import TravelCPHAirportScreen from './TravelCPHAirportScreen';
let AuthStack = createStackNavigator({ AuthScreen }, {
headerMode: 'none',
navigationOptions: {
headerStyle: {
backgroundColor: '#202020',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
},
});
AuthStack.navigationOptions = {
tabBarLabel: 'Login',
tabBarVisible: false,
};
let HomeStack = createStackNavigator({ HomeScreen }, {
title: 'Home ',
titleStyle: {
color: '#f0ca6d',
fontWeight: '300',
justifyContent: 'space-between',
},
navigationOptions: {
headerStyle: {
backgroundColor: '#303030',
},
headerTintColor: '#f0ca6d',
headerTitleStyle: {
fontWeight: 'bold',
},
},
});
HomeStack.navigationOptions = {
tabBarLabel: 'Home',
tabBarVisible: true,
};
let MeetingStack = createStackNavigator({ MeetingScreen }, {
navigationOptions: {
title: 'Meeting',
titleStyle: {
color: '#f0ca6d',
fontWeight: '300',
justifyContent: 'space-between',
textAlign: 'center'
},
headerStyle: {
backgroundColor: '#303030',
},
headerTintColor: '#f0ca6d',
headerTitleStyle: {
fontWeight: 'bold',
},
},
});
MeetingStack.navigationOptions = {
tabBarLabel: 'Meeting Point',
tabBarVisible: true,
};
let TripStack = createStackNavigator({ TripScreen }, {
navigationOptions: {
title: 'Trip',
titleStyle: {
color: '#f0ca6d',
fontWeight: '300',
justifyContent: 'space-between'
},
headerStyle: {
backgroundColor: '#303030',
},
headerTintColor: '#f0ca6d',
headerTitleStyle: {
fontWeight: 'bold',
},
},
});
TripStack.navigationOptions = {
tabBarLabel: 'Trip',
tabBarVisible: true,
};
let RateStack = createStackNavigator({ RateTripScreen }, {
navigationOptions: {
title: 'Rate Trip',
titleStyle: {
color: '#f0ca6d',
fontWeight: '300',
justifyContent: 'space-between'
},
headerStyle: {
backgroundColor: '#303030',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
},
});
RateStack.navigationOptions = {
tabBarLabel: 'Rate Trip',
tabBarVisible: true,
};
let ProfileStack = createStackNavigator({ ProfileScreen }, {
navigationOptions: {
title: 'Profile',
titleStyle: {
color: '#f0ca6d',
fontWeight: '300',
justifyContent: 'space-between',
textAlign: 'center'
},
headerStyle: {
backgroundColor: '#303030',
},
headerTintColor: '#f0ca6d',
headerTitleStyle: {
fontWeight: 'bold',
},
},
});
ProfileStack.navigationOptions = {
tabBarLabel: 'Profile',
tabBarVisible: true,
};
let TravelCPHAirportStack = createStackNavigator({ TravelCPHAirportScreen }, { headerMode: 'none',
navigationOptions: {
headerStyle: {
backgroundColor: '#202020',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
},
});
TravelCPHAirportStack.navigationOptions = {
tabBarLabel: 'CPH Airport',
tabBarVisible: false,
};
let MainTab = createBottomTabNavigator(
{
HomeStack,
MeetingStack,
TripStack,
RateStack,
ProfileStack,
},
{
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
let iconName;
switch (routeName) {
case 'HomeStack':
// const iconName = Platform.OS === 'android' ? 'android-icon': 'ios-icon';
iconName = `ios-home${focused ? '' : '-outline'}`;
break;
case 'MeetingStack':
iconName = `ios-git-network${focused ? '' : '-outline'}`;
break;
case 'TripStack':
iconName = `ios-map${focused ? '' : '-outline'}`;
break;
case 'RateStack':
// const iconName = Platform.OS === 'android' ? 'android-icon': 'ios-icon';
iconName = `ios-star${focused ? '' : '-outline'}`;
break;
case 'ProfileStack':
// const iconName = Platform.OS === 'android' ? 'android-icon': 'ios-icon';
iconName = `ios-person${focused ? '' : '-outline'}`;
break;
}
return <Ionicons name={iconName} size={30} color={tintColor} />;
},
}),
headerMode: 'none',
tabBarOptions: {
style: {
backgroundColor: '#202020'
},
activeTintColor: '#f0ca6d',
inactiveTintColor: 'white',
labelStyle: { fontSize: 12 }
},
tabBarPosition: 'bottom'
}
);
MainTab.navigationOptions = {
tabBarLabel: 'Main',
tabBarVisible: false,
};
let RootTab = createBottomTabNavigator(
{
AuthStack,
MainTab,
},{
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
let iconName;
switch (routeName) {
case 'AuthStack':
iconName = `ios-log-in${focused ? '' : '-outline'}`;
break;
}
return <Ionicons name={iconName} size={30} color={tintColor} />;
},
}),
headerMode: 'none',
tabBarOptions: {
activeTintColor: 'tomato',
inactiveTintColor: 'gray',
labelStyle: { fontSize: 12 }
},
tabBarPosition: 'bottom'
}
);
const Root = createStackNavigator(
{
root: RootTab,
},
{ headerMode: 'none', }
);
class Navigation extends Component {
render() {
return (
<Root/>
);
}
}
export default Navigation;