gnunet-svn
[Top][All Lists]
Advanced

[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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]