compose: onboarding: Switch to a simple enum class
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -30,15 +30,15 @@ import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
|||||||
import com.aurora.store.R
|
import com.aurora.store.R
|
||||||
import com.aurora.store.compose.composable.PageIndicator
|
import com.aurora.store.compose.composable.PageIndicator
|
||||||
import com.aurora.store.compose.preview.PreviewTemplate
|
import com.aurora.store.compose.preview.PreviewTemplate
|
||||||
import com.aurora.store.compose.ui.onboarding.navigation.ExtraScreen
|
import com.aurora.store.compose.ui.onboarding.navigation.OnboardingPage
|
||||||
import com.aurora.store.viewmodel.onboarding.OnboardingViewModel
|
import com.aurora.store.viewmodel.onboarding.OnboardingViewModel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun OnboardingScreen(viewModel: OnboardingViewModel = hiltViewModel()) {
|
fun OnboardingScreen(viewModel: OnboardingViewModel = hiltViewModel()) {
|
||||||
val pages = listOfNotNull(
|
val pages = listOfNotNull(
|
||||||
ExtraScreen.Welcome,
|
OnboardingPage.WELCOME,
|
||||||
ExtraScreen.Permissions
|
OnboardingPage.PERMISSIONS
|
||||||
)
|
)
|
||||||
|
|
||||||
ScreenContent(
|
ScreenContent(
|
||||||
@@ -49,7 +49,7 @@ fun OnboardingScreen(viewModel: OnboardingViewModel = hiltViewModel()) {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ScreenContent(
|
private fun ScreenContent(
|
||||||
pages: List<ExtraScreen> = emptyList(),
|
pages: List<OnboardingPage> = emptyList(),
|
||||||
onFinishOnboarding: () -> Unit = {}
|
onFinishOnboarding: () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val pagerState = rememberPagerState { pages.size }
|
val pagerState = rememberPagerState { pages.size }
|
||||||
@@ -80,8 +80,8 @@ private fun ScreenContent(
|
|||||||
verticalAlignment = Alignment.Top
|
verticalAlignment = Alignment.Top
|
||||||
) { page ->
|
) { page ->
|
||||||
when (pages[page]) {
|
when (pages[page]) {
|
||||||
ExtraScreen.Welcome -> WelcomePage()
|
OnboardingPage.WELCOME -> WelcomePage()
|
||||||
ExtraScreen.Permissions -> PermissionsPage()
|
OnboardingPage.PERMISSIONS -> PermissionsPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ private fun ScreenContent(
|
|||||||
private fun OnboardingScreenPreview() {
|
private fun OnboardingScreenPreview() {
|
||||||
PreviewTemplate {
|
PreviewTemplate {
|
||||||
ScreenContent(
|
ScreenContent(
|
||||||
pages = listOf(ExtraScreen.Welcome, ExtraScreen.Permissions)
|
pages = listOf(OnboardingPage.WELCOME, OnboardingPage.PERMISSIONS)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2025 The Calyx Institute
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.aurora.store.compose.ui.onboarding.navigation
|
|
||||||
|
|
||||||
import android.os.Parcelable
|
|
||||||
import androidx.navigation3.runtime.NavKey
|
|
||||||
import kotlinx.parcelize.Parcelize
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extra destinations for onboarding
|
|
||||||
*
|
|
||||||
* All of these destinations are child destinations of onboarding screen are shown inside it.
|
|
||||||
*/
|
|
||||||
@Parcelize
|
|
||||||
@Serializable
|
|
||||||
sealed class ExtraScreen : NavKey, Parcelable {
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data object Welcome : ExtraScreen()
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data object Permissions : ExtraScreen()
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2025 Aurora OSS
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.aurora.store.compose.ui.onboarding.navigation
|
||||||
|
|
||||||
|
enum class OnboardingPage {
|
||||||
|
WELCOME,
|
||||||
|
PERMISSIONS,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user