-
Notifications
You must be signed in to change notification settings - Fork 8
/
DrawerLayoutExample.js
142 lines (134 loc) · 3.88 KB
/
DrawerLayoutExample.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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
const {
I18nManager,
ScrollView,
StyleSheet,
Switch,
Text,
TextInput,
TouchableHighlight,
View,
} = ReactNative;
import DrawerLayout from 'react-native-drawer-layout';
var DrawerLockModeSwitches = React.createClass({
render: function() {
const {value, onValueChange} = this.props;
return (
<ScrollView style={styles.drawerLock}>
<View style={[styles.container, styles.split]}>
<Switch
onValueChange={value =>
(value ? onValueChange('unlocked') : onValueChange('unlocked'))}
value={value === 'unlocked'}
/>
<Text style={styles.spacedLeft}>Unlocked</Text>
</View>
<View style={[styles.container, styles.split]}>
<Switch
onValueChange={value =>
(value
? onValueChange('locked-closed')
: onValueChange('unlocked'))}
value={value === 'locked-closed'}
/>
<Text style={styles.spacedLeft}>locked-closed</Text>
</View>
<View style={[styles.container, styles.split]}>
<Switch
onValueChange={value =>
(value
? onValueChange('locked-open')
: onValueChange('unlocked'))}
value={value === 'locked-open'}
/>
<Text style={styles.spacedLeft}>locked-open</Text>
</View>
</ScrollView>
);
},
});
var DrawerLayoutExample = React.createClass({
getInitialState() {
return {
drawerLockMode: 'unlocked',
};
},
render: function() {
const {drawerLockMode} = this.state;
const navigationView = (
<View style={[styles.container]}>
<Text>Hello there!</Text>
<DrawerLockModeSwitches
value={drawerLockMode}
onValueChange={value => this.setState({drawerLockMode: value})}
/>
<TouchableHighlight onPress={() => this.drawer.closeDrawer()}>
<Text>Close drawer</Text>
</TouchableHighlight>
</View>
);
return (
<DrawerLayout
onDrawerSlide={e =>
this.setState({drawerSlideOutput: JSON.stringify(e.nativeEvent)})}
onDrawerStateChanged={e =>
this.setState({drawerStateChangedOutput: JSON.stringify(e)})}
drawerBackgroundColor="red"
drawerWidth={300}
drawerLockMode={drawerLockMode}
ref={drawer => {
return (this.drawer = drawer);
}}
keyboardDismissMode="on-drag"
statusBarBackgroundColor="blue"
renderNavigationView={() => navigationView}>
<ScrollView containerStyle={styles.container}>
<Text style={styles.welcome}>Content!</Text>
<DrawerLockModeSwitches
value={drawerLockMode}
onValueChange={value => this.setState({drawerLockMode: value})}
/>
<Text>{this.state.drawerStateChangedOutput}</Text>
<Text>{this.state.drawerSlideOutput}</Text>
<TouchableHighlight onPress={() => this.drawer.openDrawer()}>
<Text>Open drawer</Text>
</TouchableHighlight>
<TouchableHighlight
onPress={() => I18nManager.forceRTL(!I18nManager.isRTL)}>
<Text>Toggle RTL: {I18nManager.isRTL ? 'yes' : 'no'}</Text>
</TouchableHighlight>
<TextInput style={styles.inputField} />
</ScrollView>
</DrawerLayout>
);
},
});
var styles = StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center',
flex: 1,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
inputField: {
backgroundColor: '#F2F2F2',
height: 40,
},
split: {
flexDirection: 'row',
},
spacedLeft: {
paddingLeft: 10,
},
drawerLock: {
height: 200,
paddingTop: 50,
},
});
module.exports = DrawerLayoutExample;