-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.web.js
109 lines (100 loc) · 2.8 KB
/
index.web.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
import {Provider} from 'react-redux'
import React, {
AppRegistry, StyleSheet, TouchableOpacity, View, Text, Component, Navigator,
}
from 'react-native'
import configureStore from './store/configureStore'
import MainTabBar from './containers/MainTabBar.react'
import StoryDetail from './containers/StoryDetail.react'
import StoryList from './containers/StoryList.react'
const store = configureStore()
let NavigationBarRouteMapper = {
LeftButton(route, navigator, index, navState) {
if (index === 0) {
return null;
}
return (
<TouchableOpacity
onPress={() => navigator.pop()}
style={styles.navBarLeftButton}>
<Text style={[styles.navBarText, styles.navBarButtonText]}>返回</Text>
</TouchableOpacity>
)
},
RightButton(route, navigator, index, navState) {
return (
<View />
)
},
Title(route, navigator, index, navState) {
if (!route.title) {
return (
<Text style={[styles.navBarText, styles.navBarTitleText]}>
我的WebApp
</Text>
)
}
return (
<Text style={[styles.navBarText, styles.navBarTitleText]}>
{route.title}
</Text>
)
}
}
let RouteMapper = function(route, navigator) {
switch (route.name) {
case 'storyList':
return <StoryList navigator={navigator} />
case 'storyDetail':
return <StoryDetail navigator={navigator} detailId={route.detailId} />
case 'mainTabBar':
default:
return <MainTabBar navigator={navigator} />
}
}
class ReactNativeRedux extends Component {
render() {
return (
<Provider store={store}>
<Navigator
style={styles.container}
initialRoute={{name: 'mainTabBar'}}
renderScene={RouteMapper}
navigationBar={
<Navigator.NavigationBar
routeMapper={NavigationBarRouteMapper}
style={styles.navBar}
/>
}
/>
</Provider>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
navBar: {
backgroundColor: '#333',
height: 54,
top: -10,
},
navBarText: {
fontSize: 16
},
navBarTitleText: {
color: '#fff',
},
navBarLeftButton: {
color: '#fff',
paddingLeft: 10,
},
});
AppRegistry.registerComponent('ReactNativeRedux', () => ReactNativeRedux);
//web
let app = document.createElement('div');
document.body.appendChild(app);
AppRegistry.runApplication('ReactNativeRedux', {
rootTag: app
});