Implemented saving Image Tan width

This commit is contained in:
dankito 2020-08-30 17:02:13 +02:00
parent 5a06305171
commit d3386217b9
1 changed files with 12 additions and 2 deletions

View File

@ -4,11 +4,14 @@ import BankingUiSwift
struct ImageTanView: View { struct ImageTanView: View {
private static let ImageTanWidthDefaultsKey = "ImageTanWidth"
private var tanChallenge: ImageTanChallenge private var tanChallenge: ImageTanChallenge
private var imageData: Data 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) { init(_ tanChallenge: ImageTanChallenge) {
@ -20,7 +23,7 @@ struct ImageTanView: View {
var body: some View { var body: some View {
Section { Section {
ScaleImageView($imageWidth) ScaleImageView($imageWidth.didSet(self.imageWidthDidChange))
HStack { HStack {
Spacer() 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)
}
}
} }