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