[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-android] 11/14: [wallet] fix: AmountInputField reacts to ex
From: |
gnunet |
Subject: |
[taler-taler-android] 11/14: [wallet] fix: AmountInputField reacts to external changes |
Date: |
Tue, 26 Sep 2023 18:31:31 +0200 |
This is an automated email from the git hooks/post-receive script.
torsten-grote pushed a commit to branch master
in repository taler-android.
commit 1624b995729c4232a6945d359ec7f089866d2a15
Author: Iván Ávalos <avalos@disroot.org>
AuthorDate: Fri Sep 15 12:22:09 2023 -0600
[wallet] fix: AmountInputField reacts to external changes
---
.../net/taler/wallet/compose/AmountInputField.kt | 35 ++++++++++++++++++++--
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/wallet/src/main/java/net/taler/wallet/compose/AmountInputField.kt
b/wallet/src/main/java/net/taler/wallet/compose/AmountInputField.kt
index a9503d7..9abc03d 100644
--- a/wallet/src/main/java/net/taler/wallet/compose/AmountInputField.kt
+++ b/wallet/src/main/java/net/taler/wallet/compose/AmountInputField.kt
@@ -17,11 +17,14 @@
package net.taler.wallet.compose
import androidx.compose.foundation.interaction.MutableInteractionSource
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldColors
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
@@ -38,6 +41,8 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TransformedText
import androidx.compose.ui.text.input.VisualTransformation
+import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.unit.dp
import net.taler.common.Amount
import java.text.DecimalFormat
@@ -62,13 +67,22 @@ fun AmountInputField(
colors: TextFieldColors = TextFieldDefaults.outlinedTextFieldColors()
) {
val decimalSeparator =
DecimalFormat().decimalFormatSymbols.decimalSeparator
- var intermediate by remember { mutableStateOf(value) }
+ var tmpIn by remember { mutableStateOf(value) }
+
+ // React to external changes
+ val tmpOut = remember(tmpIn, value) {
+ transformOutput(tmpIn, decimalSeparator, '.').let {
+ if (value != it) value else tmpIn
+ }
+ }
+
OutlinedTextField(
- value = intermediate,
+ value = tmpOut,
onValueChange = { input ->
val filtered = transformOutput(input, decimalSeparator, '.')
if (Amount.isValidAmountStr(filtered)) {
- intermediate = transformInput(input, decimalSeparator, '.')
+ tmpIn = transformInput(input, decimalSeparator, '.')
+ // tmpIn = input
onValueChange(filtered)
}
},
@@ -143,4 +157,19 @@ private fun transformOutput(
it.endsWith(outputDecimalSeparator) -> "${it}0"
else -> it
}
+}
+
+@Preview
+@Composable
+fun AmountInputFieldPreview() {
+ var value by remember { mutableStateOf("0") }
+ TalerSurface {
+ Column {
+ Text(modifier = Modifier.padding(16.dp), text = value)
+ AmountInputField(
+ value = value,
+ onValueChange = { value = it },
+ )
+ }
+ }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-android] branch master updated (d7196a0 -> e7e2763), gnunet, 2023/09/26
- [taler-taler-android] 03/14: [wallet] first cleanup of payment template work, gnunet, 2023/09/26
- [taler-taler-android] 01/14: [wallet] Initial version of template support, gnunet, 2023/09/26
- [taler-taler-android] 10/14: [wallet] Improved AmountInputField with a VisualTransformation, gnunet, 2023/09/26
- [taler-taler-android] 11/14: [wallet] fix: AmountInputField reacts to external changes,
gnunet <=
- [taler-taler-android] 05/14: [wallet] add some potential TODOs for pay templates, gnunet, 2023/09/26
- [taler-taler-android] 09/14: [wallet] Support 0.x fractions in AmountInputField, gnunet, 2023/09/26
- [taler-taler-android] 04/14: [wallet] Improve internal logic of templates, gnunet, 2023/09/26
- [taler-taler-android] 08/14: [wallet] Refactor amount input into single composable, gnunet, 2023/09/26
- [taler-taler-android] 02/14: [wallet] Improved templates UX and PoS confirmation codes, gnunet, 2023/09/26
- [taler-taler-android] 14/14: [wallet] Fix back navigation after template prompt., gnunet, 2023/09/26
- [taler-taler-android] 13/14: [wallet] simplify pay templates, gnunet, 2023/09/26
- [taler-taler-android] 12/14: [wallet] simplify AmountInputField, gnunet, 2023/09/26
- [taler-taler-android] 06/14: [wallet] Additional refactoring of pay templates, gnunet, 2023/09/26
- [taler-taler-android] 07/14: [wallet] fixes for templates parsing and UI, gnunet, 2023/09/26