Skip to content

Commit

Permalink
fix(GiniBankSDK): review screen, fixes with camera qr detection label…
Browse files Browse the repository at this point in the history
…s and ipad, help screens
  • Loading branch information
igor-gini committed Jan 16, 2025
1 parent a49391a commit 259558d
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ extension UIViewController {
}

extension UIViewController {
var currentInterfaceOrientation: UIInterfaceOrientation? { view.currentInterfaceOrientation }
var currentInterfaceOrientation: UIInterfaceOrientation { view.currentInterfaceOrientation }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -142,7 +134,6 @@ final class CameraPreviewViewController: UIViewController {
view.insertSubview(previewView, at: 0)
view.addSubview(qrCodeFrameView)
view.addSubview(cameraFrameView)
view.addSubview(cameraFrameViewHorizontal)

addLoadingIndicator()
}
Expand Down Expand Up @@ -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,
Expand All @@ -210,7 +195,6 @@ final class CameraPreviewViewController: UIViewController {

private func setupConstraints() {
cameraFrameView.translatesAutoresizingMaskIntoConstraints = false
// cameraFrameViewHorizontal.translatesAutoresizingMaskIntoConstraints = false
qrCodeFrameView.translatesAutoresizingMaskIntoConstraints = false

if UIDevice.current.isIpad {
Expand All @@ -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)
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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!
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
}
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class HelpImportViewController: UIViewController, HelpBottomBarEnabledView

var bottomNavigationBar: UIView?
var navigationBarBottomAdapter: HelpBottomNavigationBarAdapter?
var bottomNavigationBarHeightConstraint: NSLayoutConstraint?

private enum HelpImportCellType {
case selectInvoice
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -100,6 +101,7 @@ final class HelpMenuViewController: UIViewController, HelpBottomBarEnabledViewCo

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
updateBottomBarHeightBasedOnOrientation()
tableView.reloadData()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 259558d

Please sign in to comment.