Skip to content

Commit d17ab72

Browse files
committed
Remove configuration
1 parent b38de8f commit d17ab72

File tree

14 files changed

+141
-186
lines changed

14 files changed

+141
-186
lines changed

BarcodeScanner.xcodeproj/project.pbxproj

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
D55281C720168E7000FF3CDD /* NSLayoutConstraint+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55281C620168E7000FF3CDD /* NSLayoutConstraint+Extensions.swift */; };
2121
D5C4E08F1CA0BFB9008D9269 /* TorchMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C4E08D1CA0BFB9008D9269 /* TorchMode.swift */; };
2222
D5CB377F2017ED2E00B9319D /* VideoPermissionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5CB377E2017ED2E00B9319D /* VideoPermissionService.swift */; };
23-
D5F1C1C91C9C5113001E17A6 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F1C1C51C9C5113001E17A6 /* Config.swift */; };
23+
D5CB3783201944DE00B9319D /* AVMetadataObject+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5CB3782201944DE00B9319D /* AVMetadataObject+Extensions.swift */; };
24+
D5F1C1C91C9C5113001E17A6 /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F1C1C51C9C5113001E17A6 /* Functions.swift */; };
2425
D5FC8AD71D252A12004BED88 /* State.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5FC8AD61D252A12004BED88 /* State.swift */; };
2526
/* End PBXBuildFile section */
2627

@@ -40,7 +41,8 @@
4041
D5C4E08D1CA0BFB9008D9269 /* TorchMode.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = TorchMode.swift; sourceTree = "<group>"; tabWidth = 2; };
4142
D5C6298B1C3A8BBD007F7B7C /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = "<group>"; };
4243
D5CB377E2017ED2E00B9319D /* VideoPermissionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPermissionService.swift; sourceTree = "<group>"; };
43-
D5F1C1C51C9C5113001E17A6 /* Config.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; tabWidth = 2; };
44+
D5CB3782201944DE00B9319D /* AVMetadataObject+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVMetadataObject+Extensions.swift"; sourceTree = "<group>"; };
45+
D5F1C1C51C9C5113001E17A6 /* Functions.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = Functions.swift; sourceTree = "<group>"; tabWidth = 2; };
4446
D5FC8AD61D252A12004BED88 /* State.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = State.swift; sourceTree = "<group>"; tabWidth = 2; };
4547
/* End PBXFileReference section */
4648

@@ -82,6 +84,7 @@
8284
D55281C620168E7000FF3CDD /* NSLayoutConstraint+Extensions.swift */,
8385
D504555E1FD8714700E46826 /* UIView+Extensions.swift */,
8486
D55281BE20167DB400FF3CDD /* UIViewController+Extensions.swift */,
87+
D5CB3782201944DE00B9319D /* AVMetadataObject+Extensions.swift */,
8588
);
8689
path = Extensions;
8790
sourceTree = "<group>";
@@ -115,15 +118,31 @@
115118
D5C629691C3A809D007F7B7C /* Sources */ = {
116119
isa = PBXGroup;
117120
children = (
121+
D5CB3785201947D000B9319D /* Helpers */,
122+
D5CB37842019477900B9319D /* DataStructures */,
118123
D55281BD20167D9F00FF3CDD /* Extensions */,
119124
D55281B42016758000FF3CDD /* Controllers */,
125+
);
126+
path = Sources;
127+
sourceTree = "<group>";
128+
};
129+
D5CB37842019477900B9319D /* DataStructures */ = {
130+
isa = PBXGroup;
131+
children = (
120132
D5FC8AD61D252A12004BED88 /* State.swift */,
121133
D5C4E08D1CA0BFB9008D9269 /* TorchMode.swift */,
122134
2DBF9E0D1F169DEF006B5AA8 /* FocusViewType.swift */,
123-
D5F1C1C51C9C5113001E17A6 /* Config.swift */,
135+
);
136+
path = DataStructures;
137+
sourceTree = "<group>";
138+
};
139+
D5CB3785201947D000B9319D /* Helpers */ = {
140+
isa = PBXGroup;
141+
children = (
142+
D5F1C1C51C9C5113001E17A6 /* Functions.swift */,
124143
D5CB377E2017ED2E00B9319D /* VideoPermissionService.swift */,
125144
);
126-
path = Sources;
145+
path = Helpers;
127146
sourceTree = "<group>";
128147
};
129148
/* End PBXGroup section */
@@ -211,9 +230,10 @@
211230
D55281C720168E7000FF3CDD /* NSLayoutConstraint+Extensions.swift in Sources */,
212231
D55281BF20167DB400FF3CDD /* UIViewController+Extensions.swift in Sources */,
213232
D55281BA2016770800FF3CDD /* CameraViewController.swift in Sources */,
214-
D5F1C1C91C9C5113001E17A6 /* Config.swift in Sources */,
233+
D5F1C1C91C9C5113001E17A6 /* Functions.swift in Sources */,
215234
D55281B8201675D500FF3CDD /* MessageViewController.swift in Sources */,
216235
D55281BC2016782C00FF3CDD /* BarcodeScannerViewController.swift in Sources */,
236+
D5CB3783201944DE00B9319D /* AVMetadataObject+Extensions.swift in Sources */,
217237
D5CB377F2017ED2E00B9319D /* VideoPermissionService.swift in Sources */,
218238
2DBF9E0E1F169DEF006B5AA8 /* FocusViewType.swift in Sources */,
219239
D504555F1FD8714700E46826 /* UIView+Extensions.swift in Sources */,

Example/BarcodeScannerExample/BarcodeScannerExample/AppDelegate.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import BarcodeScanner
33

44
@UIApplicationMain
55
class AppDelegate: UIResponder, UIApplicationDelegate {
6-
76
var window: UIWindow?
87
func application(_ application: UIApplication,
98
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
import UIKit
22
import BarcodeScanner
33

4-
class ViewController: UIViewController {
5-
4+
final class ViewController: UIViewController {
65
@IBOutlet var presentScannerButton: UIButton!
76
@IBOutlet var pushScannerButton: UIButton!
87

98
@IBAction func handleScannerPresent(_ sender: Any, forEvent event: UIEvent) {
10-
let controller = makeBarcodeScannerController()
9+
let controller = makeBarcodeScannerViewController()
1110
controller.title = "Barcode Scanner"
1211
present(controller, animated: true, completion: nil)
1312
}
1413

1514
@IBAction func handleScannerPush(_ sender: Any, forEvent event: UIEvent) {
16-
let controller = makeBarcodeScannerController()
15+
let controller = makeBarcodeScannerViewController()
1716
controller.title = "Barcode Scanner"
1817
navigationController?.pushViewController(controller, animated: true)
1918
}
2019

21-
private func makeBarcodeScannerController() -> ScannerController {
22-
let controller = ScannerController()
23-
controller.codeDelegate = self
24-
controller.errorDelegate = self
25-
controller.dismissalDelegate = self
26-
return controller
20+
private func makeBarcodeScannerViewController() -> BarcodeScannerViewController {
21+
let viewController = BarcodeScannerViewController()
22+
viewController.codeDelegate = self
23+
viewController.errorDelegate = self
24+
viewController.dismissalDelegate = self
25+
return viewController
2726
}
2827
}
2928

30-
extension ViewController: ScannerCodeDelegate {
29+
// MARK: - BarcodeScannerCodeDelegate
3130

32-
func scanner(_ controller: ScannerController, didCaptureCode code: String, type: String) {
31+
extension ViewController: BarcodeScannerCodeDelegate {
32+
func scanner(_ controller: BarcodeScannerViewController, didCaptureCode code: String, type: String) {
3333
print("Barcode Data: \(code)")
3434
print("Symbology Type: \(type)")
3535

@@ -40,16 +40,18 @@ extension ViewController: ScannerCodeDelegate {
4040
}
4141
}
4242

43-
extension ViewController: ScannerErrorDelegate {
43+
// MARK: - BarcodeScannerErrorDelegate
4444

45-
func scanner(_ controller: ScannerController, didReceiveError error: Error) {
45+
extension ViewController: BarcodeScannerErrorDelegate {
46+
func scanner(_ controller: BarcodeScannerViewController, didReceiveError error: Error) {
4647
print(error)
4748
}
4849
}
4950

50-
extension ViewController: ScannerDismissalDelegate {
51+
// MARK: - BarcodeScannerDismissalDelegate
5152

52-
func scannerDidDismiss(_ controller: ScannerController) {
53+
extension ViewController: BarcodeScannerDismissalDelegate {
54+
func scannerDidDismiss(_ controller: BarcodeScannerViewController) {
5355
controller.dismiss(animated: true, completion: nil)
5456
}
5557
}

Sources/Config.swift

Lines changed: 0 additions & 102 deletions
This file was deleted.

Sources/Controllers/BarcodeScannerViewController.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ open class BarcodeScannerViewController: UIViewController {
4040
public weak var errorDelegate: BarcodeScannerErrorDelegate?
4141
/// Delegate to dismiss barcode scanner when the close button has been pressed.
4242
public weak var dismissalDelegate: BarcodeScannerDismissalDelegate?
43+
/// `AVCaptureMetadataOutput` metadata object types.
44+
public var metadata = AVMetadataObject.ObjectType.barcodeScannerMetadata {
45+
didSet {
46+
cameraViewController.metadata = metadata
47+
}
48+
}
49+
50+
// MARK: - Private properties
51+
4352
/// Flag to lock session from capturing.
4453
private var locked = false
4554

@@ -75,6 +84,7 @@ open class BarcodeScannerViewController: UIViewController {
7584
open override func viewDidLoad() {
7685
super.viewDidLoad()
7786
view.backgroundColor = UIColor.black
87+
cameraViewController.metadata = metadata
7888
cameraViewController.delegate = self
7989

8090
add(childViewController: cameraViewController)

Sources/Controllers/CameraViewController.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ final class CameraViewController: UIViewController {
1616
weak var delegate: CameraViewControllerDelegate?
1717
/// Focus view type.
1818
var barCodeFocusViewType: FocusViewType = .animated
19+
/// `AVCaptureMetadataOutput` metadata object types.
20+
var metadata = [AVMetadataObject.ObjectType]()
1921

2022
// MARK: - UI
2123

@@ -327,8 +329,8 @@ private extension CameraViewController {
327329
func makeSettingsButton() -> UIButton {
328330
let button = UIButton(type: .system)
329331
let title = NSAttributedString(
330-
string: SettingsButton.text,
331-
attributes: [.font : SettingsButton.font, .foregroundColor : SettingsButton.color]
332+
string: localizedString("BUTTON_SETTINGS"),
333+
attributes: [.font: UIFont.boldSystemFont(ofSize: 17), .foregroundColor : UIColor.white]
332334
)
333335
button.setAttributedTitle(title, for: UIControlState())
334336
button.sizeToFit()

Sources/Controllers/HeaderViewController.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private extension HeaderViewController {
5757
func makeNavigationBar() -> UINavigationBar {
5858
let navigationBar = UINavigationBar()
5959
navigationBar.isTranslucent = false
60-
navigationBar.backgroundColor = Title.backgroundColor
60+
navigationBar.backgroundColor = .white
6161
navigationBar.items = [makeNavigationItem()]
6262
return navigationBar
6363
}
@@ -73,19 +73,19 @@ private extension HeaderViewController {
7373

7474
func makeTitleLabel() -> UILabel {
7575
let label = UILabel()
76-
label.text = Title.text
77-
label.font = Title.font
78-
label.textColor = Title.color
76+
label.text = localizedString("SCAN_BARCODE_TITLE")
77+
label.font = UIFont.boldSystemFont(ofSize: 17)
78+
label.textColor = .black
7979
label.numberOfLines = 1
8080
label.textAlignment = .center
8181
return label
8282
}
8383

8484
func makeCloseButton() -> UIButton {
8585
let button = UIButton(type: .system)
86-
button.setTitle(CloseButton.text, for: UIControlState())
87-
button.titleLabel?.font = CloseButton.font
88-
button.tintColor = CloseButton.color
86+
button.setTitle(localizedString("BUTTON_CLOSE"), for: UIControlState())
87+
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
88+
button.tintColor = .black
8989
return button
9090
}
9191
}

Sources/Controllers/MessageViewController.swift

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import UIKit
22

3-
public enum MessageStyle {
4-
case initial
5-
case loading
6-
case error
7-
}
8-
93
public final class MessageViewController: UIViewController {
104
// Blur effect view.
115
private lazy var blurView: UIVisualEffectView = .init(effect: UIBlurEffect(style: .extraLight))
@@ -19,6 +13,9 @@ public final class MessageViewController: UIViewController {
1913
private lazy var collapsedConstraints: [NSLayoutConstraint] = self.makeCollapsedConstraints()
2014
private lazy var expandedConstraints: [NSLayoutConstraint] = self.makeExpandedConstraints()
2115

16+
public var regularTintColor: UIColor = .black
17+
public var errorTintColor: UIColor = .red
18+
2219
var state: State = .scanning {
2320
didSet {
2421
handleStateUpdate()
@@ -61,30 +58,25 @@ public final class MessageViewController: UIViewController {
6158
private func handleStateUpdate() {
6259
borderView.isHidden = true
6360
borderView.layer.removeAllAnimations()
61+
textLabel.text = state.text
6462

6563
switch state {
6664
case .scanning, .unauthorized:
67-
textLabel.text = state == .scanning ? Info.text : Info.settingsText
68-
textLabel.textColor = .black
6965
textLabel.font = UIFont.boldSystemFont(ofSize: 14)
7066
textLabel.numberOfLines = 3
7167
textLabel.textAlignment = .left
72-
imageView.tintColor = .black
68+
imageView.tintColor = regularTintColor
7369
case .processing:
74-
textLabel.text = Info.loadingText
75-
textLabel.textColor = .black
7670
textLabel.font = UIFont.boldSystemFont(ofSize: 16)
7771
textLabel.numberOfLines = 10
7872
textLabel.textAlignment = .center
7973
borderView.isHidden = false
80-
imageView.tintColor = .black
74+
imageView.tintColor = regularTintColor
8175
case .notFound:
82-
textLabel.text = Info.notFoundText
83-
textLabel.textColor = .black
8476
textLabel.font = UIFont.boldSystemFont(ofSize: 16)
8577
textLabel.numberOfLines = 10
8678
textLabel.textAlignment = .center
87-
imageView.tintColor = .red
79+
imageView.tintColor = errorTintColor
8880
}
8981

9082
if state == .scanning || state == .unauthorized {
File renamed without changes.

0 commit comments

Comments
 (0)