@@ -8,10 +8,11 @@ React component that wraps the platform `DrawerLayout` (Android only). The Drawe
8
8
## Example
9
9
10
10
``` SnackPlayer name=DrawerLayoutAndroid%20Component%20Example&supportedPlatforms=android
11
- import React, { useState } from "react";
11
+ import React, { useRef, useState } from "react";
12
12
import { Button, DrawerLayoutAndroid, Text, StyleSheet, View } from "react-native";
13
13
14
14
const App = () => {
15
+ const drawer = useRef(null);
15
16
const [drawerPosition, setDrawerPosition] = useState("left");
16
17
const changeDrawerPosition = () => {
17
18
if (drawerPosition === "left") {
@@ -21,29 +22,38 @@ const App = () => {
21
22
}
22
23
};
23
24
24
- const navigationView = (
25
- <View style={styles.navigationContainer}>
26
- <Text style={{ margin: 10, fontSize: 15 }}>I'm in the Drawer!</Text>
25
+ const navigationView = () => (
26
+ <View style={[styles.container, styles.navigationContainer]}>
27
+ <Text style={styles.paragraph}>I'm in the Drawer!</Text>
28
+ <Button
29
+ title="Close drawer"
30
+ onPress={() => drawer.current.closeDrawer()}
31
+ />
27
32
</View>
28
33
);
29
34
30
35
return (
31
36
<DrawerLayoutAndroid
37
+ ref={drawer}
32
38
drawerWidth={300}
33
39
drawerPosition={drawerPosition}
34
- renderNavigationView={() => navigationView}
40
+ renderNavigationView={navigationView}
35
41
>
36
42
<View style={styles.container}>
37
- <Text style={{ margin: 10, fontSize: 15 } }>
38
- DrawerLayoutAndroid example
43
+ <Text style={styles.paragraph }>
44
+ Drawer on the {drawerPosition}!
39
45
</Text>
40
46
<Button
41
47
title="Change Drawer Position"
42
48
onPress={() => changeDrawerPosition()}
43
49
/>
44
- <Text style={{ margin: 10, fontSize: 15 } }>
45
- Drawer on the {drawerPosition}! Swipe from the side to see!
50
+ <Text style={styles.paragraph }>
51
+ Swipe from the side or press button below to see it !
46
52
</Text>
53
+ <Button
54
+ title="Open drawer"
55
+ onPress={() => drawer.current.openDrawer()}
56
+ />
47
57
</View>
48
58
</DrawerLayoutAndroid>
49
59
);
@@ -54,15 +64,15 @@ const styles = StyleSheet.create({
54
64
flex: 1,
55
65
alignItems: "center",
56
66
justifyContent: "center",
57
- paddingTop: 50,
58
- backgroundColor: "#ecf0f1",
59
- padding: 8
67
+ padding: 16
60
68
},
61
69
navigationContainer: {
62
- flex: 1,
63
- paddingTop: 50,
64
- backgroundColor: "#fff",
65
- padding: 8
70
+ backgroundColor: "#ecf0f1"
71
+ },
72
+ paragraph: {
73
+ padding: 16,
74
+ fontSize: 15,
75
+ textAlign: "center"
66
76
}
67
77
});
68
78
0 commit comments