-
Notifications
You must be signed in to change notification settings - Fork 2
/
RootNavigationContainer.js
153 lines (137 loc) · 3.82 KB
/
RootNavigationContainer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import React from 'react';
import {createAppContainer, createSwitchNavigator} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import {Image} from "react-native";
import settingsIcon from './src/assets/settings_icon.png';
import walletIcon from './src/assets/wallet_icon.png';
import usersIcon from './src/assets/users_icon.png';
import sizeHelper from "./src/helper/SizeHelper";
import Colors from "./src/theme/styles/Colors";
import {Root} from "native-base";
import {createBottomTabNavigator} from 'react-navigation-tabs';
import {OstWalletSettingsComponent} from '@ostdotcom/ost-wallet-sdk-react-native';
import IntroScreen from './src/components/IntroScreen'
import LoginScreen from './src/components/LoginScreen'
import SettingScreen from './src/components/Setting'
import SendTokens from './src/components/SendTokens'
import WalletScreen from './src/components/WalletScreen/index'
import UserScreen from "./src/components/UsersScreen";
import NavigationService from "./src/services/NavigationService";
const customTabHiddenRoutes = [
'SendTokens',
'WalletSettingScreen'
];
let recursiveMaxCount = 0;
getLastChildRoutename = (state) => {
if (!state) return null;
let index = state.index,
routes = state.routes;
if (!routes || recursiveMaxCount > 50) {
recursiveMaxCount = 0;
return state.routeName;
}
recursiveMaxCount++;
return getLastChildRoutename(routes[index]);
};
const modalStackConfig = {
navigationOptions: ({ navigation }) => {
const routeName = getLastChildRoutename(navigation.state);
return {
tabBarVisible: !customTabHiddenRoutes.includes(routeName)
};
},
headerLayoutPreset: 'center'
};
const Onboarding = createStackNavigator(
{
IntroScreen: IntroScreen,
LoginScreen: LoginScreen
}
);
const UsersStack = createStackNavigator(
{
UsersScreen: UserScreen,
SendTokens: SendTokens
},
{
...modalStackConfig
}
);
const WalletStack = createStackNavigator(
{
WalletScreen: WalletScreen,
LoginScreen: LoginScreen
},
{
headerLayoutPreset: 'center'
}
);
const SettingStack = createStackNavigator(
{
SettingScreen: SettingScreen,
WalletSettingScreen: OstWalletSettingsComponent
},
{
...modalStackConfig
}
);
const Wallet = createBottomTabNavigator({
Users: UsersStack,
Wallet: WalletStack,
Settings: SettingStack
},
{
defaultNavigationOptions: ({navigation}) => ({
tabBarIcon: ({focused, horizontal, tintColor}) => {
const {routeName} = navigation.state;
if (routeName === 'Settings') {
iconPath = settingsIcon;
height = sizeHelper.layoutPtToPx(27);
width = sizeHelper.layoutPtToPx(28);
} else if (routeName === 'Users') {
iconPath = usersIcon;
height = sizeHelper.layoutPtToPx(20);
width = sizeHelper.layoutPtToPx(28);
} else {
iconPath = walletIcon;
height = sizeHelper.layoutPtToPx(24);
width = sizeHelper.layoutPtToPx(19);
}
// You can return any component that you like here!
return <Image source={iconPath} style={{
width: width,
height: height,
tintColor: tintColor
}}/>;
},
}),
tabBarOptions: {
activeTintColor: Colors.brightSky,
inactiveTintColor: Colors.grey,
},
});
const AppContainer = createAppContainer(
createSwitchNavigator(
{
Onboarding: Onboarding,
Wallet: Wallet
},
{
initialRouteName: 'Onboarding',
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
}
)
);
const RootNavigationContainer = () => (
<Root>
<AppContainer
ref={(navigatorRef) => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
/>
</Root>
);
export default RootNavigationContainer;