Skip to content

Commit aa97a8f

Browse files
bravadomizzouSimek
andauthored
Update drawerlayoutandroid.md (facebook#2342)
* Update drawerlayoutandroid.md More detailed example of how to use openDrawer and closeDrawer * revert changes, update snack example, update base docs Co-authored-by: Bartosz Kaszubowski <[email protected]>
1 parent 92f92be commit aa97a8f

File tree

2 files changed

+52
-32
lines changed

2 files changed

+52
-32
lines changed

docs/drawerlayoutandroid.md

+26-16
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ React component that wraps the platform `DrawerLayout` (Android only). The Drawe
88
## Example
99

1010
```SnackPlayer name=DrawerLayoutAndroid%20Component%20Example&supportedPlatforms=android
11-
import React, { useState } from "react";
11+
import React, { useRef, useState } from "react";
1212
import { Button, DrawerLayoutAndroid, Text, StyleSheet, View } from "react-native";
1313
1414
const App = () => {
15+
const drawer = useRef(null);
1516
const [drawerPosition, setDrawerPosition] = useState("left");
1617
const changeDrawerPosition = () => {
1718
if (drawerPosition === "left") {
@@ -21,29 +22,38 @@ const App = () => {
2122
}
2223
};
2324
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+
/>
2732
</View>
2833
);
2934
3035
return (
3136
<DrawerLayoutAndroid
37+
ref={drawer}
3238
drawerWidth={300}
3339
drawerPosition={drawerPosition}
34-
renderNavigationView={() => navigationView}
40+
renderNavigationView={navigationView}
3541
>
3642
<View style={styles.container}>
37-
<Text style={{ margin: 10, fontSize: 15 }}>
38-
DrawerLayoutAndroid example
43+
<Text style={styles.paragraph}>
44+
Drawer on the {drawerPosition}!
3945
</Text>
4046
<Button
4147
title="Change Drawer Position"
4248
onPress={() => changeDrawerPosition()}
4349
/>
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!
4652
</Text>
53+
<Button
54+
title="Open drawer"
55+
onPress={() => drawer.current.openDrawer()}
56+
/>
4757
</View>
4858
</DrawerLayoutAndroid>
4959
);
@@ -54,15 +64,15 @@ const styles = StyleSheet.create({
5464
flex: 1,
5565
alignItems: "center",
5666
justifyContent: "center",
57-
paddingTop: 50,
58-
backgroundColor: "#ecf0f1",
59-
padding: 8
67+
padding: 16
6068
},
6169
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"
6676
}
6777
});
6878

website/versioned_docs/version-0.63/drawerlayoutandroid.md

+26-16
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ React component that wraps the platform `DrawerLayout` (Android only). The Drawe
88
## Example
99

1010
```SnackPlayer name=DrawerLayoutAndroid%20Component%20Example&supportedPlatforms=android
11-
import React, { useState } from "react";
11+
import React, { useRef, useState } from "react";
1212
import { Button, DrawerLayoutAndroid, Text, StyleSheet, View } from "react-native";
1313
1414
const App = () => {
15+
const drawer = useRef(null);
1516
const [drawerPosition, setDrawerPosition] = useState("left");
1617
const changeDrawerPosition = () => {
1718
if (drawerPosition === "left") {
@@ -21,29 +22,38 @@ const App = () => {
2122
}
2223
};
2324
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+
/>
2732
</View>
2833
);
2934
3035
return (
3136
<DrawerLayoutAndroid
37+
ref={drawer}
3238
drawerWidth={300}
3339
drawerPosition={drawerPosition}
34-
renderNavigationView={() => navigationView}
40+
renderNavigationView={navigationView}
3541
>
3642
<View style={styles.container}>
37-
<Text style={{ margin: 10, fontSize: 15 }}>
38-
DrawerLayoutAndroid example
43+
<Text style={styles.paragraph}>
44+
Drawer on the {drawerPosition}!
3945
</Text>
4046
<Button
4147
title="Change Drawer Position"
4248
onPress={() => changeDrawerPosition()}
4349
/>
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!
4652
</Text>
53+
<Button
54+
title="Open drawer"
55+
onPress={() => drawer.current.openDrawer()}
56+
/>
4757
</View>
4858
</DrawerLayoutAndroid>
4959
);
@@ -54,15 +64,15 @@ const styles = StyleSheet.create({
5464
flex: 1,
5565
alignItems: "center",
5666
justifyContent: "center",
57-
paddingTop: 50,
58-
backgroundColor: "#ecf0f1",
59-
padding: 8
67+
padding: 16
6068
},
6169
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"
6676
}
6777
});
6878

0 commit comments

Comments
 (0)