Skip to content

Commit 6518a40

Browse files
committed
Made the animation look smoother by making the highlighting box and falling letter fade out.
1 parent 3808d20 commit 6518a40

File tree

1 file changed

+24
-4
lines changed
  • app/src/main/java/com/dessalines/thumbkey/ui/components/keyboard

1 file changed

+24
-4
lines changed

app/src/main/java/com/dessalines/thumbkey/ui/components/keyboard/KeyboardKey.kt

+24-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package com.dessalines.thumbkey.ui.components.keyboard
22
import android.content.Context
33
import android.media.AudioManager
44
import androidx.compose.animation.AnimatedVisibility
5+
import androidx.compose.animation.EnterTransition
56
import androidx.compose.animation.ExitTransition
67
import androidx.compose.animation.core.tween
8+
import androidx.compose.animation.fadeOut
79
import androidx.compose.animation.slideInVertically
810
import androidx.compose.foundation.background
911
import androidx.compose.foundation.clickable
@@ -29,6 +31,7 @@ import androidx.compose.runtime.rememberCoroutineScope
2931
import androidx.compose.runtime.setValue
3032
import androidx.compose.ui.Alignment
3133
import androidx.compose.ui.Modifier
34+
import androidx.compose.ui.graphics.Color
3235
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
3336
import androidx.compose.ui.input.pointer.pointerInput
3437
import androidx.compose.ui.platform.LocalContext
@@ -291,14 +294,31 @@ fun KeyboardKey(
291294
KeyText(it, keySizeDp, hideLetters, capsLock)
292295
}
293296
}
294-
// The popup overlay
297+
298+
// The animated box that fades out.
299+
AnimatedVisibility(
300+
modifier = Modifier
301+
.fillMaxSize()
302+
.background(color = Color(0, 0, 0, 0)),
303+
visible = releasedKey.value != null,
304+
enter = EnterTransition.None,
305+
exit = fadeOut( tween(animationSpeed) )
306+
) {
307+
Box(
308+
contentAlignment = Alignment.Center,
309+
modifier = Modifier.fillMaxSize()
310+
.background(color = MaterialTheme.colorScheme.tertiaryContainer)
311+
) {}
312+
}
313+
314+
// The animated key letter that falls downwards and then fades out.
295315
AnimatedVisibility(
296316
modifier = Modifier
297317
.fillMaxSize()
298-
.background(color = MaterialTheme.colorScheme.tertiaryContainer),
318+
.background(color = Color(0, 0, 0, 0)),
299319
visible = releasedKey.value != null,
300-
enter = slideInVertically(tween(animationSpeed)),
301-
exit = ExitTransition.None
320+
enter = slideInVertically( tween(animationSpeed) ),
321+
exit = fadeOut( tween(animationSpeed) )
302322
) {
303323
Box(
304324
contentAlignment = Alignment.Center,

0 commit comments

Comments
 (0)