From 86126b3d8d71476d87551eee22c4a968a11cbb0a Mon Sep 17 00:00:00 2001 From: DatLag Date: Sun, 19 May 2024 14:41:59 +0200 Subject: [PATCH] prepare discover screen --- .../aniflow/ui/navigation/RootComponent.kt | 15 ++- .../aniflow/ui/navigation/RootConfig.kt | 3 + .../screen/discover/DiscoverComponent.kt | 11 +++ .../screen/discover/DiscoverScreen.kt | 98 +++++++++++++++++++ .../discover/DiscoverScreenComponent.kt | 45 +++++++++ 5 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverComponent.kt create mode 100644 composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverScreen.kt create mode 100644 composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverScreenComponent.kt diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootComponent.kt index d8f67b2..acbb648 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootComponent.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootComponent.kt @@ -10,6 +10,7 @@ import com.arkivanov.decompose.extensions.compose.stack.animation.stackAnimation import com.arkivanov.decompose.router.stack.* import dev.datlag.aniflow.common.onRender import dev.datlag.aniflow.other.UserHelper +import dev.datlag.aniflow.ui.navigation.screen.discover.DiscoverScreenComponent import dev.datlag.aniflow.ui.navigation.screen.favorites.FavoritesScreenComponent import dev.datlag.aniflow.ui.navigation.screen.home.HomeScreenComponent import dev.datlag.aniflow.ui.navigation.screen.medium.MediumScreenComponent @@ -44,7 +45,7 @@ class RootComponent( navigation.bringToFront(RootConfig.Details(it)) }, onDiscover = { - // navigation.replaceCurrent(RootConfig.Wallpaper) + navigation.replaceCurrent(RootConfig.Discover) }, onFavorites = { navigation.replaceCurrent(RootConfig.Favorites) @@ -63,7 +64,7 @@ class RootComponent( componentContext = componentContext, di = di, onDiscover = { - // navigation.replaceCurrent(RootConfig.Wallpaper) + navigation.replaceCurrent(RootConfig.Discover) }, onHome = { navigation.replaceCurrent(RootConfig.Home) @@ -77,6 +78,16 @@ class RootComponent( di = di, onBack = navigation::pop ) + is RootConfig.Discover -> DiscoverScreenComponent( + componentContext = componentContext, + di = di, + onHome = { + navigation.replaceCurrent(RootConfig.Home) + }, + onList = { + navigation.replaceCurrent(RootConfig.Favorites) + } + ) } } diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootConfig.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootConfig.kt index dd55b08..ae7c1ff 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootConfig.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/RootConfig.kt @@ -19,4 +19,7 @@ sealed class RootConfig { @Serializable data object Nekos : RootConfig() + + @Serializable + data object Discover : RootConfig() } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverComponent.kt new file mode 100644 index 0000000..b62e9db --- /dev/null +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverComponent.kt @@ -0,0 +1,11 @@ +package dev.datlag.aniflow.ui.navigation.screen.discover + +import dev.datlag.aniflow.ui.navigation.Component +import kotlinx.coroutines.flow.Flow + +interface DiscoverComponent : Component { + val loggedIn: Flow + + fun viewHome() + fun viewList() +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverScreen.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverScreen.kt new file mode 100644 index 0000000..f107964 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverScreen.kt @@ -0,0 +1,98 @@ +package dev.datlag.aniflow.ui.navigation.screen.discover + +import androidx.compose.animation.core.animateDpAsState +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.PaddingValues +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.rememberLazyListState +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Search +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.Scaffold +import androidx.compose.material3.SearchBar +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import dev.chrisbanes.haze.haze +import dev.datlag.aniflow.LocalHaze +import dev.datlag.aniflow.SharedRes +import dev.datlag.aniflow.common.merge +import dev.datlag.aniflow.common.scrollUpVisible +import dev.datlag.aniflow.ui.navigation.screen.component.HidingNavigationBar +import dev.datlag.aniflow.ui.navigation.screen.component.NavigationBarState +import dev.icerock.moko.resources.compose.stringResource + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun DiscoverScreen(component: DiscoverComponent) { + val listState = rememberLazyListState() + + Scaffold( + topBar = { + var query by remember { mutableStateOf("") } + var active by remember { mutableStateOf(false) } + + val activePadding by animateDpAsState( + targetValue = if (active) 0.dp else 16.dp + ) + + SearchBar( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = activePadding) + .padding(bottom = activePadding), + query = query, + onQueryChange = { + query = it + }, + active = active, + onActiveChange = { + active = it + }, + onSearch = { + query = it + }, + leadingIcon = { + Icon( + imageVector = Icons.Rounded.Search, + contentDescription = null + ) + }, + placeholder = { + Text(text = stringResource(SharedRes.strings.search)) + }, + content = { } + ) + }, + bottomBar = { + HidingNavigationBar( + visible = listState.scrollUpVisible(), + selected = NavigationBarState.Discover, + loggedIn = component.loggedIn, + onDiscover = { }, + onHome = component::viewHome, + onFavorites = component::viewList + ) + } + ) { padding -> + LazyColumn( + state = listState, + modifier = Modifier.fillMaxSize().haze(state = LocalHaze.current), + contentPadding = padding.merge(PaddingValues(16.dp)), + verticalArrangement = Arrangement.spacedBy(16.dp), + ) { + item { + Text("Discover Screen") + } + } + } +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverScreenComponent.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverScreenComponent.kt new file mode 100644 index 0000000..59c2d85 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/discover/DiscoverScreenComponent.kt @@ -0,0 +1,45 @@ +package dev.datlag.aniflow.ui.navigation.screen.discover + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.remember +import com.arkivanov.decompose.ComponentContext +import dev.chrisbanes.haze.HazeState +import dev.datlag.aniflow.LocalHaze +import dev.datlag.aniflow.common.onRender +import dev.datlag.aniflow.other.UserHelper +import kotlinx.coroutines.flow.Flow +import org.kodein.di.DI +import org.kodein.di.instance + +class DiscoverScreenComponent( + componentContext: ComponentContext, + override val di: DI, + private val onHome: () -> Unit, + private val onList: () -> Unit, +) : DiscoverComponent, ComponentContext by componentContext { + + private val userHelper by instance() + override val loggedIn: Flow = userHelper.isLoggedIn + + @Composable + override fun render() { + val haze = remember { HazeState() } + + CompositionLocalProvider( + LocalHaze provides haze + ) { + onRender { + DiscoverScreen(this) + } + } + } + + override fun viewHome() { + onHome() + } + + override fun viewList() { + onList() + } +} \ No newline at end of file