gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ios] 08/28: Binding+onChange


From: gnunet
Subject: [taler-taler-ios] 08/28: Binding+onChange
Date: Tue, 19 Sep 2023 03:44:27 +0200

This is an automated email from the git hooks/post-receive script.

marc-stibane pushed a commit to branch master
in repository taler-ios.

commit 112dfefb7ff7ecf7e30ba30a12888e38f074df8d
Author: Marc Stibane <marc@taler.net>
AuthorDate: Sun Sep 10 11:29:47 2023 +0200

    Binding+onChange
---
 TalerWallet.xcodeproj/project.pbxproj          |  6 ++++
 TalerWallet1/Helper/Binding+onChange.swift     | 45 ++++++++++++++++++++++++++
 TalerWallet1/Views/Settings/SettingsView.swift |  8 ++---
 3 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/TalerWallet.xcodeproj/project.pbxproj 
b/TalerWallet.xcodeproj/project.pbxproj
index 5db6e29..fcfd4c9 100644
--- a/TalerWallet.xcodeproj/project.pbxproj
+++ b/TalerWallet.xcodeproj/project.pbxproj
@@ -130,6 +130,8 @@
                4E3EAEA32AA12582009F1BE8 /* Nunito-Italic.ttf in Resources */ = 
{isa = PBXBuildFile; fileRef = 4E3EAEA02AA12582009F1BE8 /* Nunito-Italic.ttf 
*/; };
                4E3EAEA42AA12582009F1BE8 /* Nunito-BoldItalic.ttf in Resources 
*/ = {isa = PBXBuildFile; fileRef = 4E3EAEA12AA12582009F1BE8 /* 
Nunito-BoldItalic.ttf */; };
                4E3EAEA52AA12582009F1BE8 /* Nunito-BoldItalic.ttf in Resources 
*/ = {isa = PBXBuildFile; fileRef = 4E3EAEA12AA12582009F1BE8 /* 
Nunito-BoldItalic.ttf */; };
+               4E3EAEA82AA70157009F1BE8 /* Binding+onChange.swift in Sources 
*/ = {isa = PBXBuildFile; fileRef = 4E3EAEA72AA70157009F1BE8 /* 
Binding+onChange.swift */; };
+               4E3EAEA92AA70157009F1BE8 /* Binding+onChange.swift in Sources 
*/ = {isa = PBXBuildFile; fileRef = 4E3EAEA72AA70157009F1BE8 /* 
Binding+onChange.swift */; };
                4E40E0BE29F25ABB00B85369 /* SendAmount.swift in Sources */ = 
{isa = PBXBuildFile; fileRef = 4E40E0BD29F25ABB00B85369 /* SendAmount.swift */; 
};
                4E50B3502A1BEE8000F9F01C /* ManualWithdraw.swift in Sources */ 
= {isa = PBXBuildFile; fileRef = 4E50B34F2A1BEE8000F9F01C /* 
ManualWithdraw.swift */; };
                4E53A33729F50B7B00830EC2 /* CurrencyField.swift in Sources */ = 
{isa = PBXBuildFile; fileRef = 4E53A33629F50B7B00830EC2 /* CurrencyField.swift 
*/; };
@@ -289,6 +291,7 @@
                4E3EAE9B2AA12467009F1BE8 /* Nunito-Bold.ttf */ = {isa = 
PBXFileReference; lastKnownFileType = file; path = "Nunito-Bold.ttf"; 
sourceTree = "<group>"; };
                4E3EAEA02AA12582009F1BE8 /* Nunito-Italic.ttf */ = {isa = 
PBXFileReference; lastKnownFileType = file; path = "Nunito-Italic.ttf"; 
sourceTree = "<group>"; };
                4E3EAEA12AA12582009F1BE8 /* Nunito-BoldItalic.ttf */ = {isa = 
PBXFileReference; lastKnownFileType = file; path = "Nunito-BoldItalic.ttf"; 
sourceTree = "<group>"; };
+               4E3EAEA72AA70157009F1BE8 /* Binding+onChange.swift */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path 
= "Binding+onChange.swift"; sourceTree = "<group>"; };
                4E40E0BD29F25ABB00B85369 /* SendAmount.swift */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path 
= SendAmount.swift; sourceTree = "<group>"; };
                4E50B34F2A1BEE8000F9F01C /* ManualWithdraw.swift */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path 
= ManualWithdraw.swift; sourceTree = "<group>"; };
                4E53A33629F50B7B00830EC2 /* CurrencyField.swift */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path 
= CurrencyField.swift; sourceTree = "<group>"; };
@@ -550,6 +553,7 @@
                                4E578E912A481D8600F21F1C /* 
Controller+playSound.swift */,
                                4EB095062989CB7C0043A8A1 /* TalerDater.swift */,
                                4EB095072989CB7C0043A8A1 /* TalerStrings.swift 
*/,
+                               4E3EAEA72AA70157009F1BE8 /* 
Binding+onChange.swift */,
                                4E3EAE8B2AA0933C009F1BE8 /* Font+Taler.swift */,
                                4EB095082989CB7C0043A8A1 /* 
View+dismissTop.swift */,
                                4E3B4BC62A429F2A00CC88B8 /* 
View+Notification.swift */,
@@ -1081,6 +1085,7 @@
                                4E3EAE722A990778009F1BE8 /* 
RequestPayment.swift in Sources */,
                                4E3EAE732A990778009F1BE8 /* SettingsItem.swift 
in Sources */,
                                4E3EAE742A990778009F1BE8 /* 
BalanceRowView.swift in Sources */,
+                               4E3EAEA82AA70157009F1BE8 /* 
Binding+onChange.swift in Sources */,
                                4E3EAE752A990778009F1BE8 /* DebugViewC.swift in 
Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
@@ -1178,6 +1183,7 @@
                                4E9320452A1645B600A87B0E /* 
RequestPayment.swift in Sources */,
                                4EB095502989CBFE0043A8A1 /* SettingsItem.swift 
in Sources */,
                                4EB0955C2989CBFE0043A8A1 /* 
BalanceRowView.swift in Sources */,
+                               4E3EAEA92AA70157009F1BE8 /* 
Binding+onChange.swift in Sources */,
                                4E753A062A0952F8002D9328 /* DebugViewC.swift in 
Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
diff --git a/TalerWallet1/Helper/Binding+onChange.swift 
b/TalerWallet1/Helper/Binding+onChange.swift
new file mode 100644
index 0000000..7bf8a5f
--- /dev/null
+++ b/TalerWallet1/Helper/Binding+onChange.swift
@@ -0,0 +1,45 @@
+//  MIT License
+//  Copyright © Paul Hudson
+//
+//  Permission is hereby granted, free of charge, to any person obtaining a 
copy of this software
+//  and associated documentation files (the "Software"), to deal in the 
Software without restriction,
+//  including without limitation the rights to use, copy, modify, merge, 
publish, distribute,
+//  sublicense, and/or sell copies of the Software, and to permit persons to 
whom the Software is
+//  furnished to do so, subject to the following conditions:
+//
+//  The above copyright notice and this permission notice shall be included in 
all copies or
+//  substantial portions of the Software.
+//
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING
+//  BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
PARTICULAR PURPOSE AND
+//  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
LIABLE FOR ANY CLAIM,
+//  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE, ARISING FROM,
+//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE SOFTWARE.
+//
+import SwiftUI
+
+/// Pass the handler directly to the Binding
+extension Binding {
+    func onChange(_ handler: @escaping (Value) -> Void) -> Binding<Value> {
+        Binding (
+            get: { self.wrappedValue },
+            set: { newValue in
+                self.wrappedValue = newValue
+                handler(newValue)
+            }
+        )
+    }
+}
+
+#if false
+// use like this:
+struct BindingView: View {
+    @State private var rating = 0.0
+    var body: some View {
+        Slider (value: $rating.onChange(sliderChanged))
+    }
+    func sliderChanged(_ value: Double) {
+        print ("Rating changed to \(value)")
+    }
+}
+#endif
diff --git a/TalerWallet1/Views/Settings/SettingsView.swift 
b/TalerWallet1/Views/Settings/SettingsView.swift
index 7dbbbee..2682302 100644
--- a/TalerWallet1/Views/Settings/SettingsView.swift
+++ b/TalerWallet1/Views/Settings/SettingsView.swift
@@ -104,12 +104,10 @@ struct SettingsView: View {
                             SettingsItem(name: String(localized: "Pending 
Operations"),
                                   description: String(localized: "Exchange not 
yet ready...")) {}
                         }
-                        SettingsToggle(name: String(localized: "Set 2 seconds 
delay"), value: $developDelay,
+                        SettingsToggle(name: String(localized: "Set 2 seconds 
delay"),
+                                      value: $developDelay.onChange({ delay in
+                                        walletCore.developDelay = delay}),
                                 description: String(localized: "After each 
wallet-core action"))
-                        .onChange(of: developDelay, perform: { developDelay in
-                            walletCore.developDelay = developDelay
-                        })
-
                         SettingsItem(name: String(localized: "Withdraw 
\(DEMOCURRENCY)"),
                               description: String(localized: "Get money for 
testing")) {
                             Button("Withdraw") {

-- 
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]