mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-28 05:00:30 +02:00
Free focus on drag start
This commit is contained in:
parent
d6f8d2e912
commit
f1f1b7841e
@ -56,6 +56,7 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.layout.onPlaced
|
import androidx.compose.ui.layout.onPlaced
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.TextRange
|
import androidx.compose.ui.text.TextRange
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
@ -114,6 +115,7 @@ private fun CalculatorScreen(
|
|||||||
evaluate: () -> Unit,
|
evaluate: () -> Unit,
|
||||||
clearHistory: () -> Unit
|
clearHistory: () -> Unit
|
||||||
) {
|
) {
|
||||||
|
val focusManager = LocalFocusManager.current
|
||||||
val dragAmount = remember { Animatable(0f) }
|
val dragAmount = remember { Animatable(0f) }
|
||||||
val dragCoroutineScope = rememberCoroutineScope()
|
val dragCoroutineScope = rememberCoroutineScope()
|
||||||
val dragAnimSpec = rememberSplineBasedDecay<Float>()
|
val dragAnimSpec = rememberSplineBasedDecay<Float>()
|
||||||
@ -183,6 +185,10 @@ private fun CalculatorScreen(
|
|||||||
dragAmount.snapTo(draggedAmount)
|
dragAmount.snapTo(draggedAmount)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onDragStarted = {
|
||||||
|
// Moving composables with focus causes performance drop
|
||||||
|
focusManager.clearFocus(true)
|
||||||
|
},
|
||||||
onDragStopped = { velocity ->
|
onDragStopped = { velocity ->
|
||||||
dragCoroutineScope.launch {
|
dragCoroutineScope.launch {
|
||||||
dragAmount.animateDecay(velocity, dragAnimSpec)
|
dragAmount.animateDecay(velocity, dragAnimSpec)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user