-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.web.js
123 lines (117 loc) · 2.74 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* web 入口文件
*/
'use strict';
var React = require('react-native');
var MainTabBar = require('./MainTabBar.react');
var StoryList = require('./views/StoryList.react');
var StoryDetail = require('./views/StoryDetail.react');
var {
AppRegistry,
Navigator,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
} = React;
var NavigationBarRouteMapper = {
LeftButton: function(route, navigator, index, navState) {
if (index === 0) {
return null;
}
return (
<TouchableOpacity
onPress={() => navigator.pop()}
style={styles.navBarLeftButton}>
<Image
source={{uri:'./images/icon-back.imageset/[email protected]'}}
style={styles.navBarLeftIcon} />
</TouchableOpacity>
);
},
RightButton: function(route, navigator, index, navState) {
return (
<View/>
);
},
Title: function(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.length>16 ? route.title.substring(0, 16) + '...' : route.title}
</Text>
);
},
};
var RouteMapper = function(route, navigator) {
switch(route.name){
case 'storyList':
return (
<StoryList navigator={navigator} />
);
case 'storyDetail':
return (
<StoryDetail
navigator={navigator}
detailId={route.detailId} />
);
default:
return (
<MainTabBar navigator={navigator} />
);
}
};
var ReactNativeWeb = React.createClass({
render: function(){
var initialRoute = {name: 'MainTabBar'};
return (
<Navigator
style={styles.container}
initialRoute={initialRoute}
renderScene={RouteMapper}
navigationBar={
<Navigator.NavigationBar
routeMapper={NavigationBarRouteMapper}
style={styles.navBar}
/>
}
/>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
},
navBar: {
backgroundColor: '#333',
height: 54,
top:-10,
},
navBarText: {
fontSize: 16
},
navBarTitleText: {
color: '#fff',
},
navBarLeftButton: {
color: '#fff',
paddingLeft: 10,
},
navBarLeftIcon:{
height:32,
width:22,
},
});
AppRegistry.registerComponent('ReactNativeWeb', () => ReactNativeWeb);
//web
var app = document.createElement('div');
document.body.appendChild(app);
AppRegistry.runApplication('ReactNativeWeb', {rootTag: app});