8
8
9
9
import React , { Component } from 'react' ;
10
10
import { Platform , StyleSheet , Text , View , Image , StatusBar } from 'react-native' ;
11
- import { createStackNavigator , createBottomTabNavigator , createAppContainer , TabBarBottom } from 'react-navigation'
11
+ import { createStackNavigator , NavigationActions , createBottomTabNavigator , createAppContainer , TabBarBottom } from 'react-navigation'
12
12
import { getSession } from './src/utils'
13
13
import Home from './src/views/Home'
14
14
import Detail from './src/views/Detail'
15
15
import Info from './src/views/Info'
16
16
import Me from './src/views/Me'
17
17
import { Provider } from 'react-redux'
18
+ import { createStore } from 'redux'
19
+ import Index from './src/store'
18
20
// AsyncStorage.setItem('userinfo', 'I like to save it.')
19
21
// const storeUserinfo = AsyncStorage.getItem('userinfo')
20
22
// let islogin
21
23
// console.log(this);
22
24
getSession ( 'loginname' )
25
+ const store = createStore ( Index )
26
+ store . subscribe ( ( ) => {
27
+ //监听state变化
28
+ // console.log(store.getState());
29
+ // console.log(Tab);
30
+ Tab ( store )
31
+ // AppContainer = createAppContainer(AppNavigator(store));
32
+ } ) ;
23
33
// let a = getSession('loginname')
24
34
// console.log(a._55, a);
35
+ // console.log(store.getState());
25
36
26
37
// console.log(AsyncStorage.getItem('userinfo'));
27
-
28
38
class App extends Component {
39
+ constructor ( ) {
40
+ super ( )
41
+ this . state = {
42
+ nav : '' ,
43
+ login : store . getState ( ) . login
44
+ }
45
+ }
29
46
render ( ) {
47
+ console . log ( this . state . login ) ;
48
+
49
+ // console.log(store.getState());
50
+ // const AppContainer = createAppContainer(AppNavigator(store));
30
51
return (
31
52
< Provider store = { store } >
32
53
< AppContainer
54
+ ref = { navigatorRef => {
55
+ this . state . nav = navigatorRef
56
+ } }
33
57
onNavigationStateChange = {
34
- ( prevState , currentState ) => {
58
+ ( prevState , currentState , action ) => {
35
59
StatusBar . setBarStyle ( 'dark-content' )
60
+ console . log ( action ) ;
61
+ // this.state.nav.dispatch(SwitchActions.jumpTo({ routeName: action.routeName }))
62
+ // setTopLevelNavigator(this.state.nav);
63
+ // navigate('Home')
64
+ // console.log(prevState, currentState);
65
+ // console.log(this.state.nav);
66
+
67
+ // let state = store.getState().login
68
+ // if (state !== '') {
69
+ // // this.state.nav
70
+ // console.log(this.state.nav);
71
+ // this.state.nav._navigation.navigate('Mine')
72
+
73
+ // // this.state.nav._navigation.dispatch(
74
+ // // // this.state.nav._navigation.push('Mine')
75
+ // // )
76
+ NavigationActions . navigate ( { routeName : 'Detail' } )
77
+ // }
78
+ // this.state.nav._navigation.navigate('')
36
79
// const currentScene = getCurrentRouteName(currentState)
37
80
// const previousScene = getCurrentRouteName(prevState)
38
81
// if (previousScene !== currentScene) {
@@ -49,104 +92,168 @@ class App extends Component {
49
92
)
50
93
}
51
94
}
52
-
53
- const Tab = createBottomTabNavigator (
54
- {
55
- Home : {
56
- screen : createStackNavigator ( { Home } ) ,
57
- navigationOptions : ( { navigation } ) => ( {
58
- tabBarLabel : '首页' ,
59
- // title: '111',
60
- // headerTitle: null,
61
- // headerBackTitle: null,
62
- tabBarIcon : ( { focused, tintColor } ) => (
63
- // normalImage='https://www.easyicon.net/api/resizeApi.php?id=1225464&size=16'
64
- // normalImage={require('./src/assets/tabbar_merchant.png')}
65
- // selectedImage={require('./src/assets/tabbar_merchant.png')}
66
- < Image style = { { tintColor, width : 25 , height : 25 } } source = { require ( './src/assets/home.png' ) } > </ Image >
67
- )
68
- } ) ,
69
- } ,
70
- Publish : {
71
- screen : createStackNavigator ( { publish : Home } ) ,
72
- navigationOptions : ( { navigation } ) => ( {
73
- tabBarLabel : '发布' ,
74
- tabBarIcon : ( { focused, tintColor } ) => (
75
- < Image style = { { tintColor, width : 25 , height : 25 } } source = { require ( './src/assets/publish.png' ) } > </ Image >
76
-
77
- )
78
- } ) ,
95
+ function Tab ( params ) {
96
+ // console.log(params);
97
+ this . params = params
98
+ return createBottomTabNavigator (
99
+ {
100
+ Home : {
101
+ screen : createStackNavigator ( { Home } ) ,
102
+ navigationOptions : ( { navigation } ) => ( {
103
+ tabBarLabel : '首页' ,
104
+ // title: '111',
105
+ // headerTitle: null,
106
+ // headerBackTitle: null,
107
+ tabBarIcon : ( { focused, tintColor } ) => (
108
+ // normalImage='https://www.easyicon.net/api/resizeApi.php?id=1225464&size=16'
109
+ // normalImage={require('./src/assets/tabbar_merchant.png')}
110
+ // selectedImage={require('./src/assets/tabbar_merchant.png')}
111
+ < Image style = { { tintColor, width : 25 , height : 25 } } source = { require ( './src/assets/home.png' ) } > </ Image >
112
+ )
113
+ } ) ,
114
+ } ,
115
+ Publish : {
116
+ screen : createStackNavigator ( { publish : Home } ) ,
117
+ navigationOptions : ( { navigation } ) => ( {
118
+ tabBarLabel : '发布' ,
119
+ tabBarOnPress : ( { defaultHandler, navigation} ) => {
120
+ // console.log(defaultHandler);
121
+ jundeLogin ( defaultHandler , navigation )
122
+
123
+ } ,
124
+ tabBarIcon : ( { focused, tintColor } ) => (
125
+ < Image style = { { tintColor, width : 25 , height : 25 } } source = { require ( './src/assets/publish.png' ) } > </ Image >
126
+
127
+ )
128
+ } ) ,
129
+ } ,
130
+
131
+ Message : {
132
+ screen : createStackNavigator ( { message : Home } ) ,
133
+ navigationOptions : ( { navigation } ) => ( {
134
+ tabBarLabel : '消息' ,
135
+ tabBarOnPress : ( { defaultHandler, navigation} ) => {
136
+ // console.log(defaultHandler);
137
+ jundeLogin ( defaultHandler , navigation )
138
+
139
+ } ,
140
+ tabBarIcon : ( { focused, tintColor } ) => (
141
+ < Image style = { { tintColor, width : 25 , height : 25 } } source = { require ( './src/assets/message.png' ) } > </ Image >
142
+
143
+ )
144
+ } ) ,
145
+ } ,
146
+ Mine : {
147
+ screen : createStackNavigator ( { Mine : Me } ) ,
148
+ navigationOptions : ( { navigation } ) => ( {
149
+ tabBarLabel : '我的' ,
150
+ tabBarIcon : ( { focused, tintColor } ) => (
151
+ < Image style = { { tintColor, width : 25 , height : 25 } } source = { require ( './src/assets/me.png' ) } > </ Image >
152
+
153
+ )
154
+ } ) ,
155
+ } ,
156
+ Info : {
157
+ screen : createStackNavigator ( { Info : Info } ) ,
158
+ // paths: 'people/:name',
159
+ navigationOptions : ( { navigation } ) => ( {
160
+ tabBarLabel : '关于' ,
161
+ tabBarOnPress : ( { defaultHandler, navigation} ) => {
162
+ // console.log(defaultHandler);
163
+ jundeLogin ( defaultHandler , navigation )
164
+
165
+ } ,
166
+ tabBarIcon : ( { focused, tintColor } ) => (
167
+ < Image style = { { tintColor, width : 25 , height : 25 } } source = { require ( './src/assets/info.png' ) } > </ Image >
168
+
169
+ )
170
+ } ) ,
171
+ } ,
79
172
} ,
173
+ {
174
+ tabBarComponent : TabBarBottom ,
175
+ tabBarPosition : 'bottom' ,
176
+ lazy : true ,
177
+ animationEnabled : false ,
178
+ swipeEnabled : false ,
179
+ onTransitionStart : ( start ) => {
180
+ console . log ( strat ) ;
181
+
182
+ } ,
183
+ tabBarOptions : {
184
+ activeTintColor : 'red' ,
185
+ inactiveTintColor : 'green' ,
186
+ style : { backgroundColor : '#ffffff' } ,
187
+ } ,
188
+ } )
189
+ }
80
190
81
- Message : {
82
- screen : createStackNavigator ( { message : Home } ) ,
83
- navigationOptions : ( { navigation } ) => ( {
84
- tabBarLabel : '消息' ,
85
- tabBarIcon : ( { focused, tintColor } ) => (
86
- < Image style = { { tintColor, width : 25 , height : 25 } } source = { require ( './src/assets/message.png' ) } > </ Image >
87
-
88
- )
89
- } ) ,
90
- } ,
91
- Mine : {
92
- screen : createStackNavigator ( { Mine : Me } ) ,
93
- navigationOptions : ( { navigation } ) => ( {
94
- tabBarLabel : '我的' ,
95
- tabBarIcon : ( { focused, tintColor } ) => (
96
- < Image style = { { tintColor, width : 25 , height : 25 } } source = { require ( './src/assets/me.png' ) } > </ Image >
97
-
98
- )
99
- } ) ,
100
- } ,
101
- Info : {
102
- screen : createStackNavigator ( { Info : Info } ) ,
103
- paths : 'people/:name' ,
104
- navigationOptions : ( { navigation } ) => ( {
105
- tabBarLabel : '关于' ,
106
- tabBarIcon : ( { focused, tintColor } ) => (
107
- < Image style = { { tintColor, width : 25 , height : 25 } } source = { require ( './src/assets/info.png' ) } > </ Image >
108
-
109
- )
110
- } ) ,
111
- } ,
112
- } ,
113
- {
114
- tabBarComponent : TabBarBottom ,
115
- tabBarPosition : 'bottom' ,
116
- lazy : true ,
117
- animationEnabled : false ,
118
- swipeEnabled : false ,
119
- tabBarOptions : {
120
- activeTintColor : 'red' ,
121
- inactiveTintColor : 'green' ,
122
- style : { backgroundColor : '#ffffff' } ,
123
- } ,
191
+ function jundeLogin ( defaultHandler , navigation ) {
192
+ let login = this . params . getState ( ) . login
193
+ if ( ! login || login === '' ) {
194
+ navigation . navigate ( 'Mine' )
195
+ } else {
196
+ defaultHandler ( )
197
+ }
198
+ }
199
+ // Tabs.navigationOptions = {
200
+ // header: null,
201
+ // };
202
+ function AppNavigator ( store ) {
203
+ let Tabs = Tab ( store )
204
+ Tabs . navigationOptions = {
205
+ header : null ,
206
+ } ;
207
+ let login
208
+ if ( store ) {
209
+ login = store . getState ( ) . login
210
+
124
211
}
125
- )
126
-
127
- Tab . navigationOptions = {
128
- header : null ,
129
- } ;
130
-
131
- const AppNavigator = createStackNavigator (
132
- {
133
- Tab : {
134
- screen : Tab
135
- } ,
136
- Detail : {
137
- screen : Detail
138
- }
139
- // Web: { screen: WebScene },
140
- // GroupPurchase: { screen: GroupPurchaseScene },
141
- } ,
142
- {
143
- defaultNavigationOptions : {
144
- headerBackTitle : null ,
145
- headerTintColor : '#333333' ,
146
- showIcon : true ,
212
+ // console.log(store.getState().login);
213
+ return createStackNavigator (
214
+ {
215
+ Tab : {
216
+ screen : Tabs
217
+ } ,
218
+ Detail : {
219
+ screen : Detail
220
+ } ,
221
+ // onTransitionStart: (start) => {
222
+ // console.log(strat);
223
+
224
+ // },
225
+ // Web: { screen: WebScene },
226
+ // GroupPurchase: { screen: GroupPurchaseScene },
147
227
} ,
148
- }
149
- )
228
+ {
229
+ defaultNavigationOptions : {
230
+ headerBackTitle : null ,
231
+ headerTintColor : '#333333' ,
232
+ showIcon : true ,
233
+ } ,
234
+ }
235
+ )
236
+ }
237
+ // const AppNavigator = createStackNavigator(
238
+ // {
239
+ // Tab: {
240
+ // screen: Tab
241
+ // },
242
+ // Detail: {
243
+ // screen: Detail
244
+ // }
245
+ // // Web: { screen: WebScene },
246
+ // // GroupPurchase: { screen: GroupPurchaseScene },
247
+ // },
248
+ // {
249
+ // defaultNavigationOptions: {
250
+ // headerBackTitle: null,
251
+ // headerTintColor: '#333333',
252
+ // showIcon: true,
253
+ // },
254
+ // }
255
+ // )
150
256
151
- const AppContainer = createAppContainer ( AppNavigator ) ;
257
+ let AppContainer = createAppContainer ( AppNavigator ( ) )
258
+ // const AppContainer = createAppContainer(AppNavigator());
152
259
export default App
0 commit comments