Temp changes to TabRow/TabPager
This commit is contained in:
parent
5319c4094b
commit
c5dbc08e84
3 changed files with 35 additions and 20 deletions
|
@ -21,11 +21,10 @@ import kotlin.math.absoluteValue
|
|||
|
||||
@Stable
|
||||
class TabPagerState(
|
||||
val pageCount: Int,
|
||||
val initialPageIndex: Int,
|
||||
val onPageChanged: ((Int) -> Unit)?
|
||||
pageIndexState: MutableState<Int>,
|
||||
val pageCount: Int
|
||||
) {
|
||||
var pageIndex by mutableStateOf(initialPageIndex)
|
||||
var pageIndex by pageIndexState
|
||||
|
||||
var tempPageIndex by mutableStateOf<Int?>(null)
|
||||
|
||||
|
@ -42,14 +41,14 @@ class TabPagerState(
|
|||
if (newPageIndex > pageIndex) {
|
||||
animatable.animateTo(
|
||||
animatable.upperBound!!, tween(
|
||||
durationMillis = 300,
|
||||
durationMillis = 3000,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
)
|
||||
} else if (newPageIndex < pageIndex) {
|
||||
animatable.animateTo(
|
||||
animatable.lowerBound!!, tween(
|
||||
durationMillis = 300,
|
||||
durationMillis = 3000,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
)
|
||||
|
@ -58,17 +57,25 @@ class TabPagerState(
|
|||
pageIndex = newPageIndex
|
||||
animatable.snapTo(0f)
|
||||
tempPageIndex = null
|
||||
onPageChanged?.invoke(newPageIndex)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberTabPagerState(initialPageIndex: Int, pageCount: Int, onPageChanged: ((Int) -> Unit)? = null): TabPagerState {
|
||||
fun rememberTabPagerState(pageIndexState: MutableState<Int>, pageCount: Int): TabPagerState {
|
||||
return remember {
|
||||
TabPagerState(
|
||||
pageIndexState = pageIndexState,
|
||||
pageCount = pageCount,
|
||||
initialPageIndex = initialPageIndex,
|
||||
onPageChanged = onPageChanged
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberTabPagerState(initialPageIndex: Int, pageCount: Int): TabPagerState {
|
||||
return remember {
|
||||
TabPagerState(
|
||||
pageIndexState = mutableStateOf(initialPageIndex),
|
||||
pageCount = pageCount
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +132,6 @@ fun HorizontalTabPager(
|
|||
.plus(1)
|
||||
.coerceAtMost(state.pageCount - 1)
|
||||
state.animatable.snapTo(0f)
|
||||
state.onPageChanged?.invoke(state.pageIndex)
|
||||
}
|
||||
} else {
|
||||
state.animatable.animateTo(
|
||||
|
@ -137,7 +143,6 @@ fun HorizontalTabPager(
|
|||
.minus(1)
|
||||
.coerceAtLeast(0)
|
||||
state.animatable.snapTo(0f)
|
||||
state.onPageChanged?.invoke(state.pageIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package it.vfsfitvnm.vimusic.ui.components
|
||||
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.animateIntAsState
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.drawBehind
|
||||
|
@ -15,7 +17,10 @@ import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
|||
data class TabPosition(
|
||||
val left: Int,
|
||||
val width: Int
|
||||
)
|
||||
) {
|
||||
val center: Int
|
||||
get() = left + width / 2
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TabRow(
|
||||
|
@ -30,11 +35,19 @@ fun TabRow(
|
|||
}
|
||||
|
||||
val indicatorWidth by animateIntAsState(
|
||||
targetValue = (tabPositions?.getOrNull(tabPagerState.transitioningIndex)?.width ?: 0)
|
||||
targetValue = (tabPositions?.getOrNull(tabPagerState.transitioningIndex)?.width ?: 0),
|
||||
tween(
|
||||
durationMillis = 3000,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
)
|
||||
|
||||
val indicatorStart by animateIntAsState(
|
||||
targetValue = (tabPositions?.getOrNull(tabPagerState.transitioningIndex)?.left ?: 0)
|
||||
targetValue = (tabPositions?.getOrNull(tabPagerState.transitioningIndex)?.left ?: 0),
|
||||
tween(
|
||||
durationMillis = 3000,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
)
|
||||
|
||||
Layout(
|
||||
|
|
|
@ -131,15 +131,12 @@ fun HomeScreen() {
|
|||
host {
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
var homeScreenPageIndex by rememberPreference(homeScreenPageIndexKey, 0)
|
||||
val isFirstLaunch by rememberPreference(isFirstLaunchKey, true)
|
||||
|
||||
val tabPagerState = rememberTabPagerState(
|
||||
initialPageIndex = homeScreenPageIndex,
|
||||
pageIndexState = rememberPreference(homeScreenPageIndexKey, 0),
|
||||
pageCount = 4
|
||||
) {
|
||||
homeScreenPageIndex = it
|
||||
}
|
||||
)
|
||||
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val density = LocalDensity.current
|
||||
|
|
Loading…
Add table
Reference in a new issue