Skip to content

Commit

Permalink
prepare discover screen
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 19, 2024
1 parent b104331 commit 86126b3
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -63,7 +64,7 @@ class RootComponent(
componentContext = componentContext,
di = di,
onDiscover = {
// navigation.replaceCurrent(RootConfig.Wallpaper)
navigation.replaceCurrent(RootConfig.Discover)
},
onHome = {
navigation.replaceCurrent(RootConfig.Home)
Expand All @@ -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)
}
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ sealed class RootConfig {

@Serializable
data object Nekos : RootConfig()

@Serializable
data object Discover : RootConfig()
}
Original file line number Diff line number Diff line change
@@ -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<Boolean>

fun viewHome()
fun viewList()
}
Original file line number Diff line number Diff line change
@@ -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")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<UserHelper>()
override val loggedIn: Flow<Boolean> = 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()
}
}

0 comments on commit 86126b3

Please sign in to comment.