aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Stibane <marc@taler.net>2023-10-15 23:11:50 +0200
committerMarc Stibane <marc@taler.net>2023-10-15 23:11:50 +0200
commitf46596353ba8c26a1112030499943c2b13398af5 (patch)
tree3b0d59721ceee8692cffab2165472f3361309d59
parent4fd028f803c537e9156a8452a2d310de8db0fdff (diff)
downloadtaler-ios-f46596353ba8c26a1112030499943c2b13398af5.tar.gz
taler-ios-f46596353ba8c26a1112030499943c2b13398af5.tar.bz2
taler-ios-f46596353ba8c26a1112030499943c2b13398af5.zip
SingleAxisGeometryReader
-rw-r--r--TalerWallet.xcodeproj/project.pbxproj6
-rw-r--r--TalerWallet1/Views/HelperViews/SingleAxisGeometryReader.swift52
2 files changed, 58 insertions, 0 deletions
diff --git a/TalerWallet.xcodeproj/project.pbxproj b/TalerWallet.xcodeproj/project.pbxproj
index d341f2b..a30ede5 100644
--- a/TalerWallet.xcodeproj/project.pbxproj
+++ b/TalerWallet.xcodeproj/project.pbxproj
@@ -167,6 +167,8 @@
4E9320452A1645B600A87B0E /* RequestPayment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E9320442A1645B600A87B0E /* RequestPayment.swift */; };
4E9320472A164BC700A87B0E /* PaymentPurpose.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E9320462A164BC700A87B0E /* PaymentPurpose.swift */; };
4E9796902A3765ED006F73BC /* AgePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E97968F2A3765ED006F73BC /* AgePicker.swift */; };
+ 4E983C292ADBDD3500FA9CC5 /* SingleAxisGeometryReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E983C282ADBDD3500FA9CC5 /* SingleAxisGeometryReader.swift */; };
+ 4E983C2A2ADBDD3500FA9CC5 /* SingleAxisGeometryReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E983C282ADBDD3500FA9CC5 /* SingleAxisGeometryReader.swift */; };
4EA1ABBE29A3833A008821EA /* PublicConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EA1ABBD29A3833A008821EA /* PublicConstants.swift */; };
4EA551252A2C923600FEC9A8 /* CurrencyInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EA551242A2C923600FEC9A8 /* CurrencyInputView.swift */; };
4EAD117629F672FA008EDD0B /* KeyboardResponder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EAD117529F672FA008EDD0B /* KeyboardResponder.swift */; };
@@ -333,6 +335,7 @@
4E9320442A1645B600A87B0E /* RequestPayment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestPayment.swift; sourceTree = "<group>"; };
4E9320462A164BC700A87B0E /* PaymentPurpose.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaymentPurpose.swift; sourceTree = "<group>"; };
4E97968F2A3765ED006F73BC /* AgePicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AgePicker.swift; sourceTree = "<group>"; };
+ 4E983C282ADBDD3500FA9CC5 /* SingleAxisGeometryReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleAxisGeometryReader.swift; sourceTree = "<group>"; };
4EA1ABBD29A3833A008821EA /* PublicConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicConstants.swift; sourceTree = "<group>"; };
4EA551242A2C923600FEC9A8 /* CurrencyInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyInputView.swift; sourceTree = "<group>"; };
4EAD117529F672FA008EDD0B /* KeyboardResponder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardResponder.swift; sourceTree = "<group>"; };
@@ -725,6 +728,7 @@
4EEC157229F8242800D46A03 /* QRGeneratorView.swift */,
4E5A88F42A38A4FD00072618 /* QRCodeDetailView.swift */,
4E6EDD862A363D8D0031D520 /* ListStyle.swift */,
+ 4E983C282ADBDD3500FA9CC5 /* SingleAxisGeometryReader.swift */,
4EB095482989CBFE0043A8A1 /* TextFieldAlert.swift */,
4EBA82AA2A3EB2CA00E5F39A /* TransactionButton.swift */,
4EB095492989CBFE0043A8A1 /* AmountView.swift */,
@@ -1081,6 +1085,7 @@
4E3EAE562A990778009F1BE8 /* LocalizedAlertError.swift in Sources */,
4E3EAE572A990778009F1BE8 /* quickjs.swift in Sources */,
4E3EAE582A990778009F1BE8 /* CurrencyField.swift in Sources */,
+ 4E983C292ADBDD3500FA9CC5 /* SingleAxisGeometryReader.swift in Sources */,
4E3EAE592A990778009F1BE8 /* Model+Settings.swift in Sources */,
4E3EAE5A2A990778009F1BE8 /* ErrorView.swift in Sources */,
4E3EAE5B2A990778009F1BE8 /* View+Notification.swift in Sources */,
@@ -1184,6 +1189,7 @@
4E363CC22A2621C200D7E98C /* LocalizedAlertError.swift in Sources */,
4EB0950E2989CB9A0043A8A1 /* quickjs.swift in Sources */,
4E53A33729F50B7B00830EC2 /* CurrencyField.swift in Sources */,
+ 4E983C2A2ADBDD3500FA9CC5 /* SingleAxisGeometryReader.swift in Sources */,
4EB095152989CBB00043A8A1 /* Model+Settings.swift in Sources */,
4EB095692989CBFE0043A8A1 /* ErrorView.swift in Sources */,
4E3B4BC72A429F2A00CC88B8 /* View+Notification.swift in Sources */,
diff --git a/TalerWallet1/Views/HelperViews/SingleAxisGeometryReader.swift b/TalerWallet1/Views/HelperViews/SingleAxisGeometryReader.swift
new file mode 100644
index 0000000..e30cb2a
--- /dev/null
+++ b/TalerWallet1/Views/HelperViews/SingleAxisGeometryReader.swift
@@ -0,0 +1,52 @@
+/* MIT License
+ * Copyright (c) 2020 Canis from @wooji
+ *
+ * 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
+import UIKit
+
+struct SingleAxisGeometryReader<Content: View>: View {
+
+ private struct SizeKey: PreferenceKey {
+ static var defaultValue: CGFloat { 10 }
+ static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
+ value = max(value, nextValue())
+ }
+ }
+
+ @State private var viewSize: CGFloat = SizeKey.defaultValue
+
+ var axis: Axis = .horizontal
+ var alignment: Alignment = .center
+ let content: (CGFloat)->Content
+
+ var body: some View {
+ content(viewSize)
+ .frame(maxWidth: axis == .horizontal ? .infinity : nil,
+ maxHeight: axis == .vertical ? .infinity : nil,
+ alignment: alignment)
+ .background(GeometryReader { proxy in
+ Color.clear.preference(key: SizeKey.self,
+ value: axis == .horizontal ? proxy.size.width
+ : proxy.size.height)
+ })
+ .onPreferenceChange(SizeKey.self) { viewSize = $0 }
+ }
+}