Skip to content

Commit

Permalink
disable page scroll when details shown
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Nov 20, 2023
1 parent 3f0f5e0 commit 509e692
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ actual fun VideoScreen(component: VideoComponent) {

var streamIndex by remember(streamList) { mutableIntStateOf(0) }
var sourceIndex by remember(streamIndex) { mutableIntStateOf(0) }
val headers = remember(streamIndex, sourceIndex) {
val headers = remember(streamIndex) {
streamList[streamIndex].headers
}
val mediaItem = remember(streamList, streamIndex, sourceIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.arkivanov.decompose.router.pages.ChildPages
import com.arkivanov.decompose.value.Value
import dev.datlag.burningseries.ui.navigation.Component
import dev.icerock.moko.resources.StringResource
import kotlinx.coroutines.flow.StateFlow

interface InitialComponent : Component {

Expand All @@ -14,6 +15,8 @@ interface InitialComponent : Component {
@OptIn(ExperimentalDecomposeApi::class)
val pages: Value<ChildPages<*, Component>>

val scrollEnabled: StateFlow<Boolean>

fun selectPage(index: Int)

data class PagerItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.datlag.burningseries.ui.screen.initial

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Search
Expand All @@ -16,6 +17,7 @@ import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.extensions.compose.jetbrains.pages.Pages
import com.moriatsushi.insetsx.ExperimentalSoftwareKeyboardApi
import com.moriatsushi.insetsx.safeDrawingPadding
import dev.datlag.burningseries.common.lifecycle.collectAsStateWithLifecycle
import dev.datlag.burningseries.ui.custom.ExpandedPages
import dev.icerock.moko.resources.compose.stringResource

Expand Down Expand Up @@ -62,10 +64,21 @@ private fun CompactScreen(
}
) {
Box(modifier = Modifier.padding(it)) {
val scrollEnabled by component.scrollEnabled.collectAsStateWithLifecycle()

Pages(
pages = component.pages,
onPageSelected = { index ->
component.selectPage(index)
},
pager = { modifier, state, key, pageContent ->
HorizontalPager(
modifier = modifier,
state = state,
key = key,
pageContent = pageContent,
userScrollEnabled = scrollEnabled
)
}
) { index, page ->
selectedPage = index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.router.pages.*
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import dev.datlag.burningseries.common.ioDispatcher
import dev.datlag.burningseries.common.ioScope
Expand All @@ -22,8 +23,7 @@ import dev.datlag.burningseries.ui.navigation.Component
import dev.datlag.burningseries.ui.screen.initial.favorite.FavoriteScreenComponent
import dev.datlag.burningseries.ui.screen.initial.home.HomeScreenComponent
import dev.datlag.burningseries.ui.screen.initial.search.SearchScreenComponent
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.*
import org.kodein.di.DI
import org.kodein.di.instance

Expand Down Expand Up @@ -68,6 +68,14 @@ class InitialScreenComponent(
createChild(config, context)
}

private val homeScrollEnabled = MutableStateFlow(true)
private val favoriteScrollEnabled = MutableStateFlow(true)
private val searchScrollEnabled = MutableStateFlow(true)

override val scrollEnabled: StateFlow<Boolean> = combine(homeScrollEnabled, favoriteScrollEnabled, searchScrollEnabled) { t1, t2, t3 ->
t1 && t2 && t3
}.stateIn(ioScope(), SharingStarted.Lazily, homeScrollEnabled.value && favoriteScrollEnabled.value && searchScrollEnabled.value)

@Composable
override fun render() {
InitialScreen(this)
Expand All @@ -81,17 +89,20 @@ class InitialScreenComponent(
is View.Home -> HomeScreenComponent(
componentContext = componentContext,
di = di,
watchVideo = { watchVideo(it) }
watchVideo = { watchVideo(it) },
scrollEnabled = { homeScrollEnabled.value = it }
)
is View.Favorite -> FavoriteScreenComponent(
componentContext = componentContext,
di = di,
watchVideo = { watchVideo(it) }
watchVideo = { watchVideo(it) },
scrollEnabled = { favoriteScrollEnabled.value = it }
)
is View.Search -> SearchScreenComponent(
componentContext = componentContext,
di = di,
watchVideo = { watchVideo(it) }
watchVideo = { watchVideo(it) },
scrollEnabled = { searchScrollEnabled.value = it }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import org.kodein.di.instance
class FavoriteScreenComponent(
componentContext: ComponentContext,
override val di: DI,
private val watchVideo: (Collection<Stream>) -> Unit
private val watchVideo: (Collection<Stream>) -> Unit,
private val scrollEnabled: (Boolean) -> Unit
) : FavoriteComponent, ComponentContext by componentContext {

private val database: BurningSeries by di.instance()
Expand Down Expand Up @@ -64,7 +65,9 @@ class FavoriteScreenComponent(
initialTitle = config.title,
initialHref = config.href,
initialCoverHref = config.coverHref,
onGoBack = navigation::dismiss,
onGoBack = {
navigation.dismiss(scrollEnabled)
},
watchVideo = { watchVideo(it) }
)
}
Expand All @@ -76,7 +79,9 @@ class FavoriteScreenComponent(
}

override fun itemClicked(config: FavoriteConfig) {
navigation.activate(config)
navigation.activate(config) {
scrollEnabled(false)
}
}

override fun searchQuery(text: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import org.kodein.di.instance
class HomeScreenComponent(
componentContext: ComponentContext,
override val di: DI,
private val watchVideo: (Collection<Stream>) -> Unit
private val watchVideo: (Collection<Stream>) -> Unit,
private val scrollEnabled: (Boolean) -> Unit
) : HomeComponent, ComponentContext by componentContext {

private val homeStateMachine: HomeStateMachine by di.instance()
Expand All @@ -39,7 +40,9 @@ class HomeScreenComponent(
initialTitle = config.title,
initialHref = config.href,
initialCoverHref = config.coverHref,
onGoBack = navigation::dismiss,
onGoBack = {
navigation.dismiss(scrollEnabled)
},
watchVideo = { watchVideo(it) }
)
}
Expand All @@ -55,6 +58,8 @@ class HomeScreenComponent(
}

override fun itemClicked(config: HomeConfig) {
navigation.activate(config)
navigation.activate(config) {
scrollEnabled(false)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import org.kodein.di.instance
class SearchScreenComponent(
componentContext: ComponentContext,
override val di: DI,
private val watchVideo: (Collection<Stream>) -> Unit
private val watchVideo: (Collection<Stream>) -> Unit,
private val scrollEnabled: (Boolean) -> Unit
) : SearchComponent, ComponentContext by componentContext {

private val searchStateMachine: SearchStateMachine by di.instance()
Expand Down Expand Up @@ -73,7 +74,9 @@ class SearchScreenComponent(
initialTitle = config.title,
initialHref = config.href,
initialCoverHref = null,
onGoBack = navigation::dismiss,
onGoBack = {
navigation.dismiss(scrollEnabled)
},
watchVideo = { watchVideo(it) }
)
}
Expand All @@ -97,6 +100,8 @@ class SearchScreenComponent(
}

override fun itemClicked(config: SearchConfig) {
navigation.activate(config)
navigation.activate(config) {
scrollEnabled(false)
}
}
}
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ app = "5.0.0"
aboutlibraries = "10.9.2"
accompanist = "0.32.0"
activity = "1.8.1"
android = "8.1.3"
android = "8.1.4"
android-core = "1.12.0"
appcompat = "1.6.1"
appdirs = "1.2.2"
Expand All @@ -22,15 +22,15 @@ grpc = "1.59.0"
instesx = "0.1.0-alpha10"
jsunpacker = "1.0.2"
kamel = "0.8.3"
kodein = "7.20.2"
kodein = "7.21.0"
kotlin = "1.9.20"
ksp = "1.9.20-1.0.14"
ktor = "2.3.6"
ktorfit = "1.10.1"
ktsoup = "0.3.0"
lang = "3.13.0"
material = "1.10.0"
media3 = "1.1.1"
media3 = "1.2.0"
moko-resources = "0.23.0"
multidex = "2.0.1"
napier = "2.6.1"
Expand All @@ -44,7 +44,7 @@ serialization-json = "1.6.0"
splashscreen = "1.0.1"
sqldelight = "2.0.0"
turbine = "1.0.0"
versions = "0.49.0"
versions = "0.50.0"
vlcj = "4.8.2"
webview = "1.7.2"
windowsize-multiplatform = "0.3.1"
Expand Down

0 comments on commit 509e692

Please sign in to comment.