Updated FAB animations
This commit is contained in:
1 parent
b02bb044a3
commit
c1de9ec1a9
3 files changed
+133
-135
No files matched your search
+1
-2
@@ -130,8 +130,7 @@ fun AddAlbumScreen(
|
|||||||
onFolderClick = {
|
onFolderClick = {
|
||||||
selectionMode = false
|
selectionMode = false
|
||||||
folderPickerLauncher.launch(null)
|
folderPickerLauncher.launch(null)
|
||||||
},
|
}
|
||||||
animate = animate
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
+131
-131
@@ -1,9 +1,10 @@
|
|||||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||||
|
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
|
import androidx.compose.animation.AnimatedContent
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.animateContentSize
|
|
||||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||||
|
import androidx.compose.animation.core.LinearEasing
|
||||||
import androidx.compose.animation.core.Spring
|
import androidx.compose.animation.core.Spring
|
||||||
import androidx.compose.animation.core.animateDp
|
import androidx.compose.animation.core.animateDp
|
||||||
import androidx.compose.animation.core.spring
|
import androidx.compose.animation.core.spring
|
||||||
@@ -11,10 +12,14 @@ import androidx.compose.animation.core.tween
|
|||||||
import androidx.compose.animation.core.updateTransition
|
import androidx.compose.animation.core.updateTransition
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.animation.scaleIn
|
||||||
|
import androidx.compose.animation.scaleOut
|
||||||
|
import androidx.compose.animation.togetherWith
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
@@ -24,12 +29,13 @@ import androidx.compose.material.icons.filled.Add
|
|||||||
import androidx.compose.material.icons.filled.Folder
|
import androidx.compose.material.icons.filled.Folder
|
||||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||||
import androidx.compose.material.icons.filled.Remove
|
import androidx.compose.material.icons.filled.Remove
|
||||||
import androidx.compose.material3.CardColors
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.ElevatedCard
|
import androidx.compose.material3.ElevatedCard
|
||||||
|
import androidx.compose.material3.FloatingActionButtonDefaults
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.LargeFloatingActionButton
|
import androidx.compose.material3.LargeFloatingActionButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.surfaceColorAtElevation
|
import androidx.compose.material3.surfaceColorAtElevation
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@@ -38,12 +44,9 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.anthonyla.paperize.R
|
import com.anthonyla.paperize.R
|
||||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components.MenuRow
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Animated FAB that expands to show two options: Add image and Add folder
|
* Animated FAB that expands to show two options: Add image and Add folder
|
||||||
@@ -51,173 +54,170 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.comp
|
|||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun AddAlbumAnimatedFab(
|
fun AddAlbumAnimatedFab(
|
||||||
animate: Boolean,
|
|
||||||
onImageClick: () -> Unit,
|
onImageClick: () -> Unit,
|
||||||
onFolderClick: () -> Unit
|
onFolderClick: () -> Unit
|
||||||
) {
|
) {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
val expandedWidth = 165.dp
|
||||||
val fabTransition = updateTransition(targetState = expanded, label = "")
|
val itemSize = 2
|
||||||
|
val menuColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||||
|
val fabColor = MaterialTheme.colorScheme.primaryContainer
|
||||||
|
var isFabExpanded by remember { mutableStateOf(false) }
|
||||||
|
BackHandler(isFabExpanded) { isFabExpanded = false }
|
||||||
|
|
||||||
BackHandler(expanded) { expanded = false }
|
val fabTransition = updateTransition(targetState = isFabExpanded, label = "fabTransition")
|
||||||
|
|
||||||
val expandHorizontalSize = Pair(165.dp, 90.dp)
|
val expandFabHorizontally by fabTransition.animateDp(
|
||||||
val expandHorizontally by fabTransition.animateDp(
|
transitionSpec = {
|
||||||
transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow) }, label = "",
|
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
|
||||||
|
},
|
||||||
|
label = "expandVertically",
|
||||||
targetValueByState = {isExpanded ->
|
targetValueByState = {isExpanded ->
|
||||||
if (isExpanded) expandHorizontalSize.first else expandHorizontalSize.second
|
if (isExpanded) expandedWidth else 96.dp
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
val shrinkVerticalSize = Pair(50.dp, 90.dp)
|
val shrinkFabVertically by fabTransition.animateDp(
|
||||||
val shrinkVertically by fabTransition.animateDp(
|
transitionSpec = {
|
||||||
transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow) }, label = "",
|
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
|
||||||
|
},
|
||||||
|
label = "shrinkHorizontally",
|
||||||
targetValueByState = {isExpanded ->
|
targetValueByState = {isExpanded ->
|
||||||
if (isExpanded) shrinkVerticalSize.first else shrinkVerticalSize.second
|
if (isExpanded) 60.dp else 96.dp
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
val menuHeightSize = Pair(100.dp, 90.dp)
|
|
||||||
val menuHeight by fabTransition.animateDp(
|
val menuHeight by fabTransition.animateDp(
|
||||||
transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow) }, label = "",
|
transitionSpec = {
|
||||||
|
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
|
||||||
|
},
|
||||||
|
label = "menuHeight",
|
||||||
targetValueByState = {isExpanded ->
|
targetValueByState = {isExpanded ->
|
||||||
if (isExpanded) menuHeightSize.first else menuHeightSize.second
|
if (isExpanded) (itemSize * 50).dp else 0.dp
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (animate) {
|
|
||||||
ElevatedCard(
|
ElevatedCard(
|
||||||
colors = CardColors(
|
modifier = Modifier.padding(4.dp),
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
|
||||||
contentColor = Color.Transparent,
|
|
||||||
disabledContentColor = Color.Transparent,
|
|
||||||
disabledContainerColor = Color.Transparent,
|
|
||||||
),
|
|
||||||
shape = RoundedCornerShape(28.dp),
|
shape = RoundedCornerShape(28.dp),
|
||||||
modifier = Modifier
|
elevation = CardDefaults.elevatedCardElevation(4.dp),
|
||||||
.padding(4.dp)
|
colors = CardDefaults.elevatedCardColors().copy(
|
||||||
.width(expandHorizontally)
|
containerColor = menuColor
|
||||||
.pointerInput(Unit) {
|
)
|
||||||
detectTapGestures(onTap = { expanded = false })
|
) {
|
||||||
}
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.SpaceEvenly,
|
||||||
|
modifier = Modifier.height(menuHeight)
|
||||||
) {
|
) {
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = expanded,
|
visible = isFabExpanded,
|
||||||
enter = fadeIn(tween(300, 0, FastOutSlowInEasing)),
|
label = stringResource(R.string.add_images_btn),
|
||||||
exit = fadeOut(tween(300, 0, FastOutSlowInEasing)),
|
enter = fadeIn(tween(300, 150, LinearEasing)),
|
||||||
modifier = Modifier.animateContentSize(tween(50, 0, FastOutSlowInEasing)),
|
exit = fadeOut(tween(200, 50, LinearEasing)) + scaleOut(),
|
||||||
) {
|
|
||||||
Surface(tonalElevation = 5.dp) {
|
|
||||||
Column(modifier = Modifier.height(menuHeight)) {
|
|
||||||
MenuRow(
|
|
||||||
text = stringResource(R.string.add_images_btn),
|
|
||||||
icon = Icons.Filled.PhotoLibrary,
|
|
||||||
horizontalExpansion = expandHorizontally,
|
|
||||||
onClick = {
|
|
||||||
expanded = false
|
|
||||||
onImageClick()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
MenuRow(
|
|
||||||
text = stringResource(R.string.add_folder_btn),
|
|
||||||
icon = Icons.Filled.Folder,
|
|
||||||
horizontalExpansion = expandHorizontally,
|
|
||||||
onClick = {
|
|
||||||
expanded = false
|
|
||||||
onFolderClick()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Surface(
|
|
||||||
tonalElevation = 3.dp,
|
|
||||||
) {
|
|
||||||
LargeFloatingActionButton(
|
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
|
||||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
||||||
onClick = { expanded = !expanded },
|
|
||||||
modifier = Modifier
|
|
||||||
.width(expandHorizontally)
|
|
||||||
.height(shrinkVertically)
|
|
||||||
.animateContentSize(),
|
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.width(expandFabHorizontally)
|
||||||
|
.clickable {
|
||||||
|
onImageClick()
|
||||||
|
isFabExpanded = false
|
||||||
|
},
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
if (!expanded) Icons.Filled.Add else Icons.Filled.Remove,
|
imageVector = Icons.Filled.PhotoLibrary,
|
||||||
contentDescription = stringResource(R.string.add_wallpaper),
|
contentDescription = stringResource(R.string.add_images_btn),
|
||||||
modifier = Modifier.padding(16.dp),
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(start = 16.dp, top = 12.dp, bottom = 12.dp)
|
||||||
)
|
)
|
||||||
}
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
}
|
Text(
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ElevatedCard(
|
|
||||||
colors = CardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
|
||||||
contentColor = Color.Transparent,
|
|
||||||
disabledContentColor = Color.Transparent,
|
|
||||||
disabledContainerColor = Color.Transparent,
|
|
||||||
),
|
|
||||||
shape = RoundedCornerShape(28.dp),
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(4.dp)
|
|
||||||
.width(if (expanded) expandHorizontalSize.first else expandHorizontalSize.second)
|
|
||||||
.pointerInput(Unit) {
|
|
||||||
detectTapGestures(onTap = { expanded = false })
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
if (expanded) {
|
|
||||||
Surface(tonalElevation = 5.dp) {
|
|
||||||
Column(modifier = Modifier.height(if (expanded) menuHeightSize.first else menuHeightSize.second)) {
|
|
||||||
MenuRow(
|
|
||||||
text = stringResource(R.string.add_images_btn),
|
text = stringResource(R.string.add_images_btn),
|
||||||
icon = Icons.Filled.PhotoLibrary,
|
modifier = Modifier.padding(end = 16.dp, top = 12.dp, bottom = 12.dp),
|
||||||
horizontalExpansion = if (expanded) expandHorizontalSize.first else expandHorizontalSize.second,
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
onClick = {
|
color = MaterialTheme.colorScheme.onSurface
|
||||||
expanded = false
|
|
||||||
onImageClick()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
MenuRow(
|
|
||||||
text = stringResource(R.string.add_folder_btn),
|
|
||||||
icon = Icons.Filled.Folder,
|
|
||||||
horizontalExpansion = if (expanded) expandHorizontalSize.first else expandHorizontalSize.second,
|
|
||||||
onClick = {
|
|
||||||
expanded = false
|
|
||||||
onFolderClick()
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
AnimatedVisibility(
|
||||||
Surface(
|
visible = isFabExpanded,
|
||||||
tonalElevation = 3.dp,
|
label = stringResource(R.string.add_folder_btn),
|
||||||
) {
|
enter = fadeIn(tween(300, 150, LinearEasing)),
|
||||||
LargeFloatingActionButton(
|
exit = fadeOut(tween(200, 50, LinearEasing)) + scaleOut(),
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
|
||||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
||||||
onClick = { expanded = !expanded },
|
|
||||||
modifier = Modifier
|
|
||||||
.width(if (expanded) expandHorizontalSize.first else expandHorizontalSize.second)
|
|
||||||
.height(if (expanded) shrinkVerticalSize.first else shrinkVerticalSize.second)
|
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.width(expandFabHorizontally)
|
||||||
|
.clickable {
|
||||||
|
onFolderClick()
|
||||||
|
isFabExpanded = false
|
||||||
|
},
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
if (!expanded) Icons.Filled.Add else Icons.Filled.Remove,
|
imageVector = Icons.Filled.Folder,
|
||||||
contentDescription = stringResource(R.string.add_wallpaper),
|
contentDescription = stringResource(R.string.add_folder_btn),
|
||||||
modifier = Modifier.padding(16.dp),
|
modifier = Modifier.padding(start = 16.dp, top = 12.dp, bottom = 12.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.add_folder_btn),
|
||||||
|
modifier = Modifier.padding(end = 16.dp, top = 12.dp, bottom = 12.dp),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LargeFloatingActionButton(
|
||||||
|
elevation = FloatingActionButtonDefaults.elevation(4.dp),
|
||||||
|
shape = RoundedCornerShape(28),
|
||||||
|
containerColor = fabColor,
|
||||||
|
onClick = { isFabExpanded = !isFabExpanded },
|
||||||
|
modifier = Modifier
|
||||||
|
.width(expandFabHorizontally)
|
||||||
|
.height(shrinkFabVertically)
|
||||||
|
) {
|
||||||
|
AnimatedContent(
|
||||||
|
isFabExpanded,
|
||||||
|
transitionSpec = {
|
||||||
|
when (targetState) {
|
||||||
|
true -> {
|
||||||
|
(
|
||||||
|
scaleIn(
|
||||||
|
tween(100, 300, FastOutSlowInEasing)
|
||||||
|
) + fadeIn(
|
||||||
|
tween(250, 300, LinearEasing)
|
||||||
|
)
|
||||||
|
) .togetherWith(
|
||||||
|
fadeOut(
|
||||||
|
tween(10, 0, LinearEasing)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
false -> {
|
||||||
|
fadeIn(
|
||||||
|
tween(250, 200, FastOutSlowInEasing)
|
||||||
|
).togetherWith(
|
||||||
|
fadeOut(
|
||||||
|
tween(10, 0, LinearEasing),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
label = "FabContent"
|
||||||
|
) { isExpanded ->
|
||||||
|
Icon(
|
||||||
|
imageVector = if (isExpanded) Icons.Filled.Remove else Icons.Filled.Add,
|
||||||
|
contentDescription = stringResource(R.string.add_wallpaper),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-2
@@ -126,8 +126,7 @@ fun AlbumViewScreen(
|
|||||||
onFolderClick = {
|
onFolderClick = {
|
||||||
selectionMode = false
|
selectionMode = false
|
||||||
folderPickerLauncher.launch(null)
|
folderPickerLauncher.launch(null)
|
||||||
},
|
}
|
||||||
animate = animate
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
content = { it ->
|
content = { it ->
|
||||||
|
|||||||
Reference in new issue
Block a user