Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make flash when navigating to Discover look a bit better #1485

Merged
merged 2 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ internal fun Discover(
)
}

@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterialApi::class, ExperimentalFoundationApi::class)
@Composable
internal fun Discover(
state: DiscoverUiState,
Expand Down Expand Up @@ -202,7 +202,7 @@ internal fun Discover(
}

state.nextEpisodeWithShowToWatch?.let { nextEpisodeToWatch ->
item {
item(key = "next_episode_to_watch") {
NextEpisodeToWatch(
show = nextEpisodeToWatch.show,
season = nextEpisodeToWatch.season,
Expand All @@ -216,6 +216,7 @@ internal fun Discover(
},
modifier = Modifier
.padding(horizontal = Layout.bodyMargin, vertical = Layout.gutter)
.animateItemPlacement()
.fillMaxWidth(),
)
}
Expand All @@ -225,7 +226,7 @@ internal fun Discover(
}
}

item {
item(key = "carousel_trending") {
CarouselWithHeader(
items = state.trendingItems,
title = LocalStrings.current.discoverTrendingTitle,
Expand All @@ -234,10 +235,11 @@ internal fun Discover(
openShowDetails(it.id, null, null)
},
onMoreClick = openTrendingShows,
modifier = Modifier.animateItemPlacement(),
)
}

item {
item(key = "carousel_recommended") {
CarouselWithHeader(
items = state.recommendedItems,
title = LocalStrings.current.discoverRecommendedTitle,
Expand All @@ -246,16 +248,18 @@ internal fun Discover(
openShowDetails(it.id, null, null)
},
onMoreClick = openRecommendedShows,
modifier = Modifier.animateItemPlacement(),
)
}

item {
item(key = "carousel_refreshing") {
CarouselWithHeader(
items = state.popularItems,
title = LocalStrings.current.discoverPopularTitle,
refreshing = state.popularRefreshing,
onItemClick = { openShowDetails(it.id, null, null) },
onMoreClick = openPopularShows,
modifier = Modifier.animateItemPlacement(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

package app.tivi.home

import android.annotation.SuppressLint
import android.os.Build
import android.window.BackEvent
import android.window.OnBackAnimationCallback
import android.window.OnBackInvokedDispatcher
import androidx.annotation.RequiresApi
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.tween
import androidx.compose.animation.core.updateTransition
import androidx.compose.animation.fadeIn
Expand Down Expand Up @@ -41,13 +39,13 @@ import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.unit.dp
import app.tivi.animations.lerp
import app.tivi.util.Logger
import com.slack.circuit.runtime.Navigator
import kotlin.math.absoluteValue

@SuppressLint("NewApi")
@OptIn(ExperimentalAnimationApi::class)
internal actual class GestureNavDecoration actual constructor(
private val navigator: Navigator,
logger: Logger,
) : NavDecorationWithPrevious {

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

package app.tivi.home

import app.tivi.util.Logger
import com.slack.circuit.runtime.Navigator

internal expect class GestureNavDecoration(
navigator: Navigator,
logger: Logger,
) : NavDecorationWithPrevious
5 changes: 3 additions & 2 deletions ui/root/src/commonMain/kotlin/app/tivi/home/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import app.tivi.screens.DiscoverScreen
import app.tivi.screens.LibraryScreen
import app.tivi.screens.SearchScreen
import app.tivi.screens.UpNextScreen
import app.tivi.util.Logger
import com.moriatsushi.insetsx.navigationBars
import com.moriatsushi.insetsx.safeContentPadding
import com.moriatsushi.insetsx.statusBars
Expand All @@ -61,11 +62,11 @@ import com.slack.circuit.overlay.ContentWithOverlays
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.Screen

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun Home(
backstack: SaveableBackStack,
navigator: Navigator,
logger: Logger,
modifier: Modifier = Modifier,
) {
val windowSizeClass = LocalWindowSizeClass.current
Expand Down Expand Up @@ -132,7 +133,7 @@ internal fun Home(
NavigableCircuitContentWithPrevious(
navigator = navigator,
backstack = backstack,
decoration = GestureNavDecoration(navigator),
decoration = GestureNavDecoration(navigator, logger),
modifier = Modifier
.weight(1f)
.fillMaxHeight(),
Expand Down
19 changes: 16 additions & 3 deletions ui/root/src/commonMain/kotlin/app/tivi/home/TiviContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import app.tivi.overlays.LocalNavigator
import app.tivi.screens.TiviScreen
import app.tivi.screens.UrlScreen
import app.tivi.settings.TiviPreferences
import app.tivi.util.Logger
import app.tivi.util.TiviDateFormatter
import app.tivi.util.TiviTextCreator
import com.seiko.imageloader.ImageLoader
Expand Down Expand Up @@ -58,13 +59,14 @@ fun TiviContent(
tiviTextCreator: TiviTextCreator,
preferences: TiviPreferences,
imageLoader: ImageLoader,
logger: Logger,
@Assisted modifier: Modifier = Modifier,
) {
val coroutineScope = rememberCoroutineScope()
remember { rootViewModel(coroutineScope) }

val tiviNavigator: Navigator = remember(navigator) {
TiviNavigator(navigator, onOpenUrl)
TiviNavigator(navigator, backstack, onOpenUrl, logger)
}

// Launch an effect to track changes to the current back stack entry, and push them
Expand Down Expand Up @@ -93,6 +95,7 @@ fun TiviContent(
Home(
backstack = backstack,
navigator = tiviNavigator,
logger = logger,
modifier = modifier,
)
}
Expand All @@ -103,16 +106,26 @@ fun TiviContent(

private class TiviNavigator(
private val navigator: Navigator,
private val backStack: SaveableBackStack,
private val onOpenUrl: (String) -> Unit,
private val logger: Logger,
) : Navigator {
override fun goTo(screen: Screen) {
logger.d { "goTo. Screen: $screen. Current stack: ${backStack.toList()}" }

when (screen) {
is UrlScreen -> onOpenUrl(screen.url)
else -> navigator.goTo(screen)
}
}

override fun pop(): Screen? = navigator.pop()
override fun pop(): Screen? {
logger.d { "pop. Current stack: ${backStack.toList()}" }
return navigator.pop()
}

override fun resetRoot(newRoot: Screen): List<Screen> = navigator.resetRoot(newRoot)
override fun resetRoot(newRoot: Screen): List<Screen> {
logger.d { "resetRoot: newRoot:$newRoot. Current stack: ${backStack.toList()}" }
return navigator.resetRoot(newRoot)
}
}
11 changes: 10 additions & 1 deletion ui/root/src/iosMain/kotlin/app/tivi/home/GestureNavDecoration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.unit.dp
import app.tivi.common.compose.thenIf
import app.tivi.util.Logger
import com.slack.circuit.runtime.Navigator
import kotlin.math.absoluteValue
import kotlin.math.roundToInt
Expand All @@ -65,13 +66,15 @@ class SwipeProperties(
@OptIn(ExperimentalMaterialApi::class)
internal actual class GestureNavDecoration @ExperimentalMaterialApi constructor(
private val navigator: Navigator,
private val logger: Logger,
private val swipeProperties: SwipeProperties,
) : NavDecorationWithPrevious {

@OptIn(ExperimentalMaterialApi::class)
actual constructor(
navigator: Navigator,
) : this(navigator, SwipeProperties())
logger: Logger,
) : this(navigator, logger, SwipeProperties())

@Composable
override fun <T> DecoratedContent(
Expand All @@ -81,6 +84,12 @@ internal actual class GestureNavDecoration @ExperimentalMaterialApi constructor(
modifier: Modifier,
content: @Composable (T) -> Unit,
) {
SideEffect {
logger.d {
"DecoratedContent. arg: $arg. previous: $previous. backStackDepth: $backStackDepth"
}
}

Box(modifier = modifier) {
// Remember the previous stack depth so we know if the navigation is going "back".
var prevStackDepth by rememberSaveable { mutableStateOf(backStackDepth) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ package app.tivi.home

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import app.tivi.util.Logger
import com.slack.circuit.runtime.Navigator

internal actual class GestureNavDecoration actual constructor(
navigator: Navigator,
logger: Logger,
) : NavDecorationWithPrevious {
@Composable
override fun <T> DecoratedContent(
Expand Down
Loading