-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathindex.tsx
More file actions
162 lines (152 loc) · 3.79 KB
/
index.tsx
File metadata and controls
162 lines (152 loc) · 3.79 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
import React, { useRef, useState } from 'react';
import { StyleSheet, Text, View, TextInput } from 'react-native';
import { DrawerType, RectButton } from 'react-native-gesture-handler';
import {
DrawerLayoutController,
DrawerLayout,
} from './BetterHorizonatalDrawer';
import Animated, {
useAnimatedStyle,
interpolate,
} from 'react-native-reanimated';
const TYPES: DrawerType[] = ['front', 'back', 'back', 'slide'];
const PARALLAX = [false, false, true, false];
interface PageProps {
fromLeft: boolean;
type: DrawerType;
parallaxOn: boolean;
flipSide: () => void;
nextType: () => void;
openDrawer: () => void;
}
function Page({
fromLeft,
type,
parallaxOn,
flipSide,
nextType,
openDrawer,
}: PageProps) {
return (
<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>
);
}
function DrawerContent(
offset: Animated.SharedValue<number>,
parallax: boolean,
fromLeft: boolean
) {
const animatedStyles = useAnimatedStyle(() => ({
transform: [
{
translateX: parallax
? interpolate(offset.value, [0, 1], [fromLeft ? -50 : 50, 0])
: 0,
},
],
}));
return (
<Animated.View style={[styles.drawerContainer, animatedStyles]}>
<Text style={styles.drawerText}>
{parallax ? 'Drawer with parallax' : 'Drawer'}
</Text>
</Animated.View>
);
}
export default function Example() {
const [onLeft, setOnLeft] = useState(true);
const [type, setType] = useState(0);
const controller = useRef<DrawerLayoutController>(null);
return (
<View style={styles.container}>
<DrawerLayout
drawerPosition={onLeft ? 'left' : 'right'}
drawerType={TYPES[type]}
renderNavigationView={(offset) => {
return DrawerContent(offset, PARALLAX[type], onLeft);
}}
keyboardDismissMode="on-drag"
drawerBackgroundColor="white"
ref={controller}>
<Page
fromLeft={onLeft}
flipSide={() => {
setOnLeft(!onLeft);
}}
type={TYPES[type]}
nextType={() => {
setType((type + 1) % TYPES.length);
}}
parallaxOn={PARALLAX[type]}
openDrawer={() => {
controller.current?.open();
}}
/>
</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',
},
});