Действие при свайпе влево. Jetpack Compose, AndroidAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Действие при свайпе влево. Jetpack Compose, Android

Сообщение Anonymous »


I'm new to Android Development and working right now on my first "real project" (just trying to copy iPhone calculator). The question is how do I implement deletion on swipe to left side of a screen exactly as on iPhone?
Here I've tried already something, but the problem is that yeah the code works, but on one swipe it can delete multiple numbers and not just one. How do I fix it?

Код: Выделить всё

Box(
contentAlignment = Alignment.BottomEnd,
modifier = Modifier
.fillMaxWidth()
.height(340.dp)
.pointerInput(Unit) {
detectHorizontalDragGestures { change, dragAmount ->
val x = dragAmount
if (x < 0 && currentValue != "0" && !currentValue.contains("-") && currentValueOnlyWithNumbers.length == 1) {
currentValue = "0"
} else if (x < 0 && currentValue.contains("-") && currentValueOnlyWithNumbers.length == 1) {
currentValue = "0"
} else if (x < 0 && currentValueOnlyWithNumbers.length > 1) {
currentValue =
if (currentValue.contains(" ") && currentValue[currentValue.length - 2] == ' ') {
currentValue.dropLast(2)
} else {
currentValue.dropLast(1)
}
}
}
}
)


Источник: https://stackoverflow.com/questions/781 ... se-android
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»