Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation drawer examples #380

Merged
merged 20 commits into from
Oct 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Narrowing the examples to just the example with nested items
  • Loading branch information
jakeroseman committed Oct 14, 2024
commit 65b292b1ce509cfa4cbc0a80021a2c058eb8165c
Original file line number Diff line number Diff line change
Expand Up @@ -43,49 +43,15 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

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

@Composable
fun NavigationDrawerExamples() {
var currentExample by remember { mutableStateOf<ExampleStrings?>(null) }

if (currentExample == null) {
Column() {
Text(
text = "Select which example you'd like to see.",
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
)

Button(onClick = { currentExample = ExampleStrings.SIMPLE }) {
Text("Simple navigation drawer.")
}
Button(onClick = { currentExample = ExampleStrings.NESTED }) {
Text("Navigation drawer with nested items.")
}
NestedNavigationDrawerExample(
screenContent = {
Text(HELP_TEXT)
}
}

Column(modifier = Modifier.fillMaxSize()) {
Text(
text = "Swipe from left to open the ${currentExample!!.description}.",
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
)
}

when (currentExample) {
null,
ExampleStrings.SIMPLE -> SimpleNavigationDrawerExample()
ExampleStrings.NESTED -> NestedNavigationDrawerExample()
}
)
}

@Preview
Expand All @@ -94,36 +60,6 @@ private fun NavigationDrawerExamplesPreview() {
NavigationDrawerExamples()
}

// [START android_compose_components_simplenavigationdrawerexample]
@Composable
fun SimpleNavigationDrawerExample() {
ModalNavigationDrawer(
drawerContent = {
ModalDrawerSheet {
NavigationDrawerItem(
label = { Text(text = "Item 1") },
selected = false,
onClick = { /* Do something... */ }
)
NavigationDrawerItem(
label = { Text(text = "Item 2") },
selected = false,
onClick = { /* Do something... */ }
)
}
}
) {
// Screen content
}
}
// [END android_compose_components_simplenavigationdrawerexample]

@Preview
@Composable
private fun SimpleNavigationDrawerExamplePreview() {
SimpleNavigationDrawerExample()
}

// [START android_compose_components_navigationdrawergroupitem]
@Composable
fun NavigationDrawerGroupItem(
Expand Down Expand Up @@ -153,7 +89,9 @@ fun NavigationDrawerGroupItem(

// [START android_compose_components_nestednavigationdrawerexample]
@Composable
fun NestedNavigationDrawerExample() {
fun NestedNavigationDrawerExample(
screenContent: @Composable () -> Unit,
) {
ModalNavigationDrawer(
drawerContent = {
ModalDrawerSheet {
Expand Down Expand Up @@ -197,13 +135,13 @@ fun NestedNavigationDrawerExample() {
}
}
) {
// Screen content
screenContent()
}
}
// [END android_compose_components_nestednavigationdrawerexample]

@Preview
@Composable
private fun NestedNavigationDrawerExamplePreview() {
NestedNavigationDrawerExample()
NestedNavigationDrawerExample{ Text(HELP_TEXT) }
}
Loading