这是indexloc提供的服务,不要输入任何密码
Skip to content

Cleaned up methods used to customize pane behavior #9

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

Merged
merged 1 commit into from
Oct 19, 2024
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 @@ -42,4 +42,25 @@ fun <Pane, Destination : Node> 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 <Pane, Destination : Node> PaneStrategy<Pane, Destination>.delegated(
transitions: PaneScope<Pane, Destination>.() -> PaneScope.Transitions = this.transitions,
paneMapping: @Composable (Destination) -> Map<Pane, Destination?> = this.paneMapper,
render: @Composable PaneScope<Pane, Destination>.(Destination) -> Unit = this.render
) = paneStrategy(
transitions = transitions,
paneMapping = paneMapping,
render = render
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,12 +49,10 @@ fun <Pane, NavigationState : Node, Destination : Node> PanedNavHostConfiguration
lookaheadScope: LookaheadScope,
paneBoundsTransform: PaneScope<Pane, Destination>.() -> BoundsTransform = { DefaultBoundsTransform },
shouldAnimatePane: PaneScope<Pane, Destination>.() -> Boolean = { true },
): PanedNavHostConfiguration<Pane, NavigationState, Destination> = delegated {
val originalTransform = strategyTransform(it)
paneStrategy(
transitions = originalTransform.transitions,
paneMapping = originalTransform.paneMapper,
render = render@{ destination ->
): PanedNavHostConfiguration<Pane, NavigationState, Destination> = delegated { navigationDestination ->
val originalStrategy = strategyTransform(navigationDestination)
originalStrategy.delegated(
render = render@{ paneDestination ->
Box(
modifier = Modifier.animateBounds(
state = remember {
Expand All @@ -67,7 +64,7 @@ fun <Pane, NavigationState : Node, Destination : Node> PanedNavHostConfiguration
}
)
) {
originalTransform.render(this@render, destination)
originalStrategy.render(this@render, paneDestination)
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,16 +35,14 @@ fun <Pane, NavigationState : Node, Destination : Node> PanedNavHostConfiguration
Destination
>.paneModifierConfiguration(
paneModifier: PaneScope<Pane, Destination>.() -> Modifier = { Modifier },
): PanedNavHostConfiguration<Pane, NavigationState, Destination> = delegated {
val originalTransform = strategyTransform(it)
paneStrategy(
transitions = originalTransform.transitions,
paneMapping = originalTransform.paneMapper,
render = render@{ destination ->
): PanedNavHostConfiguration<Pane, NavigationState, Destination> = delegated { navigationDestination ->
val originalStrategy = strategyTransform(navigationDestination)
originalStrategy.delegated(
render = render@{ paneDestination ->
Box(
modifier = paneModifier()
) {
originalTransform.render(this@render, destination)
originalStrategy.render(this@render, paneDestination)
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,12 +32,9 @@ fun <NavigationState : Node, Destination : Node> PanedNavHostConfiguration<
>.threePanedMovableSharedElementConfiguration(
movableSharedElementHostState: MovableSharedElementHostState<ThreePane, Destination>,
): PanedNavHostConfiguration<ThreePane, NavigationState, Destination> =
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -51,12 +50,11 @@ inline fun <NavigationState : Node, reified Destination : Node> 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.
Expand All @@ -68,8 +66,7 @@ inline fun <NavigationState : Node, reified Destination : Node> PanedNavHostConf
.paneMapper(transientDestination)
val transient = paneMapping[ThreePane.Primary]
originalMapping + (ThreePane.TransientPrimary to transient)
},
render = originalStrategy.render
}
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -23,15 +22,13 @@ fun <NavigationState : Node, Destination : Node> PanedNavHostConfiguration<
windowWidthDpState: State<Int>,
secondaryPaneBreakPoint: State<Int> = mutableStateOf(SECONDARY_PANE_MIN_WIDTH_BREAKPOINT_DP),
tertiaryPaneBreakPoint: State<Int> = mutableStateOf(TERTIARY_PANE_MIN_WIDTH_BREAKPOINT_DP),
): PanedNavHostConfiguration<ThreePane, NavigationState, Destination> = delegated { node ->
val originalStrategy = this@threePanedNavHostConfiguration.strategyTransform(node)
paneStrategy(
render = originalStrategy.render,
transitions = originalStrategy.transitions,
paneMapping = { inner ->
): PanedNavHostConfiguration<ThreePane, NavigationState, Destination> = 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,
Expand Down
Loading