-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
260 lines (240 loc) · 7.75 KB
/
App.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Image, StatusBar } from 'react-native';
import { createStackNavigator, NavigationActions, StackViewTransitionConfigs, createBottomTabNavigator, createAppContainer, TabBarBottom } from 'react-navigation'
import { getSession } from './src/utils'
import Home from './src/views/Home'
import Detail from './src/views/Detail'
import Info from './src/views/Info'
import Me from './src/views/Me'
import Message from './src/views/Message'
import Publish from './src/views/Publish'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import Index from './src/store'
// import codePush from 'react-native-code-push'
// AsyncStorage.setItem('userinfo', 'I like to save it.')
// const storeUserinfo = AsyncStorage.getItem('userinfo')
// let islogin
// console.log(this);
// getSession('loginname')
// const TITLE_OFFSET = Platform.OS === 'ios' ? 70 : 56;
const store = createStore(Index)
store.subscribe(() => {
//监听state变化
// console.log(store.getState());
// console.log(Tab);
Tab(store)
// AppContainer = createAppContainer(AppNavigator(store));
});
// let a = getSession('loginname')
// console.log(a._55, a);
// console.log(store.getState());
// console.log(AsyncStorage.getItem('userinfo'));
class App extends Component {
// componentDidMount () {
// codePush.sync({
// updateDialog: {
// appendReleaseDescription: true,
// descriptionPrefix: '',
// mandatoryUpdateMessage: '',
// mandatoryContinueButtonLabel: '立即更新',
// optionalIgnoreButtonLabel: '稍后',
// optionalInstallButtonLabel: '后台更新',
// optionalUpdateMessage: '',
// title: '更新提示'
// },
// installMode: codePush.InstallMode.IMMEDIATE,
// mandatoryInstallMode: codePush.InstallMode.IMMEDIATE,
// deploymentKey: '4a4ca83f-18e2-4262-be4c-b8d8e548049e'
// })
// }
render () {
// console.log(this.state.login);
// console.log(store.getState());
// const AppContainer = createAppContainer(AppNavigator(store));
return (
<Provider store={store}>
<AppContainer
onNavigationStateChange={
(prevState, currentState, action) => {
StatusBar.setBarStyle('dark-content')
}
}
/>
</Provider>
)
}
}
function Tab(params) {
// console.log(params);
this.params = params
return createBottomTabNavigator(
{
Home: {
screen: createStackNavigator({ home: Home }),
navigationOptions: ({ navigation }) => ({
// tabBarVisible: false,
// header: null,
tabBarLabel: '发布',
tabBarOnPress: ({defaultHandler, navigation}) => {
// console.log(defaultHandler);
// console.log(1111);
// navigation.navigate('Home')
// console.log(navigation);
// console.log(navigation.state.routes[0]);
navigation.state.routes[0].params.queryData();//查询数据
defaultHandler()
},
tabBarIcon: ({ focused, tintColor }) => (
// normalImage='https://www.easyicon.net/api/resizeApi.php?id=1225464&size=16'
// normalImage={require('./src/assets/tabbar_merchant.png')}
// selectedImage={require('./src/assets/tabbar_merchant.png')}
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/home.png')}></Image>
)
}),
},
Publish: {
screen: createStackNavigator({ publish: Publish }),
navigationOptions: ({ navigation }) => ({
tabBarLabel: '发布',
tabBarOnPress: ({defaultHandler, navigation}) => {
// console.log(defaultHandler);
jundeLogin(defaultHandler, navigation)
},
tabBarIcon: ({ focused, tintColor }) => (
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/publish.png')}></Image>
)
}),
},
Message: {
screen: createStackNavigator({ message: Message }),
navigationOptions: ({ navigation }) => ({
tabBarLabel: '消息',
tabBarOnPress: ({defaultHandler, navigation}) => {
// console.log(defaultHandler);
jundeLogin(defaultHandler, navigation)
},
tabBarIcon: ({ focused, tintColor }) => (
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/message.png') }></Image>
)
}),
},
Mine: {
screen: createStackNavigator({ Mine: Me }),
navigationOptions: ({ navigation }) => ({
tabBarLabel: '我的',
tabBarIcon: ({ focused, tintColor }) => (
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/me.png') }></Image>
)
}),
},
Info: {
screen: createStackNavigator({ Info: Info }),
// paths: 'people/:name',
navigationOptions: ({ navigation }) => ({
title: '关于',
tabBarVisible: false,
// tabBarOnPress: ({defaultHandler, navigation}) => {
// // console.log(defaultHandler);
// jundeLogin(defaultHandler, navigation)
// },
tabBarIcon: ({ focused, tintColor }) => (
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/info.png') }></Image>
)
}),
},
},
{
tabBarComponent: TabBarBottom,
tabBarPosition: 'bottom',
lazy: true,
animationEnabled: false,
swipeEnabled: false,
tabBarOptions: {
activeTintColor: 'red',
inactiveTintColor: 'green',
style: { backgroundColor: '#ffffff' },
},
})
}
const IOS_MODAL_ROUTES = ['home', 'Info']
const dynamicModalTransition = (transitionProps, prevTransitionProps) => {
const isModal = IOS_MODAL_ROUTES.some(
screenName =>
screenName === transitionProps.scene.route.routeName ||
(prevTransitionProps && screenName === prevTransitionProps.scene.route.routeName)
)
return StackViewTransitionConfigs.defaultTransitionConfig(
transitionProps,
prevTransitionProps,
isModal
);
};
function jundeLogin (defaultHandler, navigation) {
let login = this.params.getState().login
if (!login || login === '') {
navigation.navigate('Mine')
} else {
defaultHandler()
}
}
// Tabs.navigationOptions = {
// header: null,
// };
function AppNavigator(store) {
let Tabs = Tab(store)
console.log(Tabs);
Tabs.navigationOptions = {
header: null,
// header: { visible: false },
// headerStyle: {
// backgroundColor: 'yellow',
// },
// headerTitleStyle:{
// alignSelf:'center',
// textAlign: 'center',
// flex:1,
// },
// headerTitleContainerStyle:{
// left: TITLE_OFFSET,
// right: TITLE_OFFSET,
// }
};
let login
if (store) {
login = store.getState().login
}
// console.log(store.getState().login);
return createStackNavigator(
{
Tab: {
screen: Tabs
},
Detail: {
screen: Detail
}
},
{
// transitionConfig: dynamicModalTransition,
defaultNavigationOptions: {
headerBackTitle: null,
// header: null,
// headerStyle: {
// backgroundColor: '#f4511e',
// },
headerTintColor: '#333333',
showIcon: false,
},
}
)
}
let AppContainer = createAppContainer(AppNavigator())
// const AppContainer = createAppContainer(AppNavigator());
export default App