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

Tighten up APIs #15

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 2 commits into from
Nov 1, 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
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ androidGradlePlugin = "8.5.2"
androidxActivity = "1.9.2"
activity-compose = "1.9.2"
androidxAppCompat = "1.7.0"
androidxBenchmark = "1.3.0"
androidxBenchmark = "1.3.3"
androidxCore = "1.13.1"
androidxCompose = "1.7.0"
androidxPaging = "3.3.2"
Expand All @@ -12,16 +12,16 @@ androidxTestExt = "1.2.1"
androidxTestRunner = "1.6.2"
androidxTestRules = "1.6.1"
dokka = "1.8.20"
jetbrainsCompose = "1.7.0-rc01"
jetbrainsLifecycle = "2.8.2"
jetbrainsMaterial3Adaptive = "1.0.0-rc01"
jetbrainsCompose = "1.7.0"
jetbrainsLifecycle = "2.8.3"
jetbrainsMaterial3Adaptive = "1.0.0"
junit4 = "4.13.2"
kotlin = "2.0.20"
kotlinxCoroutines = "1.9.0"
kotlinxDatetime = "0.6.1"
lifecycle-runtime = "2.8.6"
tunjidStateHolder = "1.1.0"
tunjidComposables = "0.0.5"
tunjidComposables = "0.0.7"
junit = "4.13.2"
runner = "1.0.2"
espressoCore = "3.0.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.tunjid.treenav.traverse
interface PanedNavHostState<Pane, Destination : Node> {

/**
* Creates the scope that provides context about individual panes [Pane] in an [PanedNavHost].
* Creates the scope that provides context about individual panes [Pane] in a [PanedNavHost].
*/
@Composable
fun scope(): PanedNavHostScope<Pane, Destination>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@ package com.tunjid.treenav.compose.threepane.configurations
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.tunjid.treenav.Node
import com.tunjid.treenav.compose.PanedNavHostConfiguration
import com.tunjid.treenav.compose.delegated
import com.tunjid.treenav.compose.threepane.ThreePane

/**
* An [PanedNavHostConfiguration] that selectively displays panes for a [ThreePane] layout
* based on the space available determined by the [windowWidthDpState].
* based on the space available determined by the [windowWidthState].
*
* @param windowWidthDpState provides the current width of the display in Dp.
* @param windowWidthState provides the current width of the display in Dp.
*/
fun <NavigationState : Node, Destination : Node> PanedNavHostConfiguration<
ThreePane,
NavigationState,
Destination
>.threePanedNavHostConfiguration(
windowWidthDpState: State<Int>,
secondaryPaneBreakPoint: State<Int> = mutableStateOf(SECONDARY_PANE_MIN_WIDTH_BREAKPOINT_DP),
tertiaryPaneBreakPoint: State<Int> = mutableStateOf(TERTIARY_PANE_MIN_WIDTH_BREAKPOINT_DP),
windowWidthState: State<Dp>,
secondaryPaneBreakPoint: State<Dp> = mutableStateOf(SECONDARY_PANE_MIN_WIDTH_BREAKPOINT_DP),
tertiaryPaneBreakPoint: State<Dp> = mutableStateOf(TERTIARY_PANE_MIN_WIDTH_BREAKPOINT_DP),
): 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 windowWidthDp by windowWidthState
val originalMapping = originalStrategy.paneMapper(navigationDestinationToMap)
val primaryNode = originalMapping[ThreePane.Primary]
mapOf(
Expand All @@ -45,5 +47,5 @@ fun <NavigationState : Node, Destination : Node> PanedNavHostConfiguration<
)
}

private const val SECONDARY_PANE_MIN_WIDTH_BREAKPOINT_DP = 600
private const val TERTIARY_PANE_MIN_WIDTH_BREAKPOINT_DP = 1200
private val SECONDARY_PANE_MIN_WIDTH_BREAKPOINT_DP = 600.dp
private val TERTIARY_PANE_MIN_WIDTH_BREAKPOINT_DP = 1200.dp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ internal class BoundsTransformDeferredAnimation {

// Find the given lookahead coordinates by traversing up the tree
while (currentCoords.toLookaheadCoordinates() != lookaheadScopeCoordinates) {
if (currentCoords.introducesMotionFrameOfReference) {
if (currentCoords.isAttached && currentCoords.introducesMotionFrameOfReference) {
if (parents.size == index) {
parents.add(currentCoords)
delta += currentCoords.positionInParent()
Expand All @@ -294,11 +294,13 @@ internal class BoundsTransformDeferredAnimation {
}
index++
}
currentCoords = currentCoords.parentCoordinates ?: break
currentCoords = currentCoords.parentCoordinates
?.takeIf(LayoutCoordinates::isAttached)
?: break
}

for (i in parents.size - 1 downTo index) {
delta -= parents[i].positionInParent()
if (parents[i].isAttached) delta -= parents[i].positionInParent()
parents.removeAt(parents.size - 1)
}
directManipulationParents = parents
Expand Down
6 changes: 3 additions & 3 deletions libraryVersion.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
# limitations under the License.
#
groupId=com.tunjid.treenav
treenav_version=0.0.7
strings_version=0.0.7
compose_version=0.0.7
treenav_version=0.0.9
strings_version=0.0.9
compose_version=0.0.9
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -61,13 +60,14 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.round
import com.tunjid.composables.splitlayout.SplitLayout
import com.tunjid.composables.splitlayout.SplitLayoutState
import com.tunjid.demo.common.ui.SampleAppState.Companion.rememberPanedNavHostState
import com.tunjid.demo.common.ui.chat.chatPaneStrategy
import com.tunjid.demo.common.ui.chatrooms.chatRoomPaneStrategy
Expand Down Expand Up @@ -95,7 +95,6 @@ import com.tunjid.treenav.popToRoot
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlin.math.roundToInt

@OptIn(ExperimentalSharedTransitionApi::class)
@Composable
Expand All @@ -115,7 +114,19 @@ fun SampleApp(
}
) {
SharedTransitionScope { sharedTransitionModifier ->
val windowWidthDp = remember { mutableIntStateOf(0) }
val order = remember {
listOf(
ThreePane.Tertiary,
ThreePane.Secondary,
ThreePane.Primary,
)
}
val splitLayoutState = remember {
SplitLayoutState(
orientation = Orientation.Horizontal,
maxCount = order.size,
)
}
val surfaceColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
animateDpAsState(if (appState.predictiveBackStatus.value) 16.dp else 0.dp).value
)
Expand All @@ -134,6 +145,8 @@ fun SampleApp(
}

PanedNavHost(
modifier = Modifier
.fillMaxSize(),
state = appState.rememberPanedNavHostState {
this
.paneModifierConfiguration {
Expand All @@ -148,7 +161,9 @@ fun SampleApp(
.fillMaxSize()
}
.threePanedNavHostConfiguration(
windowWidthDpState = windowWidthDp
windowWidthState = derivedStateOf {
splitLayoutState.size
}
)
.predictiveBackConfiguration(
isPreviewingBack = appState.predictiveBackStatus,
Expand All @@ -172,38 +187,20 @@ fun SampleApp(
}
)
},
modifier = Modifier
.fillMaxSize()
.onSizeChanged {
windowWidthDp.value = (it.width / density.density).roundToInt()
}
) {
val order = remember {
listOf(
ThreePane.Tertiary,
ThreePane.Secondary,
ThreePane.Primary,
)
}
val filteredOrder by remember {
derivedStateOf { order.filter { nodeFor(it) != null } }
}
val segmentedLayoutState = remember {
SegmentedLayoutState(
totalCount = order.size,
)
}.also {
it.visibleCount = filteredOrder.size
}
SegmentedLayout(
state = segmentedLayoutState,
splitLayoutState.visibleCount = filteredOrder.size
SplitLayout(
state = splitLayoutState,
modifier = Modifier
.fillMaxSize()
then movableSharedElementHostState.modifier
then sharedTransitionModifier,
itemSeparators = { paneIndex, offset ->
PaneSeparator(
segmentedLayoutState = segmentedLayoutState,
splitLayoutState = splitLayoutState,
interactionSource = appState.paneInteractionSourceAt(paneIndex),
index = paneIndex,
density = density,
Expand All @@ -223,7 +220,7 @@ fun SampleApp(

@Composable
private fun PaneSeparator(
segmentedLayoutState: SegmentedLayoutState,
splitLayoutState: SplitLayoutState,
interactionSource: MutableInteractionSource,
modifier: Modifier = Modifier,
index: Int,
Expand All @@ -232,7 +229,7 @@ private fun PaneSeparator(
) {
var alpha by remember { mutableFloatStateOf(0f) }
val draggableState = rememberDraggableState {
segmentedLayoutState.dragBy(
splitLayoutState.dragBy(
index = index,
delta = with(density) { it.toDp() }
)
Expand Down
Loading
Loading