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
Apply Spotless
  • Loading branch information
jakeroseman authored and github-actions[bot] committed Oct 14, 2024
commit 9fcc09b05fdb0ab855ee8e6718c7a85cfe9809d2
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.compose.snippets.components

import androidx.compose.animation.AnimatedVisibility
Expand Down Expand Up @@ -27,17 +43,17 @@ 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){
enum class ExampleStrings(val description: String) {
SIMPLE("simple navigation drawer example"),
NESTED("navigation drawer with nested items")
}

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

if (currentExample == null){
Column(){
if (currentExample == null) {
Column() {
Text(
text = "Select which example you'd like to see.",
textAlign = TextAlign.Center,
Expand All @@ -46,18 +62,18 @@ fun NavigationDrawerExamples(){
.padding(16.dp)
)

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

return
}

Column(modifier = Modifier.fillMaxSize()){
Column(modifier = Modifier.fillMaxSize()) {
Text(
text = "Swipe from left to open the ${currentExample!!.description}.",
textAlign = TextAlign.Center,
Expand All @@ -67,7 +83,7 @@ fun NavigationDrawerExamples(){
)
}

when (currentExample){
when (currentExample) {
null,
ExampleStrings.SIMPLE -> SimpleNavigationDrawerExample()
ExampleStrings.NESTED -> NestedNavigationDrawerExample()
Expand All @@ -76,7 +92,7 @@ fun NavigationDrawerExamples(){

@Preview
@Composable
private fun NavigationDrawerExamplesPreview(){
private fun NavigationDrawerExamplesPreview() {
NavigationDrawerExamples()
}

Expand Down Expand Up @@ -133,7 +149,7 @@ fun SimpleNavigationDrawerExample() {

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

Expand Down Expand Up @@ -190,6 +206,6 @@ fun NestedNavigationDrawerExample() {

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