Skip to content

Commit

Permalink
fix(GiniBankSDK): support for camera, error screen, no results screen…
Browse files Browse the repository at this point in the history
…, album picker screen, photo selector screen; fix camera crashing for ipad

PP-943
  • Loading branch information
igor-gini committed Jan 9, 2025
1 parent f7b8a2b commit b92318d
Show file tree
Hide file tree
Showing 31 changed files with 517 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ final class DigitalInvoiceHelpViewController: UIViewController {
scrollView.bottomAnchor.constraint(equalTo: navigationBar.topAnchor),
navigationBar.bottomAnchor.constraint(equalTo: view.bottomAnchor),
navigationBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
navigationBar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
navigationBar.heightAnchor.constraint(equalToConstant: Constants.navigationBarHeight)
navigationBar.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
view.bringSubviewToFront(navigationBar)
view.layoutSubviews()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ final class DigitalInvoiceOnboardingViewController: UIViewController {
navigationBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
navigationBar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
navigationBar.bottomAnchor.constraint(equalTo: view.bottomAnchor),
navigationBar.heightAnchor.constraint(equalToConstant: Constants.navigationBarHeight),
navigationBar.topAnchor.constraint(equalTo: scrollView.bottomAnchor)
])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ final class SkontoHelpViewController: UIViewController {
scrollView.bottomAnchor.constraint(equalTo: navigationBar.topAnchor),
navigationBar.bottomAnchor.constraint(equalTo: view.bottomAnchor),
navigationBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
navigationBar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
navigationBar.heightAnchor.constraint(equalToConstant: Constants.navigationBarHeight)
navigationBar.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
view.bringSubviewToFront(navigationBar)
view.layoutSubviews()
Expand Down
2 changes: 2 additions & 0 deletions BankSDK/GiniBankSDKExample/GiniBankSDKExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ final class BottomLabelButton: UIView {
return image
}()

private lazy var contentView: UIView = {
let contentView = UIView()
private lazy var contentView: UIStackView = {
let contentView = UIStackView(arrangedSubviews: [iconView, actionLabel])
contentView.translatesAutoresizingMaskIntoConstraints = false

contentView.spacing = 5
contentView.axis = .vertical
return contentView
}()

Expand Down Expand Up @@ -85,15 +86,7 @@ final class BottomLabelButton: UIView {
contentView.trailingAnchor.constraint(equalTo: trailingAnchor),
contentView.leadingAnchor.constraint(equalTo: leadingAnchor),

iconView.topAnchor.constraint(equalTo: contentView.topAnchor),
iconView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
iconView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
iconView.heightAnchor.constraint(equalToConstant: 20),

actionLabel.topAnchor.constraint(equalTo: iconView.bottomAnchor, constant: 5),
actionLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
actionLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
actionLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class ButtonsView: UIView {
let firstButtonTitle: String
let secondButtonTitle: String

var axis: NSLayoutConstraint.Axis {
get { buttonsView.axis }
set { buttonsView.axis = newValue }
}

init(firstTitle: String, secondTitle: String) {
firstButtonTitle = firstTitle
secondButtonTitle = secondTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class ContainerNavigationController: UIViewController {
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIDevice.current.isIpad ? .all : .portrait
return UIDevice.current.isIpad ? .all : .all
}

override var preferredStatusBarStyle: UIStatusBarStyle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ extension UIView {
NSLayoutConstraint.activate([leadingConstraint, trailingConstraint, topConstraint, bottomConstraint])
}
}

extension UIView {
var currentInterfaceOrientation: UIInterfaceOrientation? {
if #available(iOS 13, *) {
return window?.windowScene?.interfaceOrientation ?? UIApplication.shared.statusBarOrientation
} else {
return UIApplication.shared.statusBarOrientation
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ extension UIViewController {
}
}
}

extension UIViewController {
var currentInterfaceOrientation: UIInterfaceOrientation? { view.currentInterfaceOrientation }
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public class Constraints {
case top, bottom, right, left
}

@discardableResult
public class func active(item view1: Any!,
attr attr1: NSLayoutConstraint.Attribute,
relatedBy relation: NSLayoutConstraint.Relation,
Expand All @@ -179,14 +180,15 @@ public class Constraints {
multiplier: CGFloat = 1.0,
constant: CGFloat = 0,
priority: Float = 1000,
identifier: String? = nil) {
identifier: String? = nil) -> NSLayoutConstraint {
let constraint = NSLayoutConstraint(item: view1!,
attribute: attr1,
relatedBy: relation,
toItem: view2, attribute: attr2,
multiplier: multiplier,
constant: constant)
active(constraint: constraint, priority: priority, identifier: identifier)
return constraint
}

class func active(constraint: NSLayoutConstraint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extension UITableViewCell {

public struct GiniMargins {
public static let margin: CGFloat = 16
public static let marginHorizontal: CGFloat = 56
public static let iPadAspectScale: CGFloat = 0.7
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ import UIKit
return overlayView
}()

private var centerYConstraint = NSLayoutConstraint()

/**
Designated intitializer for the `AnalysisViewController`.

Expand Down Expand Up @@ -146,6 +148,14 @@ import UIKit
properties: eventProperties)
}

public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if UIDevice.current.isIphone, document is GiniImageDocument {
let isLandscape = currentInterfaceOrientation?.isLandscape == true
centerYConstraint.constant = isLandscape ? -96 / 2 : 0
}
}

// MARK: Toggle animation

/// Displays a loading activity indicator. Should be called when document analysis is started.
Expand Down Expand Up @@ -253,10 +263,10 @@ import UIKit
loadingIndicator.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(container)
container.addSubview(loadingIndicator)

centerYConstraint = container.centerYAnchor.constraint(equalTo: view.centerYAnchor)
NSLayoutConstraint.activate([
container.centerXAnchor.constraint(equalTo: view.centerXAnchor),
container.centerYAnchor.constraint(equalTo: view.centerYAnchor),
centerYConstraint,
container.heightAnchor.constraint(equalToConstant: Constants.loadingIndicatorContainerHeight),
container.widthAnchor.constraint(equalTo: container.heightAnchor),
loadingIndicator.centerXAnchor.constraint(equalTo: container.centerXAnchor),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ final class CaptureSuggestionsView: UIView {
private let containerHeight: CGFloat = 96
private var itemSeparationConstraint: NSLayoutConstraint = NSLayoutConstraint()
private var bottomConstraint: NSLayoutConstraint = NSLayoutConstraint()
private var leadingiPhondConstraint = NSLayoutConstraint()
private var trailingiPhoneConstraint = NSLayoutConstraint()
private let repeatInterval: TimeInterval = 5
private let superViewBottomAnchor: NSLayoutYAxisAnchor

Expand Down Expand Up @@ -86,6 +88,16 @@ final class CaptureSuggestionsView: UIView {
fatalError("You should use init() initializer")
}

override func layoutSubviews() {
super.layoutSubviews()
if UIDevice.current.isIphone {
let isLandscape = currentInterfaceOrientation?.isLandscape == true
let margin: CGFloat = isLandscape ? 56 : 20
leadingiPhondConstraint.constant = margin
trailingiPhoneConstraint.constant = -margin
}
}

private func addConstraints() {
guard let superview = superview, let suggestionContainer = suggestionContainer else { return }

Expand All @@ -110,9 +122,9 @@ final class CaptureSuggestionsView: UIView {
attr: .width, multiplier: 0.7)
Constraints.active(item: suggestionContainer, attr: .centerX, relatedBy: .equal, to: self, attr: .centerX)
} else {
Constraints.active(item: suggestionContainer, attr: .leading, relatedBy: .equal, to: self, attr: .leading,
leadingiPhondConstraint = Constraints.active(item: suggestionContainer, attr: .leading, relatedBy: .equal, to: self, attr: .leading,
constant: 20)
Constraints.active(item: suggestionContainer, attr: .trailing, relatedBy: .equal, to: self, attr: .trailing,
trailingiPhoneConstraint = Constraints.active(item: suggestionContainer, attr: .trailing, relatedBy: .equal, to: self, attr: .trailing,
constant: -20)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ extension CameraViewController {
cameraPane.captureButton.alpha = 0
}

public func setupCamera() {
cameraPreviewViewController.setupCamera()
public func setupCamera(bottomAnchor: NSLayoutYAxisAnchor) {
cameraPreviewViewController.setupCamera(bottomAnchor: bottomAnchor)
}

public func stopLoadingIndicater() {
Expand Down
Loading

0 comments on commit b92318d

Please sign in to comment.