Swap Android detail sections in place instead of sliding them
Selecting a section in a run or pipeline detail now cross-fades the body in place rather than sliding it sideways, so a tap on the rail or tab row is an ordinary tab change with no lateral motion and nothing to swipe. - DetailTabs.kt drops the HorizontalPager for section bodies and renders only the selected section behind a short Crossfade (SECTION_SWAP_MILLIS = 180). Level navigation (list -> detail -> stage pane) still slides via the unchanged SlidingPaneStack. - Each section's saved state (its LazyColumn scroll) is kept under its stable tab key with rememberSaveableStateHolder().SaveableStateProvider, so returning to a section restores where the operator left off instead of resetting it. - The rail/tab-row selected state and tab semantics are unchanged. - Update the two call sites' stale "pager" comments and refresh the README section describing the section selector.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package net.awan.pipelines.ui.components
|
||||
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -12,8 +14,6 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.selection.selectableGroup
|
||||
import androidx.compose.material.icons.Icons
|
||||
@@ -32,15 +32,12 @@ import androidx.compose.material3.Tab
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.VerticalDivider
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.saveable.Saver
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -49,7 +46,6 @@ import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import net.awan.pipelines.ui.theme.pipelinesText
|
||||
|
||||
/**
|
||||
@@ -83,19 +79,19 @@ fun clampTabIndex(index: Int, tabCount: Int): Int =
|
||||
if (tabCount <= 0) 0 else index.coerceIn(0, tabCount - 1)
|
||||
|
||||
/**
|
||||
* The section index + its panel, open to the right. On narrow windows the index
|
||||
* is a horizontally scrolling Material 3 [PrimaryScrollableTabRow]; on wide
|
||||
* windows it is an always-visible selectable rail. Both stay fixed and visible
|
||||
* while the sections themselves live in a [HorizontalPager], so tapping a
|
||||
* section slides its panel in from the right (and a later section enters from the
|
||||
* right, an earlier one from the left as the pager follows the index order);
|
||||
* swiping switches sections too.
|
||||
* The section index + its panel. On narrow windows the index is a horizontally
|
||||
* scrolling Material 3 [PrimaryScrollableTabRow]; on wide windows it is an
|
||||
* always-visible selectable rail. Both stay fixed and visible while the selected
|
||||
* section's panel swaps in place behind a short [Crossfade]: selecting a section
|
||||
* is an ordinary tab change with no lateral motion and no swipe, because the
|
||||
* sections are not a left-to-right pager. Only navigation between levels
|
||||
* (list → detail → stage pane) slides, via
|
||||
* [net.awan.pipelines.ui.components.SlidingPaneStack].
|
||||
*
|
||||
* The pager composes only the visible page at rest (the default
|
||||
* `beyondViewportPageCount`), preserving the previous laziness. `selectedIndex`
|
||||
* is the single source of truth: a change from outside (e.g. Back) scrolls the
|
||||
* pager, and a settled pager (a tap or a swipe) reports the new index through
|
||||
* [onSelect]. The two are guarded against feedback loops.
|
||||
* [selectedIndex] is the single source of truth; a tap reports the new index
|
||||
* through [onSelect]. Each section's own saved state (e.g. its list scroll
|
||||
* position) is keyed by its stable tab key, so returning to a section restores
|
||||
* where the operator left off instead of resetting it.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -109,27 +105,26 @@ fun DetailTabs(
|
||||
) {
|
||||
if (tabs.isEmpty()) return
|
||||
val selected = clampTabIndex(selectedIndex, tabs.size)
|
||||
val pagerState = rememberPagerState(initialPage = selected, pageCount = { tabs.size })
|
||||
// One entry per stable tab key holds a section's state while that section is
|
||||
// off-screen, so swapping sections never resets a section's scroll position
|
||||
// (or any other saved state).
|
||||
val stateHolder = rememberSaveableStateHolder()
|
||||
|
||||
// External selection (Back, or a restored index) moves the pager; skip while
|
||||
// a finger is down so a swipe is never fought mid-gesture.
|
||||
LaunchedEffect(selected, tabs.size) {
|
||||
if (!pagerState.isScrollInProgress && pagerState.settledPage != selected) {
|
||||
pagerState.animateScrollToPage(selected)
|
||||
// A short cross-fade replaces the section in place: the incoming panel fades
|
||||
// in as the outgoing one fades out, with no horizontal travel.
|
||||
val swap: @Composable (Modifier) -> Unit = { contentModifier ->
|
||||
Crossfade(
|
||||
targetState = selected,
|
||||
animationSpec = tween(durationMillis = SECTION_SWAP_MILLIS),
|
||||
modifier = contentModifier,
|
||||
label = "section-swap",
|
||||
) { index ->
|
||||
val tab = tabs[clampTabIndex(index, tabs.size)]
|
||||
stateHolder.SaveableStateProvider(tab.key) {
|
||||
content(tab, Modifier.fillMaxSize())
|
||||
}
|
||||
}
|
||||
}
|
||||
// A settled pager (tab tap or swipe) reports the section up. Keyed only on the
|
||||
// pager so it is never restarted; the callback is read through a fresh state.
|
||||
val report by rememberUpdatedState(onSelect)
|
||||
LaunchedEffect(pagerState) {
|
||||
snapshotFlow { pagerState.settledPage }
|
||||
.distinctUntilChanged()
|
||||
.collect { report(it) }
|
||||
}
|
||||
|
||||
val page: @Composable (Int) -> Unit = { index ->
|
||||
content(tabs[clampTabIndex(index, tabs.size)], Modifier.fillMaxSize())
|
||||
}
|
||||
|
||||
if (wide) {
|
||||
Row(modifier.fillMaxSize()) {
|
||||
@@ -158,9 +153,7 @@ fun DetailTabs(
|
||||
}
|
||||
VerticalDivider()
|
||||
Box(Modifier.weight(1f).fillMaxHeight()) {
|
||||
HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { index ->
|
||||
page(index)
|
||||
}
|
||||
swap(Modifier.fillMaxSize())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -174,12 +167,7 @@ fun DetailTabs(
|
||||
)
|
||||
}
|
||||
}
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
modifier = Modifier.weight(1f).fillMaxWidth(),
|
||||
) { index ->
|
||||
page(index)
|
||||
}
|
||||
swap(Modifier.weight(1f).fillMaxWidth())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,5 +270,8 @@ fun rememberSectionExpansion(vararg inputs: Any?): SectionExpansionState {
|
||||
/** The always-visible wide section rail's width (icons with labels). */
|
||||
private const val WIDE_RAIL_WIDTH_DP = 200
|
||||
|
||||
/** The in-place section swap's cross-fade duration in milliseconds (short). */
|
||||
private const val SECTION_SWAP_MILLIS = 180
|
||||
|
||||
/** Comfortable max text width for a tab body on a wide window. */
|
||||
const val DETAIL_MAX_WIDTH_DP = 840
|
||||
|
||||
@@ -118,7 +118,7 @@ fun PipelineDetailScreen(
|
||||
wide = wide,
|
||||
modifier = Modifier.padding(padding).fillMaxSize(),
|
||||
) { tab, contentModifier ->
|
||||
// The pager composes only the visible section's content.
|
||||
// Only the selected section's content is composed at rest.
|
||||
when (tab.key) {
|
||||
"summary" -> PipelineSummaryTab(detail, wide, contentModifier)
|
||||
"graph" -> PipelineGraphTab(
|
||||
|
||||
@@ -154,7 +154,7 @@ fun RunDetailScreen(
|
||||
wide = wide,
|
||||
modifier = Modifier.padding(padding).fillMaxSize(),
|
||||
) { tab, contentModifier ->
|
||||
// The pager composes only the visible section's content.
|
||||
// Only the selected section's content is composed at rest.
|
||||
when (tab.key) {
|
||||
"summary" -> RunSummaryTab(
|
||||
run = run,
|
||||
|
||||
Reference in New Issue
Block a user