-
Notifications
You must be signed in to change notification settings - Fork 804
/
MainScreen.android.js
98 lines (90 loc) · 2.56 KB
/
MainScreen.android.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
'use strict';
var React = require('react-native');
var {
AsyncStorage,
Image,
StyleSheet,
Text,
View,
DrawerLayoutAndroid,
ToolbarAndroid,
ToastAndroid,
BackAndroid,
TouchableOpacity,
Dimensions,
} = React;
var Drawer = require('react-native-drawer');
var StoriesList = require('./StoriesList');
var ThemesList = require('./ThemesList');
var SwipeRefreshLayoutAndroid = require('./SwipeRereshLayout');
var DRAWER_REF = 'drawer';
var DRAWER_WIDTH_LEFT = 56;
var toolbarActions = [
{title: '提醒', icon: require('image!ic_message_white'), show: 'always'},
{title: '夜间模式', show: 'never'},
{title: '设置选项', show: 'never'},
];
var MainScreen = React.createClass({
getInitialState: function() {
return ({
theme: null,
});
},
onSelectTheme: function(theme) {
this.refs[DRAWER_REF].closeDrawer();
this.setState({theme: theme});
},
_renderNavigationView: function() {
return (
<ThemesList
onSelectItem={this.onSelectTheme}
/>
);
},
onRefresh: function() {
this.onSelectTheme(this.state.theme);
},
onRefreshFinish: function() {
this.swipeRefreshLayout && this.swipeRefreshLayout.finishRefresh();
},
render: function() {
var title = this.state.theme ? this.state.theme.name : '首页';
return (
<DrawerLayoutAndroid
ref={DRAWER_REF}
drawerWidth={Dimensions.get('window').width - DRAWER_WIDTH_LEFT}
keyboardDismissMode="on-drag"
drawerPosition={DrawerLayoutAndroid.positions.Left}
renderNavigationView={this._renderNavigationView}>
<View style={styles.container}>
<ToolbarAndroid
navIcon={require('image!ic_menu_white')}
title={title}
titleColor="white"
style={styles.toolbar}
actions={toolbarActions}
onIconClicked={() => this.refs[DRAWER_REF].openDrawer()}
onActionSelected={this.onActionSelected} />
<SwipeRefreshLayoutAndroid
ref={(swipeRefreshLayout) => { this.swipeRefreshLayout = swipeRefreshLayout; }}
onSwipeRefresh={this.onRefresh}>
<StoriesList theme={this.state.theme} navigator={this.props.navigator}
onRefreshFinish={this.onRefreshFinish}/>
</SwipeRefreshLayoutAndroid>
</View>
</DrawerLayoutAndroid>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
backgroundColor: '#FAFAFA',
},
toolbar: {
backgroundColor: '#00a2ed',
height: 56,
},
});
module.exports = MainScreen;