Skip to content

Commit c449c7f

Browse files
Merge pull request #7 from OutSystems/development
RMET-3028 ::: Prepare v1.0.0 Release
2 parents 362eb3a + 8a2921a commit c449c7f

File tree

57 files changed

+1678
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1678
-62
lines changed

.github/workflows/github_actions.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ jobs:
1111
test:
1212
name: Unit-Tests
1313
runs-on: macos-latest
14-
1514
steps:
1615
- name: Checkout
17-
uses: actions/checkout@v1
16+
uses: actions/checkout@v4
17+
- name: Setup Java 17
18+
uses: actions/setup-java@v3
19+
with:
20+
distribution: 'zulu'
21+
java-version: '17'
1822
- name: Bundle Install
1923
run: bundle install
2024
- name: Unit tests
@@ -26,7 +30,7 @@ jobs:
2630
- name: Lint
2731
run: bundle exec fastlane lint
2832
- name: Setup sonarqube
29-
uses: warchant/setup-sonar-scanner@v3
33+
uses: warchant/setup-sonar-scanner@v7
3034
- name: Send to Sonarcloud
3135
run: bundle exec fastlane sonarqube
3236
env:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@ fastlane/test_output
8888
# https://github.com/johnno1962/injectionforxcode
8989

9090
iOSInjectionProject/
91+
.swiftlint.yml

OSBarcodeLib.xcodeproj/project.pbxproj

Lines changed: 275 additions & 11 deletions
Large diffs are not rendered by default.

OSBarcodeLib.xcodeproj/xcshareddata/xcschemes/OSBarcodeLib.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1330"
3+
LastUpgradeVersion = "1500"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// Base class implemented by all classes that require UI interaction (push and dismiss operations).
2+
class OSBARCCoordinatable {
3+
/// Object responsible for managing the user interface screens and respective flow.
4+
private(set) var coordinator: OSBARCCoordinatorProtocol
5+
6+
/// Constructor.
7+
/// - Parameter coordinator: Object responsible for managing the user interface screens and respective flow.
8+
init(coordinator: OSBARCCoordinatorProtocol) {
9+
self.coordinator = coordinator
10+
}
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import UIKit
2+
3+
/// Object responsible for managing the screen flow, in response to the user's interaction.
4+
struct OSBARCCoordinator {
5+
/// Root view controller, from whom every view gets pushed on top of.
6+
private let rootViewController: UIViewController
7+
8+
/// Construtor.
9+
/// - Parameter rootViewController: Root view controller, from whom every view gets pushed on top of.
10+
init(rootViewController: UIViewController) {
11+
self.rootViewController = rootViewController
12+
}
13+
}
14+
15+
/// Implements the `OSBARCCoordinatorProtocol` methods
16+
extension OSBARCCoordinator: OSBARCCoordinatorProtocol {
17+
func present(_ viewController: UIViewController) {
18+
self.rootViewController.present(viewController, animated: true)
19+
}
20+
21+
func dismiss() {
22+
self.rootViewController.dismiss(animated: true)
23+
}
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import UIKit
2+
3+
/// Protocol that allows pushing and poping views on top of the root view controller.
4+
protocol OSBARCCoordinatorProtocol {
5+
/// Presents the passed view controller, adding it to the currently presented view controller array.
6+
/// - Parameter viewController: New view controller to present.
7+
func present(_ viewController: UIViewController)
8+
9+
/// Dismisses the currently presented view controllers. In case of a multiple step screen, all are dismissed.
10+
func dismiss()
11+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import Foundation
2+
3+
/// All errors related with the `OSBARCManager` structure.
4+
public enum OSBARCManagerError: Error {
5+
case cameraAccessDenied
6+
case scanningCancelled
7+
}
8+
9+
/// Structure responsible for managing all barcode scanning flow.
10+
struct OSBARCManager {
11+
/// Responsible for verifying the device's authorisation to its camera. It also handles the required flow to enable this authorisation.
12+
private let permissionsBehaviour: OSBARCPermissionsProtocol
13+
/// Responsible for triggering the barcode scanner view.
14+
private let scannerBehaviour: OSBARCScannerProtocol
15+
16+
/// Constructor.
17+
/// - Parameters:
18+
/// - permissionsBehaviour: Responsible for verifying the device's authorisation to its camera. It also handles the required flow to enable this authorisation.
19+
/// - scannerBehaviour: Responsible for triggering the barcode scanner view.
20+
init(permissionsBehaviour: OSBARCPermissionsProtocol, scannerBehaviour: OSBARCScannerProtocol) {
21+
self.permissionsBehaviour = permissionsBehaviour
22+
self.scannerBehaviour = scannerBehaviour
23+
}
24+
25+
/// Convenience constructor
26+
/// - Parameter coordinator: Object responsible for managing the screen flow, in response to the user's interaction.
27+
init(coordinator: OSBARCCoordinatorProtocol) {
28+
let permissionsBehaviour = OSBARCPermissionsBehaviour(coordinator: coordinator)
29+
let scannerBehaviour = OSBARCScannerBehaviour(coordinator: coordinator)
30+
self.init(permissionsBehaviour: permissionsBehaviour, scannerBehaviour: scannerBehaviour)
31+
}
32+
}
33+
34+
/// Implementation of the `OSBARCManagerProtocol` methods.
35+
extension OSBARCManager: OSBARCManagerProtocol {
36+
func scanBarcode(with instructionsText: String, _ buttonText: String?, _ cameraModel: OSBARCCameraModel, and orientationModel: OSBARCOrientationModel) async throws -> String {
37+
// validates if the user has access to the device's camera.
38+
let hasCameraAccess = await self.permissionsBehaviour.hasCameraAccess()
39+
if !hasCameraAccess { throw OSBARCManagerError.cameraAccessDenied }
40+
// requests the scanner to start, treating its result value.
41+
return try await withCheckedThrowingContinuation {
42+
self.startScanning(with: instructionsText, buttonText, cameraModel, and: orientationModel, continuation: $0)
43+
}
44+
}
45+
46+
/// Triggers the scanner view.
47+
/// - Parameters:
48+
/// - instructionsText: Text to be displayed on the scanner view.
49+
/// - buttonText: Text to be displayed for the scan button, if this is configured. `Nil` value means that the button will not be shown.
50+
/// - cameraModel: Camera to use for input gathering.
51+
/// - orientationModel: Scanner view's orientation.
52+
/// - continuation: Object responsible for returning the method's result to its caller.
53+
private func startScanning(
54+
with instructionsText: String,
55+
_ buttonText: String?,
56+
_ cameraModel: OSBARCCameraModel,
57+
and orientationModel: OSBARCOrientationModel,
58+
continuation: CheckedContinuation<String, any Error>
59+
) {
60+
DispatchQueue.main.async {
61+
self.scannerBehaviour.startScanning(with: instructionsText, buttonText, cameraModel, and: orientationModel) { scannedCode in
62+
if !scannedCode.isEmpty {
63+
continuation.resume(returning: scannedCode)
64+
} else {
65+
continuation.resume(throwing: OSBARCManagerError.scanningCancelled)
66+
}
67+
}
68+
}
69+
}
70+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import UIKit
2+
3+
/// Structure responsible for creating the scanner flow manager..
4+
public struct OSBARCManagerFactory {
5+
/// Creates the scanner flow manager.
6+
/// - Parameter rootViewController: Root view controller, from whom every view gets pushed on top of.
7+
/// - Returns: The resulting scanner flow manager.
8+
public static func createManager(with rootViewController: UIViewController) -> OSBARCManagerProtocol {
9+
let coordinator = OSBARCCoordinator(rootViewController: rootViewController)
10+
// it calls the `OSBARCManager`'s convenience constructor.
11+
return OSBARCManager(coordinator: coordinator)
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// Protocol that contains the main features of the library.
2+
public protocol OSBARCManagerProtocol {
3+
/// Triggers the barcode scanner, returning, if possible, the scanned value.
4+
/// It can throw:
5+
/// `cameraAccessDenied`: If camera access has not been given.
6+
/// `scanningCancelled`: If scanning has been cancelled.
7+
/// - Parameters:
8+
/// - instructionsText: Text to be displayed on the scanner view.
9+
/// - buttonText: Text to be displayed for the scan button, if this is configured. `Nil` value means that the button will not be shown.
10+
/// - cameraModel: Camera to use for input gathering.
11+
/// - orientationModel: Scanner view's orientation.
12+
/// - Returns: When successful, it returns the text associated with the scanned barcode.
13+
func scanBarcode(with instructionsText: String, _ buttonText: String?, _ cameraModel: OSBARCCameraModel, and orientationModel: OSBARCOrientationModel) async throws -> String
14+
}

0 commit comments

Comments
 (0)