From 0181976d55a2768ad64cac98e905d62c1421e68d Mon Sep 17 00:00:00 2001 From: Adetunji Dahunsi Date: Sat, 12 Oct 2024 14:35:31 -0400 Subject: [PATCH 1/3] Fix package names --- library/compose/build.gradle.kts | 2 +- .../com/tunjid/treenav/compose/PaneScope.kt | 2 +- .../tunjid/treenav/compose/PanedNavHost.kt | 3 +- .../compose/PanedNavHostConfiguration.kt | 5 ++-- .../compose/SavedStatePanedNavHostState.kt | 28 +++++++++---------- .../lifecycle/DestinationLifecycleOwner.kt | 4 +-- .../MovableSharedElementState.kt | 3 +- .../MovableSharedElements.kt | 2 +- .../MovableSharedElementConfiguration.kt | 10 +++---- .../com/tunjid/demo/common/ui/DemoApp.kt | 10 +++---- .../tunjid/demo/common/ui/chat/ChatScreen.kt | 2 +- .../demo/common/ui/profile/ProfileScreen.kt | 2 +- 12 files changed, 37 insertions(+), 36 deletions(-) diff --git a/library/compose/build.gradle.kts b/library/compose/build.gradle.kts index 1ba0099..e22400a 100644 --- a/library/compose/build.gradle.kts +++ b/library/compose/build.gradle.kts @@ -23,7 +23,7 @@ kotlin { iosSimulatorArm64(), ).forEach { iosTarget -> iosTarget.binaries.framework { - baseName = "treenav-adaptive" + baseName = "treenav-compose" isStatic = true } } diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PaneScope.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PaneScope.kt index 57ffe05..d245ff0 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PaneScope.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PaneScope.kt @@ -29,7 +29,7 @@ import com.tunjid.treenav.Node import kotlin.jvm.JvmInline /** - * Scope for adaptive content that can show up in an arbitrary pane. + * Scope for navigation destinations that can show up in an arbitrary pane. */ @Stable interface PaneScope : AnimatedVisibilityScope { diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PanedNavHost.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PanedNavHost.kt index ab83491..bb89cd8 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PanedNavHost.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PanedNavHost.kt @@ -22,7 +22,8 @@ import androidx.compose.ui.Modifier import com.tunjid.treenav.Node /** - * Creates a host for adaptive navigation for panes [Pane] and destinations [Destination]. + * Creates a navigation host for destinations [Destination] that can show up + * in arbitrary panes [Pane]. * * @param state the [PanedNavHostState] producing the [PanedNavHostScope] that provides * context about the panes in [PanedNavHost]. diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PanedNavHostConfiguration.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PanedNavHostConfiguration.kt index 856e335..03b13c5 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PanedNavHostConfiguration.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PanedNavHostConfiguration.kt @@ -48,10 +48,11 @@ class PanedNavHostConfiguration( val panesToNodes = configuration.paneMapping() val saveableStateHolder = rememberSaveableStateHolder() - val adaptiveContentScope = remember { + val panedContentScope = remember { SavedStatePanedNavHostScope( panes = panes, navHostConfiguration = configuration, @@ -95,13 +95,13 @@ class SavedStatePanedNavHostState( } LaunchedEffect(navigationState, panesToNodes) { - adaptiveContentScope.onNewNavigationState( + panedContentScope.onNewNavigationState( navigationState = navigationState, panesToNodes = panesToNodes ) } - return adaptiveContentScope + return panedContentScope } companion object { @@ -122,7 +122,7 @@ class SavedStatePanedNavHostState( init = ::Slot ).toSet() - var adaptiveNavigationState by mutableStateOf( + var panedNavigationState by mutableStateOf( value = SlotBasedPanedNavigationState.initial(slots = slots) .adaptTo( slots = slots, @@ -141,17 +141,17 @@ class SavedStatePanedNavHostState( @Composable override fun Destination(pane: Pane) { - val slot = adaptiveNavigationState.slotFor(pane) + val slot = panedNavigationState.slotFor(pane) slotsToRoutes[slot]?.invoke() } override fun adaptationsIn( pane: Pane - ): Set = adaptiveNavigationState.adaptationsIn(pane) + ): Set = panedNavigationState.adaptationsIn(pane) override fun nodeFor( pane: Pane - ): Destination? = adaptiveNavigationState.destinationFor(pane) + ): Destination? = panedNavigationState.destinationFor(pane) fun onNewNavigationState( navigationState: Node, @@ -175,7 +175,7 @@ class SavedStatePanedNavHostState( slot: Slot, ) { val paneTransition = updateTransition( - targetState = adaptiveNavigationState.paneStateFor(slot), + targetState = panedNavigationState.paneStateFor(slot), label = "$slot-PaneTransition", ) paneTransition.AnimatedContent( @@ -192,7 +192,7 @@ class SavedStatePanedNavHostState( AnimatedPaneScope( paneState = targetPaneState, activeState = derivedStateOf { - val activePaneState = adaptiveNavigationState.paneStateFor(slot) + val activePaneState = panedNavigationState.paneStateFor(slot) activePaneState.currentDestination?.id == targetPaneState.currentDestination?.id }, animatedContentScope = this@AnimatedContent, @@ -220,7 +220,7 @@ class SavedStatePanedNavHostState( DisposableEffect(Unit) { onDispose { - val backstackIds = adaptiveNavigationState.backStackIds + val backstackIds = panedNavigationState.backStackIds if (!backstackIds.contains(destination.id)) removeState( destination.id ) @@ -231,18 +231,18 @@ class SavedStatePanedNavHostState( DisposableEffect( hostLifecycleState, scope.isActive, - adaptiveNavigationState, + panedNavigationState, ) { destinationLifecycleOwner.update( hostLifecycleState = hostLifecycleState, paneScope = scope, - adaptiveNavigationState = adaptiveNavigationState + panedNavigationState = panedNavigationState ) onDispose { destinationLifecycleOwner.update( hostLifecycleState = hostLifecycleState, paneScope = scope, - adaptiveNavigationState = adaptiveNavigationState + panedNavigationState = panedNavigationState ) } } @@ -276,7 +276,7 @@ class SavedStatePanedNavHostState( private inline fun updateAdaptiveNavigationState( block: SlotBasedPanedNavigationState.() -> SlotBasedPanedNavigationState ) { - adaptiveNavigationState = adaptiveNavigationState.block() + panedNavigationState = panedNavigationState.block() } } diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/lifecycle/DestinationLifecycleOwner.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/lifecycle/DestinationLifecycleOwner.kt index 16e2a2a..421073c 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/lifecycle/DestinationLifecycleOwner.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/lifecycle/DestinationLifecycleOwner.kt @@ -42,10 +42,10 @@ internal class DestinationLifecycleOwner( fun update( hostLifecycleState: State, paneScope: PaneScope<*, *>, - adaptiveNavigationState: SlotBasedPanedNavigationState<*, *>, + panedNavigationState: SlotBasedPanedNavigationState<*, *>, ) { val active = paneScope.isActive - val exists = adaptiveNavigationState.backStackIds.contains( + val exists = panedNavigationState.backStackIds.contains( destination.id ) val derivedLifecycleState = when { diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElementState.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElementState.kt index 9e97c2b..d0aca54 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElementState.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElementState.kt @@ -1,4 +1,4 @@ -package com.tunjid.scaffold.treenav.adaptive.moveablesharedelement +package com.tunjid.treenav.compose.moveablesharedelement import androidx.compose.animation.BoundsTransform import androidx.compose.animation.ExperimentalSharedTransitionApi @@ -36,7 +36,6 @@ import androidx.compose.ui.util.fastRoundToInt import com.tunjid.treenav.Node import com.tunjid.treenav.compose.PaneScope import com.tunjid.treenav.compose.PaneState -import com.tunjid.treenav.compose.moveablesharedelement.BoundsTransformDeferredAnimation import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.first diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt index 8ca6fc3..9149b64 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt @@ -1,4 +1,4 @@ -package com.tunjid.scaffold.treenav.adaptive.moveablesharedelement +package com.tunjid.treenav.compose.moveablesharedelement import androidx.compose.animation.BoundsTransform import androidx.compose.animation.ExperimentalSharedTransitionApi diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt index ad63802..a477f88 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt @@ -7,16 +7,16 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.Stable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import com.tunjid.scaffold.treenav.adaptive.moveablesharedelement.AdaptiveMovableSharedElementScope -import com.tunjid.scaffold.treenav.adaptive.moveablesharedelement.MovableSharedElementHostState -import com.tunjid.scaffold.treenav.adaptive.moveablesharedelement.MovableSharedElementScope import com.tunjid.treenav.Node -import com.tunjid.treenav.compose.PanedNavHost -import com.tunjid.treenav.compose.PanedNavHostConfiguration import com.tunjid.treenav.compose.PaneScope import com.tunjid.treenav.compose.PaneState import com.tunjid.treenav.compose.PaneStrategy +import com.tunjid.treenav.compose.PanedNavHost +import com.tunjid.treenav.compose.PanedNavHostConfiguration import com.tunjid.treenav.compose.delegated +import com.tunjid.treenav.compose.moveablesharedelement.AdaptiveMovableSharedElementScope +import com.tunjid.treenav.compose.moveablesharedelement.MovableSharedElementHostState +import com.tunjid.treenav.compose.moveablesharedelement.MovableSharedElementScope import com.tunjid.treenav.compose.threepane.ThreePane diff --git a/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/DemoApp.kt b/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/DemoApp.kt index 4b2e0e0..17ab663 100644 --- a/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/DemoApp.kt +++ b/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/DemoApp.kt @@ -46,7 +46,7 @@ import com.tunjid.demo.common.ui.data.NavigationRepository import com.tunjid.demo.common.ui.data.SampleDestination import com.tunjid.demo.common.ui.profile.profilePaneStrategy import com.tunjid.demo.common.ui.me.mePaneStrategy -import com.tunjid.scaffold.treenav.adaptive.moveablesharedelement.MovableSharedElementHostState +import com.tunjid.treenav.compose.moveablesharedelement.MovableSharedElementHostState import com.tunjid.treenav.MultiStackNav import com.tunjid.treenav.compose.PanedNavHost import com.tunjid.treenav.compose.PanedNavHostConfiguration @@ -144,7 +144,7 @@ class SampleAppState( ) val currentNavigation by navigationState - private val adaptiveNavHostConfiguration = sampleAppNavHostConfiguration( + private val panedNavHostConfiguration = sampleAppNavHostConfiguration( navigationState ) @@ -163,10 +163,10 @@ class SampleAppState( SampleDestination >.() -> PanedNavHostConfiguration ): SavedStatePanedNavHostState { - val adaptiveNavHostState = remember { + val panedNavHostState = remember { SavedStatePanedNavHostState( panes = ThreePane.entries.toList(), - configuration = adaptiveNavHostConfiguration.configurationBlock(), + configuration = panedNavHostConfiguration.configurationBlock(), ) } DisposableEffect(Unit) { @@ -177,7 +177,7 @@ class SampleAppState( } onDispose { job.cancel() } } - return adaptiveNavHostState + return panedNavHostState } } } diff --git a/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/chat/ChatScreen.kt b/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/chat/ChatScreen.kt index 1db6bd8..b1cc018 100644 --- a/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/chat/ChatScreen.kt +++ b/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/chat/ChatScreen.kt @@ -52,7 +52,7 @@ import com.tunjid.demo.common.ui.ProfilePhotoArgs import com.tunjid.demo.common.ui.SampleTopAppBar import com.tunjid.demo.common.ui.data.Message import com.tunjid.demo.common.ui.data.Profile -import com.tunjid.scaffold.treenav.adaptive.moveablesharedelement.MovableSharedElementScope +import com.tunjid.treenav.compose.moveablesharedelement.MovableSharedElementScope import kotlinx.datetime.Instant import kotlinx.datetime.TimeZone import kotlinx.datetime.toLocalDateTime diff --git a/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/profile/ProfileScreen.kt b/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/profile/ProfileScreen.kt index 61a91c3..3783786 100644 --- a/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/profile/ProfileScreen.kt +++ b/sample/common/src/commonMain/kotlin/com/tunjid/demo/common/ui/profile/ProfileScreen.kt @@ -41,7 +41,7 @@ import com.tunjid.demo.common.ui.ProfilePhoto import com.tunjid.demo.common.ui.ProfilePhotoArgs import com.tunjid.demo.common.ui.SampleTopAppBar import com.tunjid.demo.common.ui.rememberAppBarCollapsingHeaderState -import com.tunjid.scaffold.treenav.adaptive.moveablesharedelement.MovableSharedElementScope +import com.tunjid.treenav.compose.moveablesharedelement.MovableSharedElementScope import kotlin.math.roundToInt @Composable From 8425f8321018a24f82ebcf95b298d27e1bdff491 Mon Sep 17 00:00:00 2001 From: Adetunji Dahunsi Date: Sat, 12 Oct 2024 14:48:08 -0400 Subject: [PATCH 2/3] Add BlankElement --- .../MovableSharedElementConfiguration.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt index a477f88..ffeec91 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt @@ -93,9 +93,7 @@ private class ThreePaneMovableSharedElementScope( // Allow shared elements in the primary or transient primary content only ThreePane.Primary -> when { // Show a blank space for shared elements between the destinations - paneScope.isPreviewingBack && hostState.isCurrentlyShared(key) -> { _, modifier -> - Box(modifier) - } + paneScope.isPreviewingBack && hostState.isCurrentlyShared(key) -> EmptyElement // If previewing and it won't be shared, show the item as is paneScope.isPreviewingBack -> sharedElement // Share the element @@ -125,4 +123,9 @@ fun PaneState?.canAnimateOnStartingFrames() = private val PaneScope.isPreviewingBack: Boolean get() = paneState.pane == ThreePane.Primary - && paneState.adaptations.contains(ThreePane.PrimaryToTransient) \ No newline at end of file + && paneState.adaptations.contains(ThreePane.PrimaryToTransient) + +// An empty element representing blank space +private val EmptyElement: @Composable (Any?, Modifier) -> Unit = { _, modifier -> + Box(modifier) +} \ No newline at end of file From 359b1477594d7adb28d664aa9442b3b3ab3e2b0b Mon Sep 17 00:00:00 2001 From: Adetunji Dahunsi Date: Sun, 13 Oct 2024 05:18:44 -0400 Subject: [PATCH 3/3] Update logice for displaying a movable shared element, just the element or a blank space --- .../MovableSharedElementState.kt | 15 +++--- .../MovableSharedElements.kt | 31 ++++++++---- .../MovableSharedElementConfiguration.kt | 49 +++++++++---------- 3 files changed, 53 insertions(+), 42 deletions(-) diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElementState.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElementState.kt index d0aca54..13f8cf0 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElementState.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElementState.kt @@ -56,15 +56,16 @@ internal class MovableSharedElementState( private var layer: GraphicsLayer? = null private var targetOffset by mutableStateOf(IntOffset.Zero) - private var boundsAnimInProgress by mutableStateOf(false) + var animInProgress by mutableStateOf(false) + private set - private val canDrawInOverlay get() = boundsAnimInProgress + private val canDrawInOverlay get() = animInProgress private val panesKeysToSeenCount = mutableStateMapOf() private val animatedBounds: Rect? - get() = if (boundsAnimInProgress) boundsAnimation.animatedValue else null + get() = if (animInProgress) boundsAnimation.animatedValue else null - val boundsAnimation = BoundsTransformDeferredAnimation() + private val boundsAnimation = BoundsTransformDeferredAnimation() val moveableSharedElement: @Composable (Any?, Modifier) -> Unit = movableContentOf { state, modifier -> @@ -117,7 +118,7 @@ internal class MovableSharedElementState( state: MovableSharedElementState<*, Pane, Destination>, ): Modifier { val coroutineScope = rememberCoroutineScope() - state.isInProgress().also { state.boundsAnimInProgress = it } + state.isInProgress().also { state.animInProgress = it } val layer = rememberGraphicsLayer().also { state.layer = it } @@ -125,7 +126,7 @@ internal class MovableSharedElementState( isMeasurementApproachInProgress = { lookaheadSize -> // Update target size, it will serve to know if we expect an approach in progress state.boundsAnimation.updateTargetSize(lookaheadSize.toSize()) - state.boundsAnimInProgress + state.animInProgress }, isPlacementApproachInProgress = { state.boundsAnimation.updateTargetOffsetAndAnimate( @@ -135,7 +136,7 @@ internal class MovableSharedElementState( includeMotionFrameOfReference = true, boundsTransform = state.boundsTransform, ) - state.boundsAnimInProgress + state.animInProgress }, approachMeasure = { measurable, _ -> // The animated value is null on the first frame as we don't get the full bounds diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt index 9149b64..f6021d4 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/moveablesharedelement/MovableSharedElements.kt @@ -85,6 +85,12 @@ class MovableSharedElementHostState( fun isCurrentlyShared(key: Any): Boolean = keysToMovableSharedElements.contains(key) + /** + * Returns true if a movable shared element is animating. + */ + fun isInProgress(key: Any): Boolean = + keysToMovableSharedElements[key]?.animInProgress == true + /** * Provides a movable shared element that can be rendered in a given [PaneScope]. * It is the callers responsibility to perform other verifications on the ability @@ -131,24 +137,31 @@ internal class AdaptiveMovableSharedElementScope( key: Any, boundsTransform: BoundsTransform, sharedElement: @Composable (T, Modifier) -> Unit - ): @Composable (T, Modifier) -> Unit { - // This pane state may be animating out. Look up the actual current route - // Do not use the shared element if this content is being animated out - if (!paneScope.isActive) return emptyComposable() - - return with(movableSharedElementHostState) { + ): @Composable (T, Modifier) -> Unit = when { + paneScope.isActive -> with(movableSharedElementHostState) { paneScope.createOrUpdateSharedElement( key = key, boundsTransform = boundsTransform, sharedElement = sharedElement ) } + // This pane state is be transitioning out. Check if it should be displayed without + // shared element semantics. + else -> when { + movableSharedElementHostState.isCurrentlyShared(key) -> + // The element is being shared in its new destination, stop showing it + // in the in active one + if (movableSharedElementHostState.isInProgress(key)) EmptyElement + // The element is not being shared in its new destination, allow it run its exit + // transition + else sharedElement + // Element isn't being shared anymore, show the element as is without sharing. + else -> sharedElement + } } } -private fun emptyComposable(): @Composable (T, Modifier) -> Unit = EMPTY_COMPOSABLE - -private val EMPTY_COMPOSABLE: @Composable (Any?, Modifier) -> Unit = { _, _ -> } +private val EmptyElement: @Composable (Any?, Modifier) -> Unit = { _, _ -> } @OptIn(ExperimentalSharedTransitionApi::class) private val DefaultBoundsTransform = BoundsTransform { _, _ -> diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt index ffeec91..722055e 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/MovableSharedElementConfiguration.kt @@ -84,37 +84,34 @@ private class ThreePaneMovableSharedElementScope( key: Any, boundsTransform: BoundsTransform, sharedElement: @Composable (T, Modifier) -> Unit - ): @Composable (T, Modifier) -> Unit { - val paneScope = delegate.paneScope - return when (paneScope.paneState.pane) { - null -> throw IllegalArgumentException( - "Shared elements may only be used in non null panes" - ) - // Allow shared elements in the primary or transient primary content only - ThreePane.Primary -> when { - // Show a blank space for shared elements between the destinations - paneScope.isPreviewingBack && hostState.isCurrentlyShared(key) -> EmptyElement - // If previewing and it won't be shared, show the item as is - paneScope.isPreviewingBack -> sharedElement - // Share the element - else -> delegate.movableSharedElementOf( - key = key, - boundsTransform = boundsTransform, - sharedElement = sharedElement - ) - } - // Share the element when in the transient pane - ThreePane.TransientPrimary -> delegate.movableSharedElementOf( + ): @Composable (T, Modifier) -> Unit = when (paneState.pane) { + null -> throw IllegalArgumentException( + "Shared elements may only be used in non null panes" + ) + // Allow shared elements in the primary or transient primary content only + ThreePane.Primary -> when { + // Show a blank space for shared elements between the destinations + isPreviewingBack && hostState.isCurrentlyShared(key) -> EmptyElement + // If previewing and it won't be shared, show the item as is + isPreviewingBack -> sharedElement + // Share the element + else -> delegate.movableSharedElementOf( key = key, boundsTransform = boundsTransform, sharedElement = sharedElement ) - - // In the other panes use the element as is - ThreePane.Secondary, - ThreePane.Tertiary, - ThreePane.Overlay -> sharedElement } + // Share the element when in the transient pane + ThreePane.TransientPrimary -> delegate.movableSharedElementOf( + key = key, + boundsTransform = boundsTransform, + sharedElement = sharedElement + ) + + // In the other panes use the element as is + ThreePane.Secondary, + ThreePane.Tertiary, + ThreePane.Overlay -> sharedElement } }