From 76c10b1f87e8df2a7b1d13d51419cca250f59dcb Mon Sep 17 00:00:00 2001 From: eapuzzo <44156733+eapuzzo@users.noreply.github.com> Date: Fri, 25 Mar 2022 10:43:35 +0100 Subject: [PATCH] fix: auto scroll small devices Co-authored-by: Johnny Bueti <29045904+Fehniix@users.noreply.github.com> --- .../CustomPicker/CustomPickerController.swift | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/DGCAVerifier/UIComponents/CustomControllers/CustomPicker/CustomPickerController.swift b/DGCAVerifier/UIComponents/CustomControllers/CustomPicker/CustomPickerController.swift index 0fc80f3..ae8e9f3 100644 --- a/DGCAVerifier/UIComponents/CustomControllers/CustomPicker/CustomPickerController.swift +++ b/DGCAVerifier/UIComponents/CustomControllers/CustomPicker/CustomPickerController.swift @@ -63,11 +63,10 @@ class CustomPickerController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - - guard let scanMode = ScanMode.fetchFromLocalSettings() else { return } - if (scanMode == .school) { - let yOffset = self.scrollView.contentLayoutGuide.layoutFrame.height - self.scrollView.frameLayoutGuide.layoutFrame.size.height - self.scrollView.setContentOffset(CGPoint(x: 0, y: yOffset), animated: true) + + let scrollOffset: Double = self.notVisibleOptionScrollOffset() + if (scrollOffset > 0) { + self.scrollView.setContentOffset(CGPoint(x: 0, y: scrollOffset), animated: true) } } @@ -111,6 +110,28 @@ class CustomPickerController: UIViewController { self.optionViews.filter{ $0.scanMode == scanMode }.first?.didSelect() } + private func notVisibleOptionScrollOffset() -> Double { + guard let scanMode: ScanMode = ScanMode.fetchFromLocalSettings() else { return 0.0 } + guard let selectedOptionIndex: Int = self.optionViews.enumerated().compactMap({ index, optionView in + optionView.scanMode == scanMode ? index : nil + }).first else { return 0.0 } + + // Select first non-selected option to determine the height of a non-selected option. + // A selected option spans an additional view containing the scan mode description. + var baseNotSelectedOptionHeight: Double = 0.0 + for index in 0.. Void { Store.get(key: .scanMode) == nil ? disableConfirmButton() : enableConfirmButton() }