diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Extensions/UIView.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Extensions/UIView.swift index db3f7f1cc..48bc6efd9 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Extensions/UIView.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Extensions/UIView.swift @@ -38,7 +38,7 @@ extension UIView { } extension UIView { - var currentInterfaceOrientation: UIInterfaceOrientation? { + var currentInterfaceOrientation: UIInterfaceOrientation { if #available(iOS 13, *) { return window?.windowScene?.interfaceOrientation ?? UIApplication.shared.statusBarOrientation } else { diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Extensions/UIViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Extensions/UIViewController.swift index e3160a78e..7b83c135e 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Extensions/UIViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Extensions/UIViewController.swift @@ -103,5 +103,5 @@ extension UIViewController { } extension UIViewController { - var currentInterfaceOrientation: UIInterfaceOrientation? { view.currentInterfaceOrientation } + var currentInterfaceOrientation: UIInterfaceOrientation { view.currentInterfaceOrientation } } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Analysis/AnalysisViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Analysis/AnalysisViewController.swift index f5bc6b0e9..547378900 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Analysis/AnalysisViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Analysis/AnalysisViewController.swift @@ -151,7 +151,7 @@ import UIKit public override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() if UIDevice.current.isIphone, document is GiniImageDocument { - let isLandscape = currentInterfaceOrientation?.isLandscape == true + let isLandscape = currentInterfaceOrientation.isLandscape centerYConstraint.constant = isLandscape ? -96 / 2 : 0 } } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Analysis/CaptureSuggestionsView.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Analysis/CaptureSuggestionsView.swift index 7ce7c1f8f..7524c28bc 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Analysis/CaptureSuggestionsView.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Analysis/CaptureSuggestionsView.swift @@ -91,7 +91,7 @@ final class CaptureSuggestionsView: UIView { override func layoutSubviews() { super.layoutSubviews() if UIDevice.current.isIphone { - let isLandscape = currentInterfaceOrientation?.isLandscape == true + let isLandscape = currentInterfaceOrientation.isLandscape let margin: CGFloat = isLandscape ? 56 : 20 leadingiPhondConstraint.constant = margin trailingiPhoneConstraint.constant = -margin diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Camera/CameraViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Camera/CameraViewController.swift index 8cee97d71..73ed9d2f3 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Camera/CameraViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Camera/CameraViewController.swift @@ -162,7 +162,7 @@ final class CameraViewController: UIViewController { } @objc private func configureCameraPanesBasedOnOrientation() { - if !UIDevice.current.isIpad, currentInterfaceOrientation?.isLandscape == true { + if !UIDevice.current.isIpad, currentInterfaceOrientation.isLandscape { if !cameraPane.isHidden { cameraPane.setupAuthorization(isHidden: true) cameraPaneHorizontal.setupAuthorization(isHidden: false) @@ -321,8 +321,8 @@ final class CameraViewController: UIViewController { } private func configureCameraPaneButtons() { - cameraPane.setupAuthorization(isHidden: !(currentInterfaceOrientation?.isPortrait == true)) - cameraPaneHorizontal?.setupAuthorization(isHidden: !(UIDevice.current.isIphone && currentInterfaceOrientation?.isLandscape == true)) + cameraPane.setupAuthorization(isHidden: !currentInterfaceOrientation.isPortrait) + cameraPaneHorizontal?.setupAuthorization(isHidden: !(UIDevice.current.isIphone && currentInterfaceOrientation.isLandscape)) configureLeftButtons() cameraButtonsViewModel.captureAction = { [weak self] in self?.sendGiniAnalyticsEventCapture() @@ -721,8 +721,8 @@ extension CameraViewController: CameraPreviewViewControllerDelegate { cameraPreviewViewController.updatePreviewViewOrientation() UIView.animate(withDuration: 1.0) { - self.cameraPane.setupAuthorization(isHidden: !(self.currentInterfaceOrientation?.isPortrait == true)) - self.cameraPaneHorizontal?.setupAuthorization(isHidden: !(UIDevice.current.isIphone && self.currentInterfaceOrientation?.isLandscape == true)) + self.cameraPane.setupAuthorization(isHidden: !(UIDevice.current.isIpad || self.currentInterfaceOrientation.isPortrait)) + self.cameraPaneHorizontal?.setupAuthorization(isHidden: !(UIDevice.current.isIphone && self.currentInterfaceOrientation.isLandscape)) self.cameraPreviewViewController.previewView.alpha = 1 } } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/CameraPreviewViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/CameraPreviewViewController.swift index a53c9aa06..b85f5bb23 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/CameraPreviewViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/CameraPreviewViewController.swift @@ -57,14 +57,6 @@ final class CameraPreviewViewController: UIViewController { imageView.isHidden = true return imageView }() - private let cameraFocusHorizontalImage = UIImageNamedPreferred(named: "cameraFocusHorizontal") - lazy var cameraFrameViewHorizontal: UIImageView = { - let imageView = UIImageView() - imageView.image = cameraFocusHorizontalImage - imageView.contentMode = .scaleAspectFit - imageView.isHidden = true - return imageView - }() lazy var qrCodeFrameView: UIImageView = { let imageView = UIImageView() @@ -142,7 +134,6 @@ final class CameraPreviewViewController: UIViewController { view.insertSubview(previewView, at: 0) view.addSubview(qrCodeFrameView) view.addSubview(cameraFrameView) - view.addSubview(cameraFrameViewHorizontal) addLoadingIndicator() } @@ -182,12 +173,6 @@ final class CameraPreviewViewController: UIViewController { // videoPreviewLayer - used to translate detected IBANs bounding boxes to videoPreviewLayer frame coordinate system // visionToAVFTransform - transform Vision coordinate into AVF coordinate - let isIphone = UIDevice.current.isIphone - let isLandscape = currentInterfaceOrientation?.isLandscape == true -// cameraFrameViewHorizontal.isHidden = !isIphone || !isLandscape -// cameraFrameView.isHidden = isIphone && isLandscape - let frameView = isIphone && isLandscape ? cameraFrameViewHorizontal : cameraFrameView - if cameraFrameView.frame != CGRect.zero && previewView.frame != CGRect.zero { camera.setupIBANDetection(textOrientation: textOrientation, regionOfInterest: cameraFrameView.frame, @@ -210,7 +195,6 @@ final class CameraPreviewViewController: UIViewController { private func setupConstraints() { cameraFrameView.translatesAutoresizingMaskIntoConstraints = false -// cameraFrameViewHorizontal.translatesAutoresizingMaskIntoConstraints = false qrCodeFrameView.translatesAutoresizingMaskIntoConstraints = false if UIDevice.current.isIpad { @@ -233,18 +217,7 @@ final class CameraPreviewViewController: UIViewController { constant: Constants.padding), cameraFrameView.centerXAnchor.constraint(equalTo: view.centerXAnchor), cameraFrameViewBottomConstrant, -// cameraFrameView.widthAnchor.constraint(equalTo: cameraFrameView.heightAnchor, -// multiplier: 1 / Constants.a4AspectRatio), cameraFrameViewHeightAnchorPortrait - -// cameraFrameViewHorizontal.topAnchor.constraint(equalTo: view.topAnchor, constant: Constants.padding), -// cameraFrameViewHorizontal.leadingAnchor.constraint(greaterThanOrEqualTo: view.leadingAnchor, -// constant: Constants.padding), -// cameraFrameViewHorizontal.centerXAnchor.constraint(equalTo: view.centerXAnchor), -// cameraFrameViewHorizontal.bottomAnchor.constraint(lessThanOrEqualTo: view.bottomAnchor, -// constant: -bottomControlHeight-Constants.padding), -// cameraFrameViewHorizontal.widthAnchor.constraint(equalTo: cameraFrameView.heightAnchor, -// multiplier: Constants.a4AspectRatio) ]) } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/CameraBottomNavigationBar.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/CameraBottomNavigationBar.swift index 30e6f031d..18847ae1b 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/CameraBottomNavigationBar.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/CameraBottomNavigationBar.swift @@ -25,7 +25,7 @@ class CameraBottomNavigationBar: UIView { override func layoutSubviews() { super.layoutSubviews() - heightConstraint.constant = currentInterfaceOrientation?.isLandscape == true ? 62 : 114 + heightConstraint.constant = currentInterfaceOrientation.isLandscape ? 62 : 114 } func setupView() { diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/CameraNotAuthorizedView.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/CameraNotAuthorizedView.swift index f5bdaec18..6a8ef92f7 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/CameraNotAuthorizedView.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/CameraNotAuthorizedView.swift @@ -85,7 +85,7 @@ final class CameraNotAuthorizedView: UIView { override func layoutSubviews() { super.layoutSubviews() - let isLandscape = currentInterfaceOrientation?.isLandscape == true + let isLandscape = currentInterfaceOrientation.isLandscape descriptionWidthConstraint?.isActive = !isLandscape descriptionWidthLandscapeConstraint?.isActive = isLandscape } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/QRCodeOverlay.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/QRCodeOverlay.swift index d7d8e2b5f..45666b8ed 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/QRCodeOverlay.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Camera/Views/QRCodeOverlay.swift @@ -112,6 +112,8 @@ final class QRCodeOverlay: UIView { return view }() + private var incorrectQRTrailingConstraint: NSLayoutConstraint? + private var incorrectQRWidthConstraint: NSLayoutConstraint? private lazy var incorrectQRFeedback: IncorrectQRCodeTextContainer = { let view = IncorrectQRCodeTextContainer() view.layer.cornerRadius = Constants.spacing @@ -171,6 +173,19 @@ final class QRCodeOverlay: UIView { fatalError("init(coder:) has not been implemented") } + override func layoutSubviews() { + if UIDevice.current.isIphone, + let incorrectQRWidthConstraint, + let incorrectQRTrailingConstraint { + let isLandscape = currentInterfaceOrientation.isLandscape + let toBeDeactivated = isLandscape ? incorrectQRTrailingConstraint : incorrectQRWidthConstraint + let toBeActivated = isLandscape ? incorrectQRWidthConstraint : incorrectQRTrailingConstraint + toBeDeactivated.isActive = false + toBeActivated.isActive = true + } + super.layoutSubviews() + } + private func addLoadingView() { let loadingIndicator: UIView @@ -211,12 +226,14 @@ final class QRCodeOverlay: UIView { } private func layoutIncorrectQRCode(centeringBy cameraFrame: UIView) { + incorrectQRWidthConstraint = incorrectQRFeedback.widthAnchor.constraint(equalTo: cameraFrame.widthAnchor, multiplier: 327/453) + incorrectQRTrailingConstraint = incorrectQRFeedback.trailingAnchor.constraint(equalTo: cameraFrame.trailingAnchor, + constant: -Constants.spacing) NSLayoutConstraint.activate([ incorrectQRFeedback.topAnchor.constraint(equalTo: cameraFrame.topAnchor, constant: Constants.spacing), incorrectQRFeedback.leadingAnchor.constraint(equalTo: cameraFrame.leadingAnchor, constant: Constants.spacing), - incorrectQRFeedback.trailingAnchor.constraint(equalTo: cameraFrame.trailingAnchor, - constant: -Constants.spacing) + incorrectQRTrailingConstraint! ]) } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Document picker/Gallery/AlbumsPickerViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Document picker/Gallery/AlbumsPickerViewController.swift index eff7825a1..c28cf54c5 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Document picker/Gallery/AlbumsPickerViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Document picker/Gallery/AlbumsPickerViewController.swift @@ -137,7 +137,7 @@ final class AlbumsPickerViewController: UIViewController, PHPhotoLibraryChangeOb } tableViewHeightAnchor.constant = tableViewContentHeight if UIDevice.current.isIphone { - let isLandscape = currentInterfaceOrientation?.isLandscape == true + let isLandscape = currentInterfaceOrientation.isLandscape let padding = isLandscape ? Constants.paddingHorizontal * 2 : Constants.padding * 2 tableViewLeadingConstraint.constant = padding tableViewTrailingConstraint.constant = -padding diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Document picker/Gallery/ImagePickerViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Document picker/Gallery/ImagePickerViewController.swift index 2e7514b7f..b5bbf2e7d 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Document picker/Gallery/ImagePickerViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Document picker/Gallery/ImagePickerViewController.swift @@ -93,7 +93,7 @@ final class ImagePickerViewController: UIViewController { override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() if UIDevice.current.isIphone { - let isLandscape = currentInterfaceOrientation?.isLandscape == true + let isLandscape = currentInterfaceOrientation.isLandscape bottomNavigationBarHeightConstraint?.constant = isLandscape ? Constants.navigationBarHeightHorizontal : Constants.navigationBarHeight } } @@ -243,7 +243,7 @@ extension ImagePickerViewController: UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - return ImagePickerCollectionViewCell.size(itemsInARow: currentInterfaceOrientation?.isLandscape == true ? 5 : 4, + return ImagePickerCollectionViewCell.size(itemsInARow: currentInterfaceOrientation.isLandscape ? 5 : 4, collectionViewLayout: collectionViewLayout) } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Error/ErrorScreenViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Error/ErrorScreenViewController.swift index 4e982b932..f3bc27f1d 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Error/ErrorScreenViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Error/ErrorScreenViewController.swift @@ -100,7 +100,7 @@ class ErrorScreenViewController: UIViewController { override func viewDidLayoutSubviews() { if UIDevice.current.isIphone { - let isLandscape = currentInterfaceOrientation?.isLandscape == true + let isLandscape = currentInterfaceOrientation.isLandscape headeriPhoneLeadingConstraint?.constant = isLandscape ? Constants.sidePaddingHorizontal : Constants.sidePadding buttonsView.buttonsView.axis = isLandscape ? .horizontal : .vertical buttonsHeightConstraint?.constant = getButtonsMinHeight(numberOfButtons: isLandscape ? 1 : numberOfButtons) diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/Protocols/HelpBottomBarEnabledViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/Protocols/HelpBottomBarEnabledViewController.swift index e9456bcee..ec773eb8f 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/Protocols/HelpBottomBarEnabledViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/Protocols/HelpBottomBarEnabledViewController.swift @@ -10,14 +10,23 @@ import UIKit protocol HelpBottomBarEnabledViewController: UIViewController { var bottomNavigationBar: UIView? {get set} var navigationBarBottomAdapter: HelpBottomNavigationBarAdapter? {get set} + var bottomNavigationBarHeightConstraint: NSLayoutConstraint? {get set} func configureBottomNavigationBar( configuration: GiniConfiguration, under underView: UIView) + func updateBottomBarHeightBasedOnOrientation() } extension HelpBottomBarEnabledViewController { + func updateBottomBarHeightBasedOnOrientation() { + if UIDevice.current.isIphone { + let isLandscape = currentInterfaceOrientation.isLandscape + bottomNavigationBarHeightConstraint?.constant = isLandscape ? 62 : 114 + } + } + func configureCustomTopNavigationBar() { navigationItem.leftBarButtonItem = nil navigationItem.setHidesBackButton(true, animated: true) @@ -31,10 +40,12 @@ extension HelpBottomBarEnabledViewController { bottomNavigationBar.translatesAutoresizingMaskIntoConstraints = false superView.addSubview(bottomNavigationBar) superView.bringSubviewToFront(bottomNavigationBar) + bottomNavigationBarHeightConstraint = bottomNavigationBar.heightAnchor.constraint(equalToConstant: 114) NSLayoutConstraint.activate([ bottomNavigationBar.bottomAnchor.constraint(equalTo: superView.bottomAnchor), bottomNavigationBar.leadingAnchor.constraint(equalTo: superView.leadingAnchor), bottomNavigationBar.trailingAnchor.constraint(equalTo: superView.trailingAnchor), + bottomNavigationBarHeightConstraint!, view.bottomAnchor.constraint(equalTo: bottomNavigationBar.topAnchor) ]) superView.layoutSubviews() diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpFormatsViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpFormatsViewController.swift index 55e06adc6..32cddd54c 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpFormatsViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpFormatsViewController.swift @@ -12,6 +12,7 @@ final class HelpFormatsViewController: UIViewController, HelpBottomBarEnabledVie var bottomNavigationBar: UIView? var navigationBarBottomAdapter: HelpBottomNavigationBarAdapter? + var bottomNavigationBarHeightConstraint: NSLayoutConstraint? lazy var tableView: UITableView = { var tableView: UITableView @@ -27,6 +28,12 @@ final class HelpFormatsViewController: UIViewController, HelpBottomBarEnabledVie private var giniConfiguration: GiniConfiguration private let tableRowHeight: CGFloat = 44 private let sectionHeight: CGFloat = 70 + private lazy var tableViewLeadingConstraint = tableView.leadingAnchor.constraint( + equalTo: view.leadingAnchor, + constant: GiniMargins.margin) + private lazy var tableViewTrailingConstraint = tableView.trailingAnchor.constraint( + equalTo: view.trailingAnchor, + constant: -GiniMargins.margin) init(giniConfiguration: GiniConfiguration) { self.giniConfiguration = giniConfiguration @@ -45,6 +52,13 @@ final class HelpFormatsViewController: UIViewController, HelpBottomBarEnabledVie override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() + updateBottomBarHeightBasedOnOrientation() + if UIDevice.current.isIphone { + let isLandscape = currentInterfaceOrientation.isLandscape + let margin = isLandscape ? GiniMargins.marginHorizontal : GiniMargins.margin + tableViewLeadingConstraint.constant = margin + tableViewTrailingConstraint.constant = -margin + } tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: GiniMargins.margin, right: 0) tableView.reloadData() } @@ -112,12 +126,8 @@ final class HelpFormatsViewController: UIViewController, HelpBottomBarEnabledVie ]) } else { NSLayoutConstraint.activate([ - tableView.leadingAnchor.constraint( - equalTo: view.leadingAnchor, - constant: GiniMargins.margin), - tableView.trailingAnchor.constraint( - equalTo: view.trailingAnchor, - constant: -GiniMargins.margin) + tableViewLeadingConstraint, + tableViewTrailingConstraint ]) } view.layoutSubviews() diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpImportViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpImportViewController.swift index e126d6c80..f8bd4736c 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpImportViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpImportViewController.swift @@ -12,6 +12,7 @@ final class HelpImportViewController: UIViewController, HelpBottomBarEnabledView var bottomNavigationBar: UIView? var navigationBarBottomAdapter: HelpBottomNavigationBarAdapter? + var bottomNavigationBarHeightConstraint: NSLayoutConstraint? private enum HelpImportCellType { case selectInvoice @@ -43,6 +44,7 @@ final class HelpImportViewController: UIViewController, HelpBottomBarEnabledView override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() + updateBottomBarHeightBasedOnOrientation() tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: GiniMargins.margin * 2, right: 0) } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpMenuViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpMenuViewController.swift index 8cdbccf67..79b20b6a4 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpMenuViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpMenuViewController.swift @@ -27,6 +27,7 @@ final class HelpMenuViewController: UIViewController, HelpBottomBarEnabledViewCo private let tableRowHeight: CGFloat = 44 var navigationBarBottomAdapter: HelpBottomNavigationBarAdapter? var bottomNavigationBar: UIView? + var bottomNavigationBarHeightConstraint: NSLayoutConstraint? private var bottomConstraint: NSLayoutConstraint? lazy var tableView: UITableView = { @@ -100,6 +101,7 @@ final class HelpMenuViewController: UIViewController, HelpBottomBarEnabledViewCo override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() + updateBottomBarHeightBasedOnOrientation() tableView.reloadData() } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpTipsViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpTipsViewController.swift index 327dce613..c95463453 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpTipsViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpTipsViewController.swift @@ -15,8 +15,10 @@ import UIKit */ final class HelpTipsViewController: UIViewController, HelpBottomBarEnabledViewController { + var bottomNavigationBar: UIView? var navigationBarBottomAdapter: HelpBottomNavigationBarAdapter? + var bottomNavigationBarHeightConstraint: NSLayoutConstraint? private lazy var tableView: UITableView = { var tableView: UITableView @@ -50,6 +52,7 @@ final class HelpTipsViewController: UIViewController, HelpBottomBarEnabledViewCo override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() + updateBottomBarHeightBasedOnOrientation() tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: GiniMargins.margin, right: 0) tableView.reloadData() } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/NoResult/NoResultScreenViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/NoResult/NoResultScreenViewController.swift index ef3d61b6b..a7bf9b799 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/NoResult/NoResultScreenViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/NoResult/NoResultScreenViewController.swift @@ -138,7 +138,7 @@ final class NoResultScreenViewController: UIViewController { } if UIDevice.current.isIphone { - let isLandscape = currentInterfaceOrientation?.isLandscape == true + let isLandscape = currentInterfaceOrientation.isLandscape headeriPhoneLeadingConstraint?.constant = isLandscape ? Constants.sidePaddingHorizontal : Constants.sidePadding buttonsView.axis = isLandscape ? .horizontal : .vertical buttonsHeightConstraint?.constant = getButtonsMinHeight(numberOfButtons: isLandscape ? 1 : numberOfButtons) diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Review/ReviewViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Review/ReviewViewController.swift index b36a08526..9b73785cd 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Review/ReviewViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Review/ReviewViewController.swift @@ -185,12 +185,16 @@ public final class ReviewViewController: UIViewController { return addPagesButton }() - private lazy var buttonContainer: UIView = { - let view = UIView() + private lazy var buttonContainer: UIStackView = { + let view = UIStackView(arrangedSubviews: [processButton]) view.translatesAutoresizingMaskIntoConstraints = false + view.axis = .horizontal + view.spacing = Constants.padding return view }() + private var bottomNavigationBar: UIView? + private var loadingIndicatorView: UIActivityIndicatorView = { let indicatorView = UIActivityIndicatorView() indicatorView.hidesWhenStopped = true @@ -200,7 +204,7 @@ public final class ReviewViewController: UIViewController { }() private lazy var cellSize: CGSize = { - return calculatedCellSize() + return calculatedCellSize(isHorizontal: false) }() private lazy var collectionViewHeightConstraint = collectionView.heightAnchor.constraint( @@ -239,6 +243,12 @@ public final class ReviewViewController: UIViewController { tipLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.titleHeight), tipLabel.heightAnchor.constraint(lessThanOrEqualToConstant: Constants.maxTitleHeight)] + private var trailingConstraints: [NSLayoutConstraint] { + [ + collectionViewConstraints[2], + tipLabelConstraints[2] + ] + } private lazy var collectionViewConstraints: [NSLayoutConstraint] = [ collectionView.topAnchor.constraint(equalTo: tipLabel.bottomAnchor, constant: Constants.padding), collectionView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), @@ -250,19 +260,17 @@ public final class ReviewViewController: UIViewController { pageControl.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), pageControl.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)] + private lazy var pageControlHorizontalConstraints: [NSLayoutConstraint] = [ + pageControl.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -Constants.padding * 2), + pageControl.topAnchor.constraint(equalTo: collectionView.bottomAnchor, constant: Constants.padding * 2), + pageControl.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + pageControl.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -275) + ] + private lazy var processButtonConstraints: [NSLayoutConstraint] = [ - processButton.topAnchor.constraint(equalTo: buttonContainer.topAnchor), processButton.widthAnchor.constraint(greaterThanOrEqualToConstant: Constants.buttonSize.width), - processButton.leadingAnchor.constraint(equalTo: buttonContainer.leadingAnchor), - processButton.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.buttonSize.height), - processButton.bottomAnchor.constraint(equalTo: buttonContainer.bottomAnchor, constant: -8), - processButton.trailingAnchor.constraint(lessThanOrEqualTo: buttonContainer.trailingAnchor)] - - private lazy var addPagesButtonConstraints: [NSLayoutConstraint] = [ - addPagesButton.centerYAnchor.constraint(equalTo: processButton.centerYAnchor), - addPagesButton.leadingAnchor.constraint(equalTo: processButton.trailingAnchor, - constant: Constants.padding), - addPagesButton.trailingAnchor.constraint(equalTo: buttonContainer.trailingAnchor)] + processButton.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.buttonSize.height) + ] private lazy var buttonContainerConstraints: [NSLayoutConstraint] = [ buttonContainer.topAnchor.constraint(equalTo: pageControl.bottomAnchor, constant: Constants.padding * 2), @@ -272,6 +280,11 @@ public final class ReviewViewController: UIViewController { buttonContainer.leadingAnchor.constraint(greaterThanOrEqualTo: view.leadingAnchor) ] + private lazy var buttonContainerHorizontalConstraints: [NSLayoutConstraint] = [ + buttonContainer.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -85), + buttonContainer.centerYAnchor.constraint(equalTo: collectionView.centerYAnchor) + ] + // MARK: - Init /** @@ -324,6 +337,7 @@ extension ReviewViewController { } private func layoutBottomNavigationBar(_ navigationBar: UIView) { + bottomNavigationBar = navigationBar navigationBar.translatesAutoresizingMaskIntoConstraints = false view.addSubview(navigationBar) NSLayoutConstraint.activate([ @@ -371,7 +385,7 @@ extension ReviewViewController { public override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() - let size = calculatedCellSize() + let size = calculatedCellSize(isHorizontal: false) collectionViewHeightConstraint.constant = size.height + 4 if UIDevice.current.isIpad { // cellSize needs to be updated when the screen is rotated @@ -391,7 +405,23 @@ extension ReviewViewController { self.setCellStatus(for: self.currentPage, isActive: true) } } + } else if UIDevice.current.isIphone { + let isLandscape = currentInterfaceOrientation.isLandscape + buttonContainer.axis = isLandscape ? .vertical : .horizontal + + trailingConstraints.forEach { $0.constant = isLandscape ? -275 : 0 } + let constraintsToActivate = isLandscape + ? buttonContainerHorizontalConstraints + pageControlHorizontalConstraints + : buttonContainerConstraints + pageControlConstraints + + let constraintsToDeactivate = isLandscape + ? buttonContainerConstraints + pageControlConstraints + : buttonContainerHorizontalConstraints + pageControlHorizontalConstraints + + NSLayoutConstraint.deactivate(constraintsToDeactivate) + NSLayoutConstraint.activate(constraintsToActivate) } + collectionView.reloadData() } private func setupView() { @@ -404,12 +434,11 @@ extension ReviewViewController { contentView.addSubview(tipLabel) contentView.addSubview(collectionView) contentView.addSubview(pageControl) + if giniConfiguration.multipageEnabled { + buttonContainer.addSubview(addPagesButton) + } if !giniConfiguration.bottomNavigationBarEnabled { contentView.addSubview(buttonContainer) - buttonContainer.addSubview(processButton) - if giniConfiguration.multipageEnabled { - buttonContainer.addSubview(addPagesButton) - } } edgesForExtendedLayout = [] } @@ -517,7 +546,7 @@ extension ReviewViewController { NSLayoutConstraint.activate(buttonContainerConstraints) NSLayoutConstraint.activate(processButtonConstraints) if giniConfiguration.multipageEnabled { - NSLayoutConstraint.activate(addPagesButtonConstraints) + buttonContainer.addArrangedSubview(addPagesButton) } } else { NSLayoutConstraint.activate([ @@ -589,8 +618,9 @@ extension ReviewViewController { } } - private func calculatedCellSize() -> CGSize { + private func calculatedCellSize(isHorizontal: Bool) -> CGSize { let a4Ratio = 1.4142 + let widthRatio: CGFloat = isHorizontal ? 1/a4Ratio : a4Ratio if UIDevice.current.isIpad { var height = self.view.bounds.height - 260 if giniConfiguration.bottomNavigationBarEnabled { @@ -602,12 +632,12 @@ extension ReviewViewController { } else { if view.safeAreaInsets.bottom > 0 { let height = self.view.bounds.height * 0.6 - let width = height / a4Ratio + let width = height / widthRatio let cellSize = CGSize(width: width, height: height) return cellSize } else { let height = self.view.bounds.height * 0.5 - let width = height / a4Ratio + let width = height / widthRatio let cellSize = CGSize(width: width, height: height) return cellSize } @@ -660,13 +690,18 @@ extension ReviewViewController: UICollectionViewDelegateFlowLayout { public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - return cellSize + let page = pages[indexPath.row] + let isHorizontal = { + guard let size = page.document.previewImage?.size, UIDevice.current.isIphone else { return false } + return size.width > size.height + }() + return calculatedCellSize(isHorizontal: false) } public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { - let margin = (self.view.bounds.width - cellSize.width) / 2 + let margin = (self.view.bounds.width - (currentInterfaceOrientation.isLandscape && UIDevice.current.isIphone ? 275 : 0) - cellSize.width) / 2 return UIEdgeInsets(top: 0, left: margin, bottom: 0, right: margin) } @@ -682,7 +717,7 @@ extension ReviewViewController: UICollectionViewDelegateFlowLayout { let offset = scrollView.contentOffset let cellWidthIncludingSpacing = cellSize.width + layout.minimumLineSpacing let index = (offset.x + scrollView.contentInset.left) / cellWidthIncludingSpacing - currentPage = Int(round(index)) + currentPage = max(min(Int(round(index)), pages.count - 1), 0) self.pageControl.currentPage = currentPage } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Resources/GiniImages.xcassets/cameraFocusHorizontal.imageset/Contents.json b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Resources/GiniImages.xcassets/cameraFocusHorizontal.imageset/Contents.json deleted file mode 100644 index 5c431d253..000000000 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Resources/GiniImages.xcassets/cameraFocusHorizontal.imageset/Contents.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "images" : [ - { - "filename" : "Group 3.pdf", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Resources/GiniImages.xcassets/cameraFocusHorizontal.imageset/Group 3.pdf b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Resources/GiniImages.xcassets/cameraFocusHorizontal.imageset/Group 3.pdf deleted file mode 100644 index 403c04d23..000000000 Binary files a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Resources/GiniImages.xcassets/cameraFocusHorizontal.imageset/Group 3.pdf and /dev/null differ