-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding landing screen with navigation destinations. * Apply Spotless * Updating the navigation to use an enum class that enumerated all possible destinations. They go on to populate a LazyColumn in NavigationButtons. * Apply Spotless * Updating the navigation to use an enum class that enumerated all possible destinations. They go on to populate a LazyColumn in NavigationButtons. * Removing when block from NavigationItems. * Apply Spotless --------- Co-authored-by: jakeroseman <jakeroseman@users.noreply.github.com>
- Loading branch information
1 parent
0210c41
commit f2035d0
Showing
3 changed files
with
131 additions
and
8 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
compose/snippets/src/main/java/com/example/compose/snippets/LandingScreen/LandingScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2023 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.LandingScreen | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.example.compose.snippets.navigation.Destination | ||
|
||
@Composable | ||
fun LandingScreen( | ||
navigate: (Destination) -> Unit | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.padding(16.dp) | ||
.fillMaxSize(), | ||
verticalArrangement = Arrangement.spacedBy(24.dp), | ||
) { | ||
Text( | ||
modifier = Modifier.fillMaxWidth(), | ||
style = TextStyle( | ||
fontSize = 24.sp, | ||
fontWeight = FontWeight.Bold, | ||
textAlign = TextAlign.Center, | ||
), | ||
text = "Android snippets", | ||
) | ||
Text( | ||
text = "Use the following buttons to view a selection of the snippets used in the Android documentation." | ||
) | ||
NavigationItems { navigate(it) } | ||
} | ||
} | ||
|
||
@Composable | ||
fun NavigationItems(navigate: (Destination) -> Unit) { | ||
LazyColumn( | ||
modifier = Modifier | ||
.padding(16.dp) | ||
.fillMaxSize(), | ||
verticalArrangement = Arrangement.spacedBy(8.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
items(Destination.values().toList()) { destination -> | ||
NavigationItem(destination) { | ||
navigate( | ||
destination | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun NavigationItem(destination: Destination, onClick: () -> Unit) { | ||
Button( | ||
onClick = { onClick() } | ||
) { | ||
Text(destination.title) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
compose/snippets/src/main/java/com/example/compose/snippets/navigation/Destination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2023 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.navigation | ||
|
||
enum class Destination(val route: String, val title: String) { | ||
BrushExamples("brushExamples", "Brush Examples"), | ||
ImageExamples("imageExamples", "Image Examples"), | ||
} |