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

Updated names and packages for compose module #5

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 5 commits into from
Oct 12, 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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ kotlinxCoroutines = "1.9.0"
kotlinxDatetime = "0.6.1"
lifecycle-runtime = "2.8.6"
tunjidStateHolder = "1.1.0"
tunjidComposables = "0.0.4"
tunjidComposables = "0.0.5"
junit = "4.13.2"
runner = "1.0.2"
espressoCore = "3.0.2"
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.tunjid.treenav.adaptive
package com.tunjid.treenav.compose

import androidx.compose.animation.AnimatedContentScope
import androidx.compose.animation.AnimatedVisibilityScope
Expand All @@ -32,15 +32,15 @@ import kotlin.jvm.JvmInline
* Scope for adaptive content that can show up in an arbitrary pane.
*/
@Stable
interface AdaptivePaneScope<Pane, Destination : Node> : AnimatedVisibilityScope {
interface PaneScope<Pane, Destination : Node> : AnimatedVisibilityScope {

/**
* Provides information about the adaptive context that created this [AdaptivePaneScope].
* Provides information about the adaptive context that created this [PaneScope].
*/
val paneState: AdaptivePaneState<Pane, Destination>
val paneState: PaneState<Pane, Destination>

/**
* Whether or not this [AdaptivePaneScope] is active in its current pane. It is inactive when
* Whether or not this [PaneScope] is active in its current pane. It is inactive when
* it is animating out of its [AnimatedVisibilityScope].
*/
val isActive: Boolean
Expand All @@ -55,14 +55,14 @@ interface AdaptivePaneScope<Pane, Destination : Node> : AnimatedVisibilityScope
}

/**
* An implementation of [AdaptivePaneScope] that supports animations and shared elements
* An implementation of [PaneScope] that supports animations and shared elements
*/
@Stable
internal class AnimatedAdaptivePaneScope<Pane, Destination : Node>(
paneState: AdaptivePaneState<Pane, Destination>,
internal class AnimatedPaneScope<Pane, Destination : Node>(
paneState: PaneState<Pane, Destination>,
activeState: State<Boolean>,
val animatedContentScope: AnimatedContentScope
) : AdaptivePaneScope<Pane, Destination>, AnimatedVisibilityScope by animatedContentScope {
) : PaneScope<Pane, Destination>, AnimatedVisibilityScope by animatedContentScope {

override var paneState by mutableStateOf(paneState)

Expand All @@ -73,25 +73,25 @@ internal class AnimatedAdaptivePaneScope<Pane, Destination : Node>(
* Information about content in a pane
*/
@Stable
sealed interface AdaptivePaneState<Pane, Destination : Node> {
sealed interface PaneState<Pane, Destination : Node> {
val currentDestination: Destination?
val pane: Pane?
val adaptations: Set<Adaptation>
}

/**
* [Slot] based implementation of [AdaptivePaneState]
* [Slot] based implementation of [PaneState]
*/
internal data class SlotPaneState<Pane, Destination : Node>(
val slot: Slot?,
val previousDestination: Destination?,
override val currentDestination: Destination?,
override val pane: Pane?,
override val adaptations: Set<Adaptation>,
) : AdaptivePaneState<Pane, Destination>
) : PaneState<Pane, Destination>

/**
* A spot taken by an [AdaptivePaneStrategy] that may be moved in from pane to pane.
* A spot taken by an [PaneStrategy] that may be moved in from pane to pane.
*/
@JvmInline
internal value class Slot internal constructor(val index: Int)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.tunjid.treenav.compose

import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import com.tunjid.treenav.Node

/**
* Provides the logic used to select, configure and place a navigation [Destination] for each
* pane [Pane] for the current active navigation [Destination].
*/
@Stable
class PaneStrategy<Pane, Destination : Node> internal constructor(
val transitions: PaneScope<Pane, Destination>.() -> PaneScope.Transitions,
/**
* Defines what route to show in the secondary panel alongside this route
*/
val paneMapper: @Composable (Destination) -> Map<Pane, Destination?>,
val render: @Composable PaneScope<Pane, Destination>.(Destination) -> Unit
)

/**
* Allows for defining the logic used to select, configure and place a navigation
* [Destination] for each pane [Pane] for the current active navigation [Destination].
*
* @param transitions the transitions to run within each [PaneScope].
* @param paneMapping provides the mapping of panes to destinations for a given destination [Destination].
* @param render defines the Composable rendered for each destination
* in a given [PaneScope].
*/
fun <Pane, Destination : Node> paneStrategy(
transitions: PaneScope<Pane, Destination>.() -> PaneScope.Transitions = { NoTransition },
paneMapping: @Composable (Destination) -> Map<Pane, Destination?> = { emptyMap() },
render: @Composable PaneScope<Pane, Destination>.(Destination) -> Unit
) = PaneStrategy(
paneMapper = paneMapping,
transitions = transitions,
render = render
)

private val NoTransition = PaneScope.Transitions(
enter = EnterTransition.None,
exit = ExitTransition.None,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.tunjid.treenav.adaptive
package com.tunjid.treenav.compose

import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
Expand All @@ -24,18 +24,18 @@ import com.tunjid.treenav.Node
/**
* Creates a host for adaptive navigation for panes [Pane] and destinations [Destination].
*
* @param state the [AdaptiveNavHostState] producing the [AdaptiveNavHostScope] that provides
* context about the panes in [AdaptiveNavHost].
* @param state the [PanedNavHostState] producing the [PanedNavHostScope] that provides
* context about the panes in [PanedNavHost].
* @param modifier The modifier to be applied to the layout.
* @param content [AdaptiveNavHostScope] receiving lambda allowing for placing each pane in its
* @param content [PanedNavHostScope] receiving lambda allowing for placing each pane in its
* appropriate slot.
*
*/
@Composable
fun <Pane, Destination : Node> AdaptiveNavHost(
state: AdaptiveNavHostState<Pane, Destination>,
fun <Pane, Destination : Node> PanedNavHost(
state: PanedNavHostState<Pane, Destination>,
modifier: Modifier = Modifier,
content: @Composable AdaptiveNavHostScope<Pane, Destination>.() -> Unit
content: @Composable PanedNavHostScope<Pane, Destination>.() -> Unit
) {
Box(
modifier = modifier
Expand Down
Loading
Loading