Skip to content

Commit

Permalink
fix(GiniBankSDK): fixes on camera + add support for bottom nav bar on…
Browse files Browse the repository at this point in the history
… review screen
  • Loading branch information
igor-gini committed Jan 20, 2025
1 parent 259558d commit f46a9ad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ final class CameraPreviewViewController: UIViewController {
if isViewLoaded {
setupIBANDetectionIfViewsAreLoaded()
}
if UIDevice.current.isIphone,
let defaultImageView,
let defaultImage,
let cgimage = defaultImage.cgImage
{
defaultImageView.image = UIImage(cgImage: cgimage, scale: 1, orientation: currentInterfaceOrientation.isLandscape ? .left : .up)
}
}

private func setupIBANDetectionIfViewsAreLoaded() {
Expand Down Expand Up @@ -321,6 +328,7 @@ final class CameraPreviewViewController: UIViewController {
self.isAuthorized = true
self.cameraFrameView.isHidden = false
self.addDefaultImage()
self.updatePreviewViewOrientation()
#endif
} else {
self.isAuthorized = false
Expand Down Expand Up @@ -445,8 +453,12 @@ extension CameraPreviewViewController {

/// Adds a default image to the canvas when no camera is available (DEBUG mode only)
private func addDefaultImage() {
guard let defaultImage = defaultImage else { return }

guard let defaultImageCG = defaultImage?.cgImage else { return }
if let defaultImageView {
defaultImageView.removeFromSuperview()
self.defaultImageView = nil
}
let defaultImage = UIImage(cgImage: defaultImageCG, scale: 1, orientation: (UIDevice.current.isIphone && currentInterfaceOrientation.isLandscape) ? .left : .up)
defaultImageView = UIImageView(image: defaultImage)
guard let defaultImageView = defaultImageView else { return }
defaultImageView.alpha = 0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ public final class ReviewViewController: UIViewController {
return indicatorView
}()

private var loadingIndicator: UIView?

private lazy var cellSize: CGSize = {
return calculatedCellSize(isHorizontal: false)
}()
Expand Down Expand Up @@ -409,14 +411,29 @@ extension ReviewViewController {
let isLandscape = currentInterfaceOrientation.isLandscape
buttonContainer.axis = isLandscape ? .vertical : .horizontal

if giniConfiguration.bottomNavigationBarEnabled {
if isLandscape {
view.addSubview(buttonContainer)
addLoadingView()
} else {
loadingIndicator?.removeFromSuperview()
buttonContainer.removeFromSuperview()
}
}

bottomNavigationBar?.alpha = isLandscape ? 0 : 1
bottomNavigationBar?.isUserInteractionEnabled = !isLandscape

trailingConstraints.forEach { $0.constant = isLandscape ? -275 : 0 }
let constraintsToActivate = isLandscape
? buttonContainerHorizontalConstraints + pageControlHorizontalConstraints
: buttonContainerConstraints + pageControlConstraints
? buttonContainerHorizontalConstraints + pageControlHorizontalConstraints
: giniConfiguration.bottomNavigationBarEnabled
? []
: buttonContainerConstraints + pageControlConstraints

let constraintsToDeactivate = isLandscape
? buttonContainerConstraints + pageControlConstraints
: buttonContainerHorizontalConstraints + pageControlHorizontalConstraints
? buttonContainerConstraints + pageControlConstraints
: buttonContainerHorizontalConstraints + pageControlHorizontalConstraints

NSLayoutConstraint.deactivate(constraintsToDeactivate)
NSLayoutConstraint.activate(constraintsToActivate)
Expand All @@ -435,7 +452,7 @@ extension ReviewViewController {
contentView.addSubview(collectionView)
contentView.addSubview(pageControl)
if giniConfiguration.multipageEnabled {
buttonContainer.addSubview(addPagesButton)
buttonContainer.addArrangedSubview(addPagesButton)
}
if !giniConfiguration.bottomNavigationBarEnabled {
contentView.addSubview(buttonContainer)
Expand All @@ -446,7 +463,11 @@ extension ReviewViewController {
// MARK: - Loading indicator

private func addLoadingView() {
guard !giniConfiguration.bottomNavigationBarEnabled else { return }
guard !giniConfiguration.bottomNavigationBarEnabled || (buttonContainer.superview != nil && UIDevice.current.isIphone) else { return }
if let loadingIndicator {
loadingIndicator.removeFromSuperview()
self.loadingIndicator = nil
}
let loadingIndicator: UIView

if let customLoadingIndicator = giniConfiguration.onButtonLoadingIndicator?.injectedView() {
Expand All @@ -465,6 +486,7 @@ extension ReviewViewController {
loadingIndicator.widthAnchor.constraint(equalToConstant: 45),
loadingIndicator.heightAnchor.constraint(equalToConstant: 45)
])
self.loadingIndicator = loadingIndicator
}

private func showAnimation() {
Expand Down Expand Up @@ -541,10 +563,10 @@ extension ReviewViewController {
NSLayoutConstraint.activate(tipLabelConstraints)
NSLayoutConstraint.activate(collectionViewConstraints)
NSLayoutConstraint.activate(pageControlConstraints)
NSLayoutConstraint.activate(processButtonConstraints)

if !giniConfiguration.bottomNavigationBarEnabled {
NSLayoutConstraint.activate(buttonContainerConstraints)
NSLayoutConstraint.activate(processButtonConstraints)
if giniConfiguration.multipageEnabled {
buttonContainer.addArrangedSubview(addPagesButton)
}
Expand Down Expand Up @@ -623,7 +645,7 @@ extension ReviewViewController {
let widthRatio: CGFloat = isHorizontal ? 1/a4Ratio : a4Ratio
if UIDevice.current.isIpad {
var height = self.view.bounds.height - 260
if giniConfiguration.bottomNavigationBarEnabled {
if giniConfiguration.bottomNavigationBarEnabled, !(currentInterfaceOrientation.isLandscape && UIDevice.current.isIphone) {
height -= Constants.bottomNavigationBarHeight
height -= Constants.padding
}
Expand Down

0 comments on commit f46a9ad

Please sign in to comment.