Skip to content

Commit

Permalink
Adding bounce click. Not working yet. #298
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Feb 4, 2023
1 parent 57a2567 commit b2cc466
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.jerboa.ui.components.common

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.waitForUpOrCancellation
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput

enum class ButtonState { Pressed, Idle }

fun Modifier.bounceClick() = composed {
var buttonState
by remember { mutableStateOf(ButtonState.Idle) }
val scale by animateFloatAsState(
if (buttonState
== ButtonState.Pressed
) {
0.70f
} else {
1f
}
)
this.graphicsLayer {
scaleX = scale
scaleY = scale
}
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
onClick = { }
).pointerInput(buttonState) {
awaitPointerEventScope {
buttonState = if (buttonState == ButtonState.Pressed) {
waitForUpOrCancellation()
ButtonState.Idle
} else {
awaitFirstDown(false)
ButtonState.Pressed
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fun ActionBarButton(
val barMod = if (noClick) {
Modifier
} else {
Modifier.clickable(onClick = {
Modifier.bounceClick().clickable(onClick = {
if (account !== null) {
onClick()
} else {
Expand Down

0 comments on commit b2cc466

Please sign in to comment.