-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved the keyboard actions for text fields, making them more user-friendly. Started working on entry animations for FABs to provide a better user experience. Added some small code improvements to enhance overall code quality.
- Loading branch information
Mihai-Cristian Condrea
committed
Nov 23, 2024
1 parent
70e530f
commit 69bee4b
Showing
10 changed files
with
73 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 32 additions & 43 deletions
75
app/src/main/kotlin/com/d4rk/cartcalculator/ui/components/FloatingActionButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,52 @@ | ||
package com.d4rk.cartcalculator.ui.components | ||
|
||
import androidx.compose.animation.core.AnimationSpec | ||
import androidx.compose.animation.core.FastOutSlowInEasing | ||
import androidx.compose.animation.core.animateFloatAsState | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.material3.ExtendedFloatingActionButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.SideEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.graphicsLayer | ||
import com.d4rk.cartcalculator.ui.components.animations.bounceClick | ||
|
||
@Composable | ||
fun AnimatedExtendedFloatingActionButton( | ||
visible: Boolean = true, | ||
onClick: () -> Unit, | ||
icon: @Composable () -> Unit, | ||
text: (@Composable () -> Unit)? = null, | ||
) { | ||
var isInitiallyVisible by rememberSaveable { mutableStateOf(false) } | ||
|
||
SideEffect { | ||
if (!isInitiallyVisible) { | ||
isInitiallyVisible = true | ||
} | ||
} | ||
|
||
val animationSpec = tween<Float>( | ||
durationMillis = 300, delayMillis = 0, easing = FastOutSlowInEasing | ||
visible : Boolean = true , | ||
onClick : () -> Unit , | ||
icon : @Composable () -> Unit , | ||
text : (@Composable () -> Unit)? = null , | ||
offsetX : Float = 50f , | ||
offsetY : Float = 50f , | ||
scale : Float = 0.8f , | ||
animationSpec : AnimationSpec<Float> = tween( | ||
durationMillis = 300 , easing = FastOutSlowInEasing | ||
) | ||
|
||
val alpha by animateFloatAsState( | ||
targetValue = if (visible) 1f else 0f, animationSpec = animationSpec, label = "Alpha" | ||
) | ||
val offsetX by animateFloatAsState( | ||
targetValue = if (visible) 0f else 50f, animationSpec = animationSpec, label = "OffsetX" | ||
) { | ||
val animatedOffsetX by animateFloatAsState( | ||
targetValue = if (visible) 0f else offsetX , | ||
animationSpec = animationSpec , | ||
label = "OffsetX" | ||
) | ||
val offsetY by animateFloatAsState( | ||
targetValue = if (visible) 0f else 50f, animationSpec = animationSpec, label = "OffsetY" | ||
val animatedOffsetY by animateFloatAsState( | ||
targetValue = if (visible) 0f else offsetY , | ||
animationSpec = animationSpec , | ||
label = "OffsetY" | ||
) | ||
val scale by animateFloatAsState( | ||
targetValue = if (visible) 1f else 0.8f, animationSpec = animationSpec, label = "Scale" | ||
val animatedScale by animateFloatAsState( | ||
targetValue = if (visible) 1f else scale , animationSpec = animationSpec , label = "Scale" | ||
) | ||
|
||
ExtendedFloatingActionButton( | ||
onClick = onClick, | ||
icon = icon, | ||
text = text ?: {}, | ||
modifier = Modifier | ||
.bounceClick() | ||
.graphicsLayer { | ||
this.alpha = alpha | ||
this.translationX = offsetX | ||
this.translationY = offsetY | ||
this.scaleX = scale | ||
this.scaleY = scale | ||
} | ||
) | ||
ExtendedFloatingActionButton(onClick = onClick , | ||
icon = icon , | ||
text = text ?: {} , | ||
modifier = Modifier | ||
.bounceClick() | ||
.graphicsLayer { | ||
scaleX = animatedScale | ||
scaleY = animatedScale | ||
translationX = animatedOffsetX | ||
translationY = animatedOffsetY | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters