forked from software-mansion/react-native-gesture-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
178 lines (169 loc) · 4.64 KB
/
index.js
File metadata and controls
178 lines (169 loc) · 4.64 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
Animated,
View,
TextInput,
} from 'react-native';
import { RectButton } from 'react-native-gesture-handler';
import DrawerLayout from 'react-native-gesture-handler/DrawerLayout';
const TYPES = ['front', 'back', 'back', 'slide'];
const PARALLAX = [false, false, true, false];
const Page = ({
fromLeft,
type,
parallaxOn,
flipSide,
nextType,
openDrawer,
}) => (
<View style={styles.page}>
<Text style={styles.pageText}>Hi 👋</Text>
<RectButton style={styles.rectButton} onPress={flipSide}>
<Text style={styles.rectButtonText}>
Drawer to the {fromLeft ? 'left' : 'right'}! -> Flip
</Text>
</RectButton>
<RectButton style={styles.rectButton} onPress={nextType}>
<Text style={styles.rectButtonText}>
Type '{type}
{parallaxOn && ' with parallax'}'! -> Next
</Text>
</RectButton>
<RectButton style={styles.rectButton} onPress={openDrawer}>
<Text style={styles.rectButtonText}>Open drawer</Text>
</RectButton>
<TextInput
style={styles.pageInput}
placeholder="Just an input field to test kb dismiss mode"
/>
</View>
);
export default class Example extends Component {
state = { fromLeft: true, type: 0 };
renderParallaxDrawer = progressValue => {
const parallax = progressValue.interpolate({
inputRange: [0, 1],
outputRange: [this.state.fromLeft ? -50 : 50, 0],
});
const animatedStyles = {
transform: [{ translateX: parallax }],
};
return (
<Animated.View style={[styles.drawerContainer, animatedStyles]}>
<Text style={styles.drawerText}>I am in the drawer!</Text>
<Text style={styles.drawerText}>
Watch parallax animation while you pull the drawer!
</Text>
</Animated.View>
);
};
renderDrawer = () => {
return (
<View style={styles.drawerContainer}>
<Text style={styles.drawerText}>I am in the drawer!</Text>
</View>
);
};
render() {
const drawerType = TYPES[this.state.type];
const parallax = PARALLAX[this.state.type];
return (
<View style={styles.container}>
<DrawerLayout
ref={drawer => {
this.drawer = drawer;
}}
drawerWidth={200}
keyboardDismissMode="on-drag"
drawerPosition={
this.state.fromLeft
? DrawerLayout.positions.Left
: DrawerLayout.positions.Right
}
drawerType={drawerType}
drawerBackgroundColor="#ddd"
overlayColor={drawerType === 'front' ? 'black' : '#00000000'}
renderNavigationView={
parallax ? this.renderParallaxDrawer : this.renderDrawer
}
contentContainerStyle={
// careful; don't elevate the child container
// over top of the drawer when the drawer is supposed
// to be in front - you won't be able to see/open it.
drawerType === 'front'
? {}
: Platform.select({
ios: {
shadowColor: '#000',
shadowOpacity: 0.5,
shadowOffset: { width: 0, height: 2 },
shadowRadius: 60,
},
android: {
elevation: 100,
backgroundColor: '#000',
},
})
}>
<Page
type={drawerType}
fromLeft={this.state.fromLeft}
parallaxOn={parallax}
flipSide={() => this.setState({ fromLeft: !this.state.fromLeft })}
nextType={() =>
this.setState({ type: (this.state.type + 1) % TYPES.length })}
openDrawer={() => this.drawer.openDrawer()}
/>
</DrawerLayout>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
page: {
...StyleSheet.absoluteFillObject,
alignItems: 'center',
paddingTop: 40,
backgroundColor: 'gray',
},
pageText: {
fontSize: 21,
color: 'white',
},
rectButton: {
height: 60,
padding: 10,
alignSelf: 'stretch',
alignItems: 'center',
justifyContent: 'center',
marginTop: 20,
backgroundColor: 'white',
},
rectButtonText: {
backgroundColor: 'transparent',
},
drawerContainer: {
flex: 1,
paddingTop: 10,
},
pageInput: {
height: 60,
padding: 10,
alignSelf: 'stretch',
alignItems: 'center',
justifyContent: 'center',
marginTop: 20,
backgroundColor: '#eee',
},
drawerText: {
margin: 10,
fontSize: 15,
textAlign: 'left',
},
});