-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDrawerLayoutExample.js
93 lines (83 loc) · 2.36 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
'use strict';
import React from 'react-native';
const { View, Text, StyleSheet, TouchableHighlight, TextInput, Image, InteractionManager } = React;
var DrawerLayout = require('react-native-drawer-layout');
function increaseCounter() {
setTimeout(function() {
this.setState({
counter: this.state.counter + 1
});
increaseCounter.call(this);
}.bind(this), 100);
}
function doExpensiveOperation() {
console.log('Starting expensive operation');
var i;
for (i = 0; i < Math.pow(2, 23); i++) {
i * i;
}
console.log('Finishing expensive operation');
}
var DrawerLayoutExample = React.createClass({
componentWillMount() {
increaseCounter.call(this);
},
getInitialState() {
return {
counter: 0,
};
},
render: function() {
var navigationView = (
<View style={[styles.container, {backgroundColor: '#fff'}]}>
<Text>Hello there!</Text>
<Image style={{
height: 200,
width: 200,
transform: [{
rotateX: ('' + this.state.counter + 'deg')
}]
}} source={{uri: 'http://placekitten.com/801/800' }} />
<TouchableHighlight onPress={() => this.drawer.closeDrawer()}>
<Text>Close drawer</Text>
</TouchableHighlight>
</View>
);
return (
<DrawerLayout
onDrawerSlide={e => {
this.setState({drawerSlideOutput: JSON.stringify(e.nativeEvent)});
InteractionManager.runAfterInteractions(doExpensiveOperation);
}}
onDrawerStateChanged={(e) => this.setState({drawerStateChangedOutput: JSON.stringify(e)})}
drawerWidth={300}
ref={(drawer) => { return this.drawer = drawer }}
keyboardDismissMode="on-drag"
renderNavigationView={() => navigationView}>
<View style={styles.container}>
<Text style={styles.welcome}>Content!</Text>
<Text>{this.state.drawerStateChangedOutput}</Text>
<Text>{this.state.drawerSlideOutput}</Text>
<Text>{this.state.counter}</Text>
</View>
</DrawerLayout>
);
}
});
var styles = StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center',
flex: 1
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
inputField: {
backgroundColor: '#F2F2F2',
height: 40,
},
});
module.exports = DrawerLayoutExample;