-
-
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
12bc776
commit 70e530f
Showing
14 changed files
with
248 additions
and
125 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
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
63 changes: 63 additions & 0 deletions
63
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.d4rk.cartcalculator.ui.components | ||
|
||
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 | ||
) | ||
|
||
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 offsetY by animateFloatAsState( | ||
targetValue = if (visible) 0f else 50f, animationSpec = animationSpec, label = "OffsetY" | ||
) | ||
val scale by animateFloatAsState( | ||
targetValue = if (visible) 1f else 0.8f, 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 | ||
} | ||
) | ||
} |
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
Oops, something went wrong.