Skip to content

Commit

Permalink
Release version 3.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Team Mobile Schorsch committed Nov 22, 2023
1 parent 22c4068 commit 6d38680
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ extension AVCaptureVideoOrientation {
}
}

init?(_ device: UIDeviceOrientation?) {
guard let orientation = device else { return nil }
switch orientation {
init(_ device: UIDeviceOrientation) {
switch device {
case .portrait: self = .portrait
case .portraitUpsideDown: self = .portraitUpsideDown
case .landscapeLeft: self = .landscapeRight
case .landscapeRight: self = .landscapeLeft
default: return nil
default: self = .portrait
}
}
}
19 changes: 19 additions & 0 deletions Sources/GiniCaptureSDK/Core/Extensions/UIImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import UIKit
import AVFoundation

extension UIImage {
convenience init?(qrData data: Data) {
Expand Down Expand Up @@ -157,3 +158,21 @@ extension UIImage {
return self
}
}


extension UIImage.Orientation {
init(_ cgOrientation: AVCaptureVideoOrientation) {
switch cgOrientation {
case .portrait:
self = .up
case .landscapeRight:
self = .right
case .landscapeLeft:
self = .left
case .portraitUpsideDown:
self = .down
@unknown default:
fatalError("Unknown AVCaptureVideoOrientation case encountered")
}
}
}
21 changes: 21 additions & 0 deletions Sources/GiniCaptureSDK/Core/Extensions/UIWindow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// UIWindow.swift
//
//
// Copyright © 2023 Gini GmbH. All rights reserved
//

import UIKit

extension UIWindow {
static var orientation: UIInterfaceOrientation {
if #available(iOS 13.0, *) {
return UIApplication.shared.windows
.first?
.windowScene?
.interfaceOrientation ?? .portrait
} else {
return UIApplication.shared.statusBarOrientation
}
}
}
6 changes: 3 additions & 3 deletions Sources/GiniCaptureSDK/Core/GiniConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ import GiniBankAPILibrary
@objc public var flashToggleEnabled = false

/**
When the flash toggle is enabled, this flag indicates if the flash is on by default.
Set whether the camera flash should be on or off when the SDK starts. The flash is off by default.
*/
@objc public var flashOnByDefault = true
@objc public var flashOnByDefault = false

/**
Sets the close button text in the navigation bar on the camera screen.
*/
*/
@objc public var navigationBarCameraTitleCloseButton = ""

/**
Expand Down
44 changes: 44 additions & 0 deletions Sources/GiniCaptureSDK/Core/Helpers/DeviceOrientation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// DeviceOrientation.swift
//
//
// Copyright © 2023 Gini GmbH. All rights reserved
//

import UIKit

enum Device {

/**
* This property tries to get 4 orientations:
* landscapeLeft, landscapeRight, portrait, portraitUpsideDown
* as defined by UIDeviceOrientation enum.
* It can return also unknown orientation (which is rare case)
*/
static var orientation: UIDeviceOrientation {

// otherwise if there is flat (faceUp, faceDown), unknown orientation
// try to get orientation from UIInterfaceOrientation
// Notice that:
// UIDeviceOrientationLandscapeRight => UIInterfaceOrientationLandscapeLeft
// UIDeviceOrientationLandscapeLeft => UIInterfaceOrientationLandscapeRight

let interfaceOrientation = UIWindow.orientation
switch interfaceOrientation {
case .landscapeLeft:
return UIDeviceOrientation.landscapeRight
case .landscapeRight:
return UIDeviceOrientation.landscapeLeft
case .portrait:
return .portrait
case .portraitUpsideDown:
return .portraitUpsideDown
case .unknown:
break
@unknown default:
break
}

return .unknown
}
}
2 changes: 1 addition & 1 deletion Sources/GiniCaptureSDK/Core/Screens/Camera/Camera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ final class Camera: NSObject, CameraProtocol {
// Set the orientation according to the current orientation of the interface
DispatchQueue.main.sync { [weak self] in
guard let self = self else { return }
connection.videoOrientation = AVCaptureVideoOrientation(self.application.statusBarOrientation)
connection.videoOrientation = AVCaptureVideoOrientation(Device.orientation)
}

// Trigger photo capturing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ import UIKit
if let image = self.cameraButtonsViewModel.didCapture(imageData: data,
processedImageData: processedImageData,
error: error,
orientation:
UIApplication.shared.statusBarOrientation,
orientation: UIWindow.orientation,
giniConfiguration: self.giniConfiguration) {

UIImpactFeedbackGenerator(style: .medium).impactOccurred()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ final class CameraPreviewViewController: UIViewController {
return spinner
}()

private let cameraFocusImage = UIImageNamedPreferred(named: "cameraFocus")
lazy var cameraFrameView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImageNamedPreferred(named: "cameraFocus")
imageView.image = cameraFocusImage
imageView.contentMode = .scaleAspectFit
imageView.isHidden = true
return imageView
Expand All @@ -71,12 +72,6 @@ final class CameraPreviewViewController: UIViewController {
private var camera: CameraProtocol
private var defaultImageView: UIImageView?
private var focusIndicatorImageView: UIImageView?
private let interfaceOrientationsMapping: [UIInterfaceOrientation: AVCaptureVideoOrientation] = [
.portrait: .portrait,
.landscapeRight: .landscapeRight,
.landscapeLeft: .landscapeLeft,
.portraitUpsideDown: .portraitUpsideDown
]

private var cameraFocusSmall: UIImage? {
return UIImageNamedPreferred(named: "cameraFocusSmall")
Expand Down Expand Up @@ -240,20 +235,19 @@ final class CameraPreviewViewController: UIViewController {
}

private func updateFrameOrientation(with orientation: AVCaptureVideoOrientation) {
if UIDevice.current.isIpad {
NSLayoutConstraint.deactivate([cameraFrameViewHeightAnchorPortrait, cameraFrameViewHeightAnchorLandscape])

let isLandscape = orientation == .landscapeRight || orientation == .landscapeLeft
cameraFrameViewHeightAnchorPortrait.isActive = !isLandscape
cameraFrameViewHeightAnchorLandscape.isActive = isLandscape

if let image = cameraFrameView.image?.cgImage {
if isLandscape {
cameraFrameView.image = UIImage(cgImage: image, scale: 1.0, orientation: .left)
} else {
cameraFrameView.image = UIImage(cgImage: image, scale: 1.0, orientation: .up)
}

guard UIDevice.current.isIpad else { return }
let isLandscape = orientation == .landscapeRight || orientation == .landscapeLeft
if let image = cameraFocusImage?.cgImage {
NSLayoutConstraint.deactivate([
cameraFrameViewHeightAnchorPortrait,
cameraFrameViewHeightAnchorLandscape
])
if isLandscape {
cameraFrameViewHeightAnchorLandscape.isActive = true
cameraFrameView.image = UIImage(cgImage: image, scale: 1.0, orientation: .left)
} else {
cameraFrameViewHeightAnchorPortrait.isActive = true
cameraFrameView.image = UIImage(cgImage: image, scale: 1.0, orientation: .up)
}
}
}
Expand Down Expand Up @@ -361,18 +355,10 @@ final class CameraPreviewViewController: UIViewController {

func updatePreviewViewOrientation() {

let orientation: AVCaptureVideoOrientation
if UIDevice.current.isIpad {
orientation = interfaceOrientationsMapping[UIApplication.shared.statusBarOrientation] ?? .portrait
currentOrientation = UIApplication.shared.statusBarOrientation
} else {
orientation = .portrait
currentOrientation = .portrait
}

let videoOrientation = AVCaptureVideoOrientation(Device.orientation)
previewView.videoPreviewLayer.connection?.videoOrientation = videoOrientation
setupOrientationAndTransform()
previewView.videoPreviewLayer.connection?.videoOrientation = orientation
updateFrameOrientation(with: orientation)
updateFrameOrientation(with: videoOrientation)
}

func changeQRFrameColor(to color: UIColor) {
Expand Down Expand Up @@ -406,25 +392,26 @@ final class CameraPreviewViewController: UIViewController {
.scaledBy(x: roi.width, y: roi.height)

// Compensate for orientation (buffers always come in the same orientation).
switch currentOrientation {
switch Device.orientation {
case .landscapeLeft:
textOrientation = CGImagePropertyOrientation.up
textOrientation = .up
uiRotationTransform = CGAffineTransform.identity
case .landscapeRight:
textOrientation = CGImagePropertyOrientation.down
textOrientation = .down
uiRotationTransform = CGAffineTransform(translationX: 1, y: 1).rotated(by: CGFloat.pi)
case .portraitUpsideDown:
textOrientation = CGImagePropertyOrientation.left
textOrientation = .left
uiRotationTransform = CGAffineTransform(translationX: 1, y: 0).rotated(by: CGFloat.pi / 2)
default: // everything else to .portraitUp
textOrientation = CGImagePropertyOrientation.right
textOrientation = .right
uiRotationTransform = CGAffineTransform(translationX: 0, y: 1).rotated(by: -CGFloat.pi / 2)
}

// Full Vision ROI to AVF transform.
visionToAVFTransform = roiToGlobalTransform.concatenating(bottomToTopTransform)
.concatenating(uiRotationTransform)
}

}

// MARK: - Default and not authorized views
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ final class AlbumsPickerTableViewCell: UITableViewCell {

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
accessoryType = .disclosureIndicator
let chevronImage = UIImageNamedPreferred(named: "chevron")
let chevronImageView = UIImageView(image: chevronImage)
chevronImageView.image = chevronImage
accessoryView = chevronImageView
contentView.addSubview(albumThumbnailView)
contentView.addSubview(albumTitleLabel)
contentView.addSubview(albumSubTitleLabel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ final class HelpMenuDataSource: HelpRoundedCornersDataSource<HelpMenuItem, HelpM
cell.titleLabel.numberOfLines = 0
cell.titleLabel.font = giniConfiguration.textStyleFonts[.body]
cell.titleLabel.adjustsFontForContentSizeCategory = true
cell.accessoryType = .disclosureIndicator
let chevronImage = UIImageNamedPreferred(named: "chevron")
let chevronImageView = UIImageView(image: chevronImage)
chevronImageView.image = chevronImage
cell.accessoryView = chevronImageView
cell.selectionStyle = .none
cell.separatorView.backgroundColor = GiniColor(
light: UIColor.GiniCapture.light3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class OnboardingPageCell: UICollectionViewCell {

override func layoutSubviews() {
if UIDevice.current.isIpad {
if UIApplication.shared.statusBarOrientation.isLandscape {
if UIWindow.orientation.isLandscape {
topConstraint.constant = Constants.compactTopPadding
iconBottomConstraint.constant = calculateIconMargin()
} else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/GiniCaptureSDK/GiniCaptureSDKVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// Created by Nadya Karaban on 29.10.21.
//

public let GiniCaptureSDKVersion = "3.6.0"
public let GiniCaptureSDKVersion = "3.7.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "chevron.pdf",
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "chevron-dark.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Binary file not shown.
6 changes: 0 additions & 6 deletions Tests/GiniCaptureSDKTests/HelpMenuViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,10 @@ final class HelpMenuViewControllerTests: XCTestCase {
func testCellContent() {
let indexPath = IndexPath(row: 0, section: 0)
let itemText = helpMenuViewController.dataSource.items[indexPath.row].title
let cellAccesoryType = UITableViewCell.AccessoryType.disclosureIndicator

let cell = helpMenuViewController.dataSource.tableView(helpMenuViewController.tableView, cellForRowAt: indexPath) as! HelpMenuCell

XCTAssertEqual(itemText, cell.titleLabel.text,
"cell text in the first row should be the same as the first item text")

XCTAssertEqual(cellAccesoryType,
cell.accessoryType,
"cell accesory type should be and a disclosure indicator")
}

}

0 comments on commit 6d38680

Please sign in to comment.