Код: Выделить всё
HorizontalPager(
state = pagerState,
modifier = Modifier
.fillMaxSize(),
beyondViewportPageCount = 1,
flingBehavior = PagerDefaults.flingBehavior(
state = pagerState,
snapAnimationSpec = spring(
stiffness = Spring.StiffnessVeryLow,
visibilityThreshold = 3f
),
),
){
// pages
}
Код: Выделить всё
pagerState.animateScrollToPage(
page = currentPageIndex.intValue + 1,
animationSpec = spring(
stiffness = Spring.StiffnessVeryLow,
visibilityThreshold = 3f
)
)
почему и как это исправить?
p/s: это код, который я нашел в Pager API:
Код: Выделить всё
@Composable
fun flingBehavior(
state: PagerState,
pagerSnapDistance: PagerSnapDistance = PagerSnapDistance.atMost(1),
decayAnimationSpec: DecayAnimationSpec = rememberSplineBasedDecay(),
snapAnimationSpec: AnimationSpec = spring(
stiffness = Spring.StiffnessMediumLow,
visibilityThreshold = Int.VisibilityThreshold.toFloat()
),
@FloatRange(from = 0.0, to = 1.0) snapPositionalThreshold: Float = 0.5f
): TargetedFlingBehavior {
require(snapPositionalThreshold in 0f..1f) {
"snapPositionalThreshold should be a number between 0 and 1. " +
"You've specified $snapPositionalThreshold"
}
val density = LocalDensity.current
val layoutDirection = LocalLayoutDirection.current
return remember(
state,
decayAnimationSpec,
snapAnimationSpec,
pagerSnapDistance,
density,
layoutDirection
) {
val snapLayoutInfoProvider =
SnapLayoutInfoProvider(
state,
pagerSnapDistance
) { flingVelocity, lowerBound, upperBound ->
calculateFinalSnappingBound(
pagerState = state,
layoutDirection = layoutDirection,
snapPositionalThreshold = snapPositionalThreshold,
flingVelocity = flingVelocity,
lowerBoundOffset = lowerBound,
upperBoundOffset = upperBound
)
}
snapFlingBehavior(
snapLayoutInfoProvider = snapLayoutInfoProvider,
decayAnimationSpec = decayAnimationSpec,
snapAnimationSpec = snapAnimationSpec
)
}
}
Код: Выделить всё
snapAnimationSpec: AnimationSpec = spring(
stiffness = Spring.StiffnessMediumLow,
visibilityThreshold = Int.VisibilityThreshold.toFloat()
),
Подробнее здесь: https://stackoverflow.com/questions/791 ... ck-compose
Мобильная версия