Skip to content

Commit 752dbe6

Browse files
authored
Merge pull request #89 from hyperoslo/refactor/documentation-tools
Refactoring: update documentation
2 parents a333fcc + 1b4217c commit 752dbe6

15 files changed

+276
-263
lines changed

Example/BarcodeScannerExample/BarcodeScannerExample/ViewController.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ final class ViewController: UIViewController {
66
@IBOutlet var pushScannerButton: UIButton!
77

88
@IBAction func handleScannerPresent(_ sender: Any, forEvent event: UIEvent) {
9-
let controller = makeBarcodeScannerViewController()
10-
controller.title = "Barcode Scanner"
11-
present(controller, animated: true, completion: nil)
9+
let viewController = makeBarcodeScannerViewController()
10+
viewController.title = "Barcode Scanner"
11+
present(viewController, animated: true, completion: nil)
1212
}
1313

1414
@IBAction func handleScannerPush(_ sender: Any, forEvent event: UIEvent) {
15-
let controller = makeBarcodeScannerViewController()
16-
controller.title = "Barcode Scanner"
17-
navigationController?.pushViewController(controller, animated: true)
15+
let viewController = makeBarcodeScannerViewController()
16+
viewController.title = "Barcode Scanner"
17+
navigationController?.pushViewController(viewController, animated: true)
1818
}
1919

2020
private func makeBarcodeScannerViewController() -> BarcodeScannerViewController {
@@ -33,8 +33,7 @@ extension ViewController: BarcodeScannerCodeDelegate {
3333
print("Barcode Data: \(code)")
3434
print("Symbology Type: \(type)")
3535

36-
let delayTime = DispatchTime.now() + Double(Int64(6 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
37-
DispatchQueue.main.asyncAfter(deadline: delayTime) {
36+
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
3837
controller.resetWithError()
3938
}
4039
}

README.md

Lines changed: 75 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,29 @@ barcode capturing functionality and a great user experience.
3939

4040
### Controller
4141

42-
To start capturing just instantiate `BarcodeScannerController`, set needed
42+
To start capturing just instantiate `BarcodeScannerViewController`, set needed
4343
delegates and present it:
4444

4545
```swift
46-
let controller = BarcodeScannerController()
47-
controller.codeDelegate = self
48-
controller.errorDelegate = self
49-
controller.dismissalDelegate = self
46+
let viewController = BarcodeScannerViewController()
47+
viewController.codeDelegate = self
48+
viewController.errorDelegate = self
49+
viewController.dismissalDelegate = self
5050

51-
present(controller, animated: true, completion: nil)
51+
present(viewController, animated: true, completion: nil)
5252
```
5353

5454
<div align="center">
5555
<img src="https://github.com/hyperoslo/BarcodeScanner/blob/master/Art/ExampleScanning.png" alt="BarcodeScanner scanning" width="270" height="480" />
5656
</div><br/>
5757

58-
You can also push `BarcodeScannerController` to your navigation stack:
58+
You can also push `BarcodeScannerViewController` to your navigation stack:
5959

6060
```swift
61-
let controller = BarcodeScannerController()
62-
controller.codeDelegate = self
61+
let viewController = BarcodeScannerViewController()
62+
viewController.codeDelegate = self
6363

64-
navigationController?.pushViewController(controller, animated: true)
64+
navigationController?.pushViewController(viewController, animated: true)
6565
```
6666

6767
### Delegates
@@ -72,8 +72,7 @@ Use `BarcodeScannerCodeDelegate` when you want to get the captured code back.
7272

7373
```swift
7474
extension ViewController: BarcodeScannerCodeDelegate {
75-
76-
func barcodeScanner(_ controller: BarcodeScannerController, didCaptureCode code: String, type: String) {
75+
func barcodeScanner(_ controller: BarcodeScannerViewController, didCaptureCode code: String, type: String) {
7776
print(code)
7877
controller.reset()
7978
}
@@ -85,8 +84,7 @@ extension ViewController: BarcodeScannerCodeDelegate {
8584
Use `BarcodeScannerErrorDelegate` when you want to handle session errors.
8685
```swift
8786
extension ViewController: BarcodeScannerErrorDelegate {
88-
89-
func barcodeScanner(_ controller: BarcodeScannerController, didReceiveError error: Error) {
87+
func barcodeScanner(_ controller: BarcodeScannerViewController, didReceiveError error: Error) {
9088
print(error)
9189
}
9290
}
@@ -95,97 +93,107 @@ extension ViewController: BarcodeScannerErrorDelegate {
9593
**Dismissal delegate**
9694

9795
Use `BarcodeScannerDismissalDelegate` to handle "Close button" tap.
98-
**Please note** that `BarcodeScannerController` doesn't dismiss itself if it was
99-
presented initially.
96+
**Please note** that `BarcodeScannerViewController` doesn't dismiss itself if
97+
it was presented initially.
10098

10199
```swift
102100
extension ViewController: BarcodeScannerDismissalDelegate {
103-
104-
func barcodeScannerDidDismiss(_ controller: BarcodeScannerController) {
101+
func barcodeScannerDidDismiss(_ controller: BarcodeScannerViewController) {
105102
controller.dismiss(animated: true, completion: nil)
106103
}
107104
}
108105
```
109106

110107
### Actions
111108

112-
When the code is captured `BarcodeScannerController` switches to the processing
109+
When the code is captured `BarcodeScannerViewController` switches to the processing
113110
mode:
114111

115112
<div align="center">
116113
<img src="https://github.com/hyperoslo/BarcodeScanner/blob/master/Art/ExampleLoading.png" alt="BarcodeScanner loading" width="270" height="480" />
117114
</div><br/>
118115

119-
While the user see a nice loading animation you can perform some
116+
While the user sees a nice loading animation you can perform some
120117
background task, for example make a network request to fetch product info based
121118
on the code. When the task is done you have 3 options to proceed:
122119

123-
1. Dismiss `BarcodeScannerController` and show your results.
120+
1. Dismiss `BarcodeScannerViewController` and show your results.
121+
122+
```swift
123+
func barcodeScanner(_ controller: BarcodeScannerViewController, didCaptureCode code: String, type: String) {
124+
// Code processing
125+
controller.dismiss(animated: true, completion: nil)
126+
}
127+
```
124128

125-
```swift
126-
func barcodeScanner(_ controller: BarcodeScannerController, didCaptureCode code: String, type: String) {
127-
// Code processing
128-
controller.dismiss(animated: true, completion: nil)
129-
}
130-
```
131129
2. Show an error message and switch back to the scanning mode (for example,
132130
when there is no product found with a given barcode in your database):
133131

134-
<div align="center">
135-
<img src="https://github.com/hyperoslo/BarcodeScanner/blob/master/Art/ExampleError.png" alt="BarcodeScanner error" width="270" height="480" />
136-
</div><br/>
132+
<div align="center">
133+
<img src="https://github.com/hyperoslo/BarcodeScanner/blob/master/Art/ExampleError.png" alt="BarcodeScanner error" width="270" height="480" />
134+
</div><br/>
135+
136+
```swift
137+
func barcodeScanner(_ controller: BarcodeScannerViewController, didCaptureCode code: String, type: String) {
138+
// Code processing
139+
controller.resetWithError(message: "Error message")
140+
// If message is not provided the default message will be used instead.
141+
}
142+
```
137143

138-
```swift
139-
func barcodeScanner(_ controller: BarcodeScannerController, didCaptureCode code: String, type: String) {
140-
// Code processing
141-
controller.resetWithError(message: "Error message")
142-
// If message is not provided the default message from the config will be used instead.
143-
}
144-
```
145144
3. Reset the controller to the scanning mode (with or without animation):
146145

147146
```swift
148-
func barcodeScanner(_ controller: BarcodeScannerController, didCaptureCode code: String, type: String) {
147+
func barcodeScanner(_ controller: BarcodeScannerViewController, didCaptureCode code: String, type: String) {
149148
// Code processing
150149
controller.reset(animated: true)
151150
}
152151
```
153152

154153
If you want to do continuous barcode scanning just set the `isOneTimeSearch`
155-
property on your `BarcodeScannerController` instance to `false`.
154+
property on your `BarcodeScannerViewController` instance to `false`.
156155

157156
### Customization
158157

159-
We styled **BarcodeScanner** to make it look nice, but feel free to customize
160-
its appearance by changing global configuration variables:
158+
We styled **BarcodeScanner** to make it look nice, but you can always use public
159+
properties or inheritance to customize its appearance.
160+
161+
**Header**
162+
163+
```swift
164+
let viewController = BarcodeScannerViewController()
165+
viewController.headerViewController.titleLabel.text = "Scan barcode"
166+
viewController.headerViewController.closeButton.tintColor = .red
167+
```
168+
169+
**Please note** that `HeaderViewController` is visible only when
170+
`BarcodeScannerViewController` is being presented.
171+
172+
**Footer and messages**
173+
174+
```swift
175+
let viewController = BarcodeScannerViewController()
176+
viewController.messageViewController.regularTintColor = .black
177+
viewController.messageViewController.errorTintColor = .red
178+
viewController.messageViewController.textLabel.textColor = .black
179+
```
180+
181+
**Camera**
182+
```swift
183+
let viewController = BarcodeScannerViewController()
184+
viewController.barCodeFocusViewType = .animated
185+
let title = NSAttributedString(
186+
string: "Settings",
187+
attributes: [.font: UIFont.boldSystemFont(ofSize: 17), .foregroundColor : UIColor.white]
188+
)
189+
viewController.settingButton.setAttributedTitle(title, for: UIControlState())
190+
```
161191

192+
**Metadata**
162193
```swift
163-
// Strings
164-
BarcodeScanner.Title.text = NSLocalizedString("Scan barcode", comment: "")
165-
BarcodeScanner.CloseButton.text = NSLocalizedString("Close", comment: "")
166-
BarcodeScanner.SettingsButton.text = NSLocalizedString("Settings", comment: "")
167-
BarcodeScanner.Info.text = NSLocalizedString(
168-
"Place the barcode within the window to scan. The search will start automatically.", comment: "")
169-
BarcodeScanner.Info.loadingText = NSLocalizedString("Looking for your product...", comment: "")
170-
BarcodeScanner.Info.notFoundText = NSLocalizedString("No product found.", comment: "")
171-
BarcodeScanner.Info.settingsText = NSLocalizedString(
172-
"In order to scan barcodes you have to allow camera under your settings.", comment: "")
173-
174-
// Fonts
175-
BarcodeScanner.Title.font = UIFont.boldSystemFont(ofSize: 17)
176-
BarcodeScanner.CloseButton.font = UIFont.boldSystemFont(ofSize: 17)
177-
BarcodeScanner.SettingsButton.font = UIFont.boldSystemFont(ofSize: 17)
178-
BarcodeScanner.Info.font = UIFont.boldSystemFont(ofSize: 14)
179-
BarcodeScanner.Info.loadingFont = UIFont.boldSystemFont(ofSize: 16)
180-
181-
// Colors
182-
BarcodeScanner.Title.color = UIColor.black
183-
BarcodeScanner.CloseButton.color = UIColor.black
184-
BarcodeScanner.SettingsButton.color = UIColor.white
185-
BarcodeScanner.Info.textColor = UIColor.black
186-
BarcodeScanner.Info.tint = UIColor.black
187-
BarcodeScanner.Info.loadingTint = UIColor.black
188-
BarcodeScanner.Info.notFoundTint = UIColor.red
194+
// Add extra metadata object type
195+
let viewController = BarcodeScannerViewController()
196+
viewController.metadata.append(AVMetadataObject.ObjectType.qr)
189197
```
190198

191199
## Installation

0 commit comments

Comments
 (0)