From 8f15bd25b39d71682e699c2f54f95a072349b535 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 4 Aug 2020 00:53:34 +0200 Subject: [PATCH] Implemented resizing TAN image --- .../Base.lproj/Localizable.strings | 1 + .../de.lproj/Localizable.strings | 1 + .../BankingiOSApp/ui/views/ImageTanView.swift | 49 ++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings b/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings index cd8c63f2..d24c50c7 100644 --- a/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings +++ b/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings @@ -65,6 +65,7 @@ "Enter TAN Dialog Title" = "Enter TAN"; "TAN procedure" = "TAN procedure"; "TAN medium" = "TAN medium"; +"Size" = "Size"; "TAN hint from your bank:" = "Hint from your bank:"; "Enter TAN:" = "TAN"; "Decoding error" = "Decoding error"; diff --git a/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings b/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings index ce966590..4d165264 100644 --- a/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings +++ b/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings @@ -65,6 +65,7 @@ "Enter TAN Dialog Title" = "TAN-Abfrage"; "TAN procedure" = "TAN Verfahren"; "TAN medium" = "TAN Medium"; +"Size" = "Größe"; "TAN hint from your bank:" = "Hinweis Ihrer Bank:"; "Enter TAN:" = "TAN"; "Decoding error" = "Dekodierungsfehler"; diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/ImageTanView.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/ImageTanView.swift index e931f7af..10090f5a 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/ImageTanView.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/ImageTanView.swift @@ -8,17 +8,64 @@ struct ImageTanView: View { private var imageData: Data + @State private var imageWidth: CGFloat + + private let imageMinWidth: CGFloat + + private let imageMaxWidth: CGFloat + + private let step: CGFloat + init(_ tanChallenge: ImageTanChallenge) { self.tanChallenge = tanChallenge self.imageData = tanChallenge.image.imageBytesAsNSData() + + let screenWidth = UIScreen.main.bounds.width + let screenWidthQuarter = screenWidth / 4 + + self.imageMinWidth = screenWidthQuarter < 150 ? 150 : screenWidthQuarter // don't know whey but iOS seems that it doesn't scale image smaller than 150 + self.imageMaxWidth = screenWidth + + let range = imageMaxWidth - imageMinWidth + + self._imageWidth = State(initialValue: imageMinWidth + range / 2) + + self.step = range / 20 } var body: some View { - UIKitImageView(data: self.imageData) + Section { + HStack { + Text("Size") + + Spacer() + + Rectangle() + .fill(Color.gray) + .frame(width: 6, height: 9) + + Slider(value: $imageWidth, in: imageMinWidth...imageMaxWidth, step: step) + + Rectangle() + .fill(Color.gray) + .frame(width: 16, height: 19) + } + + HStack { + Spacer() + + UIKitImageView(data: self.imageData) + .frame(width: imageWidth, height: imageWidth) + .padding(.horizontal, -32.0) + + Spacer() + } + } } + }