From d3386217b9b2a8669783aff3afbcf410aa002311 Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 30 Aug 2020 17:02:13 +0200 Subject: [PATCH] Implemented saving Image Tan width --- .../BankingiOSApp/ui/views/ImageTanView.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/ImageTanView.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/ImageTanView.swift index 5ba64832..0c516e00 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/ImageTanView.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/ImageTanView.swift @@ -4,11 +4,14 @@ import BankingUiSwift struct ImageTanView: View { + private static let ImageTanWidthDefaultsKey = "ImageTanWidth" + + private var tanChallenge: ImageTanChallenge private var imageData: Data - @State private var imageWidth: CGFloat = UIScreen.main.bounds.width / 2 + @State private var imageWidth = CGFloat(UserDefaults.standard.float(forKey: Self.ImageTanWidthDefaultsKey, defaultValue: Float(UIScreen.main.bounds.width / 2))) init(_ tanChallenge: ImageTanChallenge) { @@ -20,7 +23,7 @@ struct ImageTanView: View { var body: some View { Section { - ScaleImageView($imageWidth) + ScaleImageView($imageWidth.didSet(self.imageWidthDidChange)) HStack { Spacer() @@ -34,6 +37,13 @@ struct ImageTanView: View { } } + + private func imageWidthDidChange(oldValue: CGFloat?, newValue: CGFloat?) { + if let newValue = newValue { + UserDefaults.standard.set(newValue, forKey: Self.ImageTanWidthDefaultsKey) + } + } + }