Fix FAB animation
This commit is contained in:
1 parent
fb20f899e2
commit
082e05584a
5 files changed
+24
-7
No files matched your search
@@ -15,8 +15,10 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.SmallFloatingActionButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
@@ -39,8 +41,12 @@ fun FabLayout(
|
||||
expanded: Boolean,
|
||||
onExpandChanged: (Boolean) -> Unit,
|
||||
autoCancel: Boolean,
|
||||
showAddButton: Boolean = true,
|
||||
delayOnShow: Boolean = false,
|
||||
fabBuilder: FabBuilder.() -> Unit,
|
||||
) {
|
||||
var delayOnExpand by remember { mutableStateOf(hidden) }
|
||||
var delayOnHide by remember { mutableStateOf(expanded) }
|
||||
val secondaryFab = remember(fabBuilder) {
|
||||
buildList {
|
||||
fabBuilder { icon, action ->
|
||||
@@ -62,9 +68,9 @@ fun FabLayout(
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val appearState by animateFloatAsState(
|
||||
targetValue = if (hidden) 0f else 1f,
|
||||
animationSpec = tween(FAB_ANIMATE_TIME, if (hidden) 0 else FAB_ANIMATE_TIME),
|
||||
animationSpec = tween(FAB_ANIMATE_TIME, if (delayOnHide || !hidden && delayOnShow) FAB_ANIMATE_TIME else 0),
|
||||
label = "hiddenState",
|
||||
)
|
||||
) { delayOnExpand = hidden }
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize().navigationBarsPadding().padding(16.dp),
|
||||
contentAlignment = Alignment.BottomEnd,
|
||||
@@ -77,7 +83,11 @@ fun FabLayout(
|
||||
},
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
val animatedProgress by animateFloatMergePredictiveBackAsState(expanded, tween(FAB_ANIMATE_TIME)) {
|
||||
val animatedProgress by animateFloatMergePredictiveBackAsState(
|
||||
expanded,
|
||||
tween(FAB_ANIMATE_TIME, if (delayOnExpand) FAB_ANIMATE_TIME else 0),
|
||||
finishedListener = { delayOnHide = expanded },
|
||||
) {
|
||||
onExpandChanged(false)
|
||||
}
|
||||
FloatingActionButton(
|
||||
@@ -86,8 +96,12 @@ fun FabLayout(
|
||||
Icon(
|
||||
imageVector = Icons.Default.Close,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.graphicsLayer {
|
||||
rotationZ = lerp(0f, -135f, animatedProgress)
|
||||
modifier = if (showAddButton) {
|
||||
Modifier.graphicsLayer {
|
||||
rotationZ = lerp(0f, -135f, animatedProgress)
|
||||
}
|
||||
} else {
|
||||
Modifier
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -497,6 +497,7 @@ fun DownloadsScreen(navigator: DestinationsNavigator) {
|
||||
selectMode = false
|
||||
},
|
||||
autoCancel = false,
|
||||
showAddButton = false,
|
||||
) {
|
||||
onClick(Icons.Default.DoneAll) {
|
||||
val info = list.associateBy { it.gid }
|
||||
|
||||
@@ -321,6 +321,7 @@ fun FavouritesScreen(navigator: DestinationsNavigator) {
|
||||
selectMode = false
|
||||
},
|
||||
autoCancel = !selectMode,
|
||||
delayOnShow = true,
|
||||
) {
|
||||
if (!select) {
|
||||
onClick(EhIcons.Default.GoTo) {
|
||||
|
||||
@@ -813,6 +813,7 @@ fun GalleryListScreen(lub: ListUrlBuilder, navigator: DestinationsNavigator) {
|
||||
expanded = expanded,
|
||||
onExpandChanged = { expanded = it },
|
||||
autoCancel = true,
|
||||
delayOnShow = true,
|
||||
) {
|
||||
onClick(Icons.Default.Refresh) {
|
||||
urlBuilder.setIndex(null)
|
||||
|
||||
@@ -250,8 +250,8 @@ fun SearchBarScreen(
|
||||
},
|
||||
floatingActionButton = {
|
||||
val hiddenState by animateFloatAsState(
|
||||
targetValue = if (showSearchFab) 1f else 0f,
|
||||
animationSpec = tween(FAB_ANIMATE_TIME, if (showSearchFab) FAB_ANIMATE_TIME else 0),
|
||||
targetValue = if (showSearchFab && !active) 1f else 0f,
|
||||
animationSpec = tween(FAB_ANIMATE_TIME, if (showSearchFab && !active) FAB_ANIMATE_TIME else 0),
|
||||
label = "hiddenState",
|
||||
)
|
||||
FloatingActionButton(
|
||||
|
||||
Reference in new issue
Block a user