Presentation Package

The Presentation package manages the app's user interface (UI) and contains three sub-packages:
Components
Contains reusable UI elements like the bottom navigation bar, toolbar, loading indicators, and dialogs to maintain consistent design across the app.
Theme
Manages the app's appearance, including colors, typography (fonts), and themes (dark/light theme), allowing easy customization of the app's visual style.
Screens
Contains all the screens in the app. Each screen follows a structured setup:
-
Screen: The main composable function for the UI.
-
UiState: Represents the current ui state of the screen, and also contains UiEvent to handle user actions and events on the screen.
-
ScreenRoute: Manages the navigation logic to and from the screen.
ScreenRouteis an interface that defines a@Composable Content()function. Route classes are annotated with@Serializablefor type-safe navigation using Compose Navigation. SeeOnBoardingScreenRouteas an example. -
UiStateHolder (ViewModel): Manages the screen's state.
UiStateHolderis an abstract class extendingViewModelfromandroidx.lifecycle. It interacts with the UiState and handles events (UiEvent) triggered by user actions.For new screens, extend the
UiStateHolderclass. When you need to call a suspend function, do so within theuiStateHolderScope.launch, which delegates toviewModelScope.class NewUiStateHolder() : UiStateHolder() {
fun testFunction() = uiStateHolderScope.launch {
//Call suspend function
}
}For creating instances of a UiStateHolder, the
uiStateHolderfunction is used for most screens. SeeOnBoardingScreenRouteclass.val uiStateHolder = uiStateHolder<OnboardingUiStateHolder>()For screens in the bottom navigation, you can use the
navigatorUiStateHolderon theNavHostControllerto ensure the ViewModel is scoped to the navigation graph and does not get recreated when switching between navigation items. SeeProfileScreenRouteclass.val navigator = LocalNavigator.current
val uiStateHolder = navigator.navigatorUiStateHolder<ProfileUiStateHolder>()Additionally, ensure that the DI setup is done in the
AppInitializerwithin the presentationModule, for example, by includingviewModelOf(::NewUiStateHolder)to handle dependencies correctly for the UiStateHolder.