Simplifying Compose stack

This commit is contained in:
Vitor Pamplona
2023-11-04 16:48:29 -04:00
parent 6d17c8d79f
commit 3de52a6c0d
2 changed files with 25 additions and 48 deletions
@@ -183,10 +183,6 @@ private fun FeedLoaded(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
val baseModifier = remember {
Modifier
}
LazyColumn( LazyColumn(
contentPadding = FeedPadding, contentPadding = FeedPadding,
state = listState state = listState
@@ -201,7 +197,7 @@ private fun FeedLoaded(
NoteCompose( NoteCompose(
item, item,
routeForLastRead = routeForLastRead, routeForLastRead = routeForLastRead,
modifier = baseModifier, modifier = Modifier,
isBoostedNote = false, isBoostedNote = false,
showHidden = state.showHidden.value, showHidden = state.showHidden.value,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
@@ -4,7 +4,6 @@ import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.FlowRow
@@ -104,18 +103,14 @@ fun VideoScreen(
} }
Column(Modifier.fillMaxHeight()) { Column(Modifier.fillMaxHeight()) {
Column( RenderPage(
modifier = Modifier.padding(vertical = 0.dp)
) {
SaveableFeedState(
videoFeedView = videoFeedView, videoFeedView = videoFeedView,
pagerStateKey = ScrollStateKeys.VIDEO_SCREEN,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav
scrollStateKey = ScrollStateKeys.VIDEO_SCREEN
) )
} }
} }
}
@Composable @Composable
fun WatchAccountForVideoScreen(videoFeedView: NostrVideoFeedViewModel, accountViewModel: AccountViewModel) { fun WatchAccountForVideoScreen(videoFeedView: NostrVideoFeedViewModel, accountViewModel: AccountViewModel) {
@@ -127,16 +122,6 @@ fun WatchAccountForVideoScreen(videoFeedView: NostrVideoFeedViewModel, accountVi
} }
} }
@Composable
private fun SaveableFeedState(
videoFeedView: NostrVideoFeedViewModel,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
scrollStateKey: String? = null
) {
RenderPage(videoFeedView, accountViewModel, scrollStateKey, nav)
}
@OptIn(ExperimentalFoundationApi::class) @OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
public fun WatchScrollToTop( public fun WatchScrollToTop(
@@ -153,21 +138,19 @@ public fun WatchScrollToTop(
} }
} }
@OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
fun RenderPage( fun RenderPage(
videoFeedView: NostrVideoFeedViewModel, videoFeedView: NostrVideoFeedViewModel,
accountViewModel: AccountViewModel,
pagerStateKey: String?, pagerStateKey: String?,
accountViewModel: AccountViewModel,
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
val feedState by videoFeedView.feedContent.collectAsStateWithLifecycle() val feedState by videoFeedView.feedContent.collectAsStateWithLifecycle()
Box() {
Column {
Crossfade( Crossfade(
targetState = feedState, targetState = feedState,
animationSpec = tween(durationMillis = 100) animationSpec = tween(durationMillis = 100),
label = "RenderPage"
) { state -> ) { state ->
when (state) { when (state) {
is FeedState.Empty -> { is FeedState.Empty -> {
@@ -188,8 +171,6 @@ fun RenderPage(
} }
} }
} }
}
}
@Composable @Composable
@OptIn(ExperimentalFoundationApi::class) @OptIn(ExperimentalFoundationApi::class)