Skip to content

Commit 65b292b

Browse files
committed
Narrowing the examples to just the example with nested items
1 parent 5cb2216 commit 65b292b

File tree

1 file changed

+10
-72
lines changed

1 file changed

+10
-72
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/components/NavigationDrawer.kt

Lines changed: 10 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -43,49 +43,15 @@ import androidx.compose.ui.text.style.TextAlign
4343
import androidx.compose.ui.tooling.preview.Preview
4444
import androidx.compose.ui.unit.dp
4545

46-
enum class ExampleStrings(val description: String) {
47-
SIMPLE("simple navigation drawer example"),
48-
NESTED("navigation drawer with nested items")
49-
}
46+
const val HELP_TEXT = "Swipe from left to open navigation drawer with nested items."
5047

5148
@Composable
5249
fun NavigationDrawerExamples() {
53-
var currentExample by remember { mutableStateOf<ExampleStrings?>(null) }
54-
55-
if (currentExample == null) {
56-
Column() {
57-
Text(
58-
text = "Select which example you'd like to see.",
59-
textAlign = TextAlign.Center,
60-
modifier = Modifier
61-
.fillMaxWidth()
62-
.padding(16.dp)
63-
)
64-
65-
Button(onClick = { currentExample = ExampleStrings.SIMPLE }) {
66-
Text("Simple navigation drawer.")
67-
}
68-
Button(onClick = { currentExample = ExampleStrings.NESTED }) {
69-
Text("Navigation drawer with nested items.")
70-
}
50+
NestedNavigationDrawerExample(
51+
screenContent = {
52+
Text(HELP_TEXT)
7153
}
72-
}
73-
74-
Column(modifier = Modifier.fillMaxSize()) {
75-
Text(
76-
text = "Swipe from left to open the ${currentExample!!.description}.",
77-
textAlign = TextAlign.Center,
78-
modifier = Modifier
79-
.fillMaxWidth()
80-
.padding(16.dp)
81-
)
82-
}
83-
84-
when (currentExample) {
85-
null,
86-
ExampleStrings.SIMPLE -> SimpleNavigationDrawerExample()
87-
ExampleStrings.NESTED -> NestedNavigationDrawerExample()
88-
}
54+
)
8955
}
9056

9157
@Preview
@@ -94,36 +60,6 @@ private fun NavigationDrawerExamplesPreview() {
9460
NavigationDrawerExamples()
9561
}
9662

97-
// [START android_compose_components_simplenavigationdrawerexample]
98-
@Composable
99-
fun SimpleNavigationDrawerExample() {
100-
ModalNavigationDrawer(
101-
drawerContent = {
102-
ModalDrawerSheet {
103-
NavigationDrawerItem(
104-
label = { Text(text = "Item 1") },
105-
selected = false,
106-
onClick = { /* Do something... */ }
107-
)
108-
NavigationDrawerItem(
109-
label = { Text(text = "Item 2") },
110-
selected = false,
111-
onClick = { /* Do something... */ }
112-
)
113-
}
114-
}
115-
) {
116-
// Screen content
117-
}
118-
}
119-
// [END android_compose_components_simplenavigationdrawerexample]
120-
121-
@Preview
122-
@Composable
123-
private fun SimpleNavigationDrawerExamplePreview() {
124-
SimpleNavigationDrawerExample()
125-
}
126-
12763
// [START android_compose_components_navigationdrawergroupitem]
12864
@Composable
12965
fun NavigationDrawerGroupItem(
@@ -153,7 +89,9 @@ fun NavigationDrawerGroupItem(
15389

15490
// [START android_compose_components_nestednavigationdrawerexample]
15591
@Composable
156-
fun NestedNavigationDrawerExample() {
92+
fun NestedNavigationDrawerExample(
93+
screenContent: @Composable () -> Unit,
94+
) {
15795
ModalNavigationDrawer(
15896
drawerContent = {
15997
ModalDrawerSheet {
@@ -197,13 +135,13 @@ fun NestedNavigationDrawerExample() {
197135
}
198136
}
199137
) {
200-
// Screen content
138+
screenContent()
201139
}
202140
}
203141
// [END android_compose_components_nestednavigationdrawerexample]
204142

205143
@Preview
206144
@Composable
207145
private fun NestedNavigationDrawerExamplePreview() {
208-
NestedNavigationDrawerExample()
146+
NestedNavigationDrawerExample{ Text(HELP_TEXT) }
209147
}

0 commit comments

Comments
 (0)