-
-
Notifications
You must be signed in to change notification settings - Fork 538
UI Layer
SuperDragonXD edited this page Apr 2, 2026
·
2 revisions
The user interface (UI) for Lawnicons is built entirely with Jetpack Compose. This modern toolkit allows us to create a declarative and reactive UI, making it more intuitive to build and maintain.
-
Location: You'll find all UI-related code in the
app/src/main/kotlin/app/lawnchair/lawnicons/ui/directory. -
Organization:
-
theme/: ContainsLawniconsTheme.kt(which sets up Material 3 Expressive, dynamic coloring, and contrast modes) andLawniconsColor.kt(for color palette definitions). -
components/: This package is for UI building blocks.-
core/: Generic, reusable Composables likeLawniconsScaffold.ktandSimpleListRow.kt. - Subpackages like
home/oriconpreview/contain Composables specific to those features.
-
-
destination/: Each feature has its own subpackage containing both the screen Composable and its ViewModel (for example,home/Home.kt+home/HomeViewModel.kt,contributors/Contributors.kt+contributors/ContributorsViewModel.kt).
-
-
Core Principles:
- Unidirectional Data Flow (UDF): State (data) flows down from ViewModels to Composables. User actions (events) flow up from Composables to ViewModels.
-
Reactivity: The UI updates automatically when the state it observes changes. We typically use
collectAsStateWithLifecycleto listen toStateFlowfrom ViewModels.
-
Navigation:
- Lawnicons uses Navigation3 (
androidx.navigation3), the typed navigation framework for Compose. - Routes are typed Kotlin objects implementing
NavKey(for example,Home,About,NewIcons,IconRequest,Contributors,Acknowledgements,DebugMenu). -
Lawnicons.ktsets up aNavDisplaywith anentryProviderblock that maps each route to its screen Composable via destination functions (for example,homeDestination(),aboutDestination()). -
NavigationState.ktmanages per-route back stacks usingrememberNavBackStack,rememberDecoratedNavEntries, and supports top-level route switching with process-death resilience viarememberSerializable. -
Navigator.ktprovidesnavigate(route)andgoBack()functions that update theNavigationState, handling both top-level route switches and nested back-stack pushes.
- Lawnicons uses Navigation3 (
-
Responsiveness:
- The app adapts to different screen sizes.
MainActivity.ktcalculatesisExpandedScreenusingWindowWidthSizeClassandWindowHeightSizeClass. - Composables like
TopAppBar.kt, the home screen's bottom toolbar/FAB, andIconPreviewGrid.ktadjust their layout based on this value.
- The app adapts to different screen sizes.
-
Previews in Android Studio:
- We use the
@PreviewLawniconscustom annotation andSampleData(fromui/util/PreviewUtils.kt) to create effective UI previews. -
LocalInspectionMode.currenthelps simplify previews by, for example, avoiding network requests for images.
- We use the
-
MainActivity.kt: The app's single Activity. It initializes Compose, retrievesMetroViewModelFactoryfromLawniconsGraph, determines screen size characteristics, and handles theICON_PICKER_INTENT_ACTION. -
Lawnicons.kt(inui/): The root Composable containing theNavDisplaywhich manages navigation between different screens using Navigation3 and Material motion transitions. -
NavigationState.kt: Manages saveable back stacks for each top-level route, converting them into decoratedNavEntrylists forNavDisplay. -
Navigator.kt: Encapsulates navigation logic —navigate()for forward navigation andgoBack()for back-stack popping. -
LawniconsScaffold.kt: A common scaffold structure used by most screens, providing a consistent top app bar. -
IconPreviewGrid.kt: Displays the main grid of icons efficiently usingLazyVerticalGrid.
The UI layer is designed to be a presentation layer. It focuses on displaying data provided by ViewModels and capturing user input, delegating business logic to the ViewModels.
Found an issue or have a suggestion for this wiki? Please let us know!
- Home
- Getting started
- Architecture
- Key Feature Explanations
- Troubleshooting for Developers
- Project Glossary