diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PaneStrategy.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PaneStrategy.kt index 937e043..ce23829 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PaneStrategy.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/PaneStrategy.kt @@ -42,4 +42,25 @@ fun paneStrategy( private val NoTransition = PaneScope.Transitions( enter = EnterTransition.None, exit = ExitTransition.None, +) + +/** + * Creates a new [PaneStrategy] from this by conditionally overriding parts of it. + * + * @see paneStrategy + * + * @param transitions the transitions to run within each [PaneScope]. + * @param paneMapping provides the mapping of panes to destinations for a given + * navigation [Destination]. + * @param render defines the Composable rendered for each destination + * in a given [PaneScope]. + */ +fun PaneStrategy.delegated( + transitions: PaneScope.() -> PaneScope.Transitions = this.transitions, + paneMapping: @Composable (Destination) -> Map = this.paneMapper, + render: @Composable PaneScope.(Destination) -> Unit = this.render +) = paneStrategy( + transitions = transitions, + paneMapping = paneMapping, + render = render ) \ No newline at end of file diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/AnimatePaneBoundsConfiguration.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/AnimatePaneBoundsConfiguration.kt index 6290a99..892c080 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/AnimatePaneBoundsConfiguration.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/AnimatePaneBoundsConfiguration.kt @@ -26,7 +26,6 @@ import com.tunjid.treenav.Node import com.tunjid.treenav.compose.PaneScope import com.tunjid.treenav.compose.PanedNavHostConfiguration import com.tunjid.treenav.compose.delegated -import com.tunjid.treenav.compose.paneStrategy import com.tunjid.treenav.compose.utilities.AnimatedBoundsState import com.tunjid.treenav.compose.utilities.AnimatedBoundsState.Companion.animateBounds import com.tunjid.treenav.compose.utilities.DefaultBoundsTransform @@ -50,12 +49,10 @@ fun PanedNavHostConfiguration lookaheadScope: LookaheadScope, paneBoundsTransform: PaneScope.() -> BoundsTransform = { DefaultBoundsTransform }, shouldAnimatePane: PaneScope.() -> Boolean = { true }, -): PanedNavHostConfiguration = delegated { - val originalTransform = strategyTransform(it) - paneStrategy( - transitions = originalTransform.transitions, - paneMapping = originalTransform.paneMapper, - render = render@{ destination -> +): PanedNavHostConfiguration = delegated { navigationDestination -> + val originalStrategy = strategyTransform(navigationDestination) + originalStrategy.delegated( + render = render@{ paneDestination -> Box( modifier = Modifier.animateBounds( state = remember { @@ -67,7 +64,7 @@ fun PanedNavHostConfiguration } ) ) { - originalTransform.render(this@render, destination) + originalStrategy.render(this@render, paneDestination) } } ) diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/PaneModifierConfiguration.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/PaneModifierConfiguration.kt index 9c8015f..42f5ad1 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/PaneModifierConfiguration.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/configurations/PaneModifierConfiguration.kt @@ -22,7 +22,6 @@ import com.tunjid.treenav.Node import com.tunjid.treenav.compose.PaneScope import com.tunjid.treenav.compose.PanedNavHostConfiguration import com.tunjid.treenav.compose.delegated -import com.tunjid.treenav.compose.paneStrategy /** * A [PanedNavHostConfiguration] that allows for centrally defining the [Modifier] for @@ -36,16 +35,14 @@ fun PanedNavHostConfiguration Destination >.paneModifierConfiguration( paneModifier: PaneScope.() -> Modifier = { Modifier }, -): PanedNavHostConfiguration = delegated { - val originalTransform = strategyTransform(it) - paneStrategy( - transitions = originalTransform.transitions, - paneMapping = originalTransform.paneMapper, - render = render@{ destination -> +): PanedNavHostConfiguration = delegated { navigationDestination -> + val originalStrategy = strategyTransform(navigationDestination) + originalStrategy.delegated( + render = render@{ paneDestination -> Box( modifier = paneModifier() ) { - originalTransform.render(this@render, destination) + originalStrategy.render(this@render, paneDestination) } } ) 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 b5eded0..8d5fd38 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 @@ -10,7 +10,6 @@ import androidx.compose.ui.Modifier import com.tunjid.treenav.Node 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 @@ -33,12 +32,9 @@ fun PanedNavHostConfiguration< >.threePanedMovableSharedElementConfiguration( movableSharedElementHostState: MovableSharedElementHostState, ): PanedNavHostConfiguration = - delegated { destination -> - val originalStrategy = - this@threePanedMovableSharedElementConfiguration.strategyTransform(destination) - PaneStrategy( - transitions = originalStrategy.transitions, - paneMapper = originalStrategy.paneMapper, + delegated { navigationDestination -> + val originalStrategy = strategyTransform(navigationDestination) + originalStrategy.delegated( render = { paneDestination -> val delegate = remember { AdaptiveMovableSharedElementScope( diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/PredictiveBackConfiguration.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/PredictiveBackConfiguration.kt index eec1449..6ae19ed 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/PredictiveBackConfiguration.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/PredictiveBackConfiguration.kt @@ -23,7 +23,6 @@ import androidx.compose.runtime.setValue import com.tunjid.treenav.Node import com.tunjid.treenav.compose.PanedNavHostConfiguration import com.tunjid.treenav.compose.delegated -import com.tunjid.treenav.compose.paneStrategy import com.tunjid.treenav.compose.threepane.ThreePane /** @@ -51,12 +50,11 @@ inline fun PanedNavHostConf if (isPreviewingBack.value) destinationTransform(navigationState.backPreviewTransform()) else current }, - strategyTransform = { destination -> - val originalStrategy = strategyTransform(destination) - paneStrategy( - transitions = originalStrategy.transitions, - paneMapping = paneMapper@{ inner -> - val originalMapping = originalStrategy.paneMapper(inner) + strategyTransform = { navigationDestination -> + val originalStrategy = strategyTransform(navigationDestination) + originalStrategy.delegated( + paneMapping = paneMapper@{ navigationDestinationToMap -> + val originalMapping = originalStrategy.paneMapper(navigationDestinationToMap) val isPreviewing by isPreviewingBack if (!isPreviewing) return@paneMapper originalMapping // Back is being previewed, therefore the original mapping is already for back. @@ -68,8 +66,7 @@ inline fun PanedNavHostConf .paneMapper(transientDestination) val transient = paneMapping[ThreePane.Primary] originalMapping + (ThreePane.TransientPrimary to transient) - }, - render = originalStrategy.render + } ) } ) diff --git a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/ThreePaneAdaptiveConfiguration.kt b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/ThreePaneAdaptiveConfiguration.kt index 4960c44..bdcb800 100644 --- a/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/ThreePaneAdaptiveConfiguration.kt +++ b/library/compose/src/commonMain/kotlin/com/tunjid/treenav/compose/threepane/configurations/ThreePaneAdaptiveConfiguration.kt @@ -5,7 +5,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import com.tunjid.treenav.Node import com.tunjid.treenav.compose.PanedNavHostConfiguration -import com.tunjid.treenav.compose.paneStrategy import com.tunjid.treenav.compose.delegated import com.tunjid.treenav.compose.threepane.ThreePane @@ -23,15 +22,13 @@ fun PanedNavHostConfiguration< windowWidthDpState: State, secondaryPaneBreakPoint: State = mutableStateOf(SECONDARY_PANE_MIN_WIDTH_BREAKPOINT_DP), tertiaryPaneBreakPoint: State = mutableStateOf(TERTIARY_PANE_MIN_WIDTH_BREAKPOINT_DP), -): PanedNavHostConfiguration = delegated { node -> - val originalStrategy = this@threePanedNavHostConfiguration.strategyTransform(node) - paneStrategy( - render = originalStrategy.render, - transitions = originalStrategy.transitions, - paneMapping = { inner -> +): PanedNavHostConfiguration = delegated { destination -> + val originalStrategy = strategyTransform(destination) + originalStrategy.delegated( + paneMapping = { navigationDestinationToMap -> // Consider navigation state different if window size class changes val windowWidthDp by windowWidthDpState - val originalMapping = originalStrategy.paneMapper(inner) + val originalMapping = originalStrategy.paneMapper(navigationDestinationToMap) val primaryNode = originalMapping[ThreePane.Primary] mapOf( ThreePane.Primary to primaryNode,