Skip to content

Commit 71d90a7

Browse files
committed
Add property to show/hide camera button
1 parent e34635e commit 71d90a7

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

Sources/Controllers/BarcodeScannerViewController.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import AVFoundation
55

66
/// Delegate to handle the captured code.
77
public protocol BarcodeScannerCodeDelegate: class {
8-
func scanner(_ controller: BarcodeScannerViewController, didCaptureCode code: String, type: String)
8+
func scanner(
9+
_ controller: BarcodeScannerViewController,
10+
didCaptureCode code: String,
11+
type: String
12+
)
913
}
1014

1115
/// Delegate to report errors.
@@ -28,6 +32,7 @@ public protocol BarcodeScannerDismissalDelegate: class {
2832
- Not found error message
2933
*/
3034
open class BarcodeScannerViewController: UIViewController {
35+
private static let footerHeight: CGFloat = 75
3136

3237
// MARK: - Public properties
3338

@@ -66,9 +71,9 @@ open class BarcodeScannerViewController: UIViewController {
6671
public private(set) lazy var cameraViewController: CameraViewController = .init()
6772

6873
// Constraints that are activated when the view is used as a footer.
69-
private lazy var collapsedConstraints: [NSLayoutConstraint] = self.makeCollapsedMessageConstraints()
74+
private lazy var collapsedConstraints: [NSLayoutConstraint] = self.makeCollapsedConstraints()
7075
// Constraints that are activated when the view is used for loading animation and error messages.
71-
private lazy var expandedConstraints: [NSLayoutConstraint] = self.makeExpandedMessageConstraints()
76+
private lazy var expandedConstraints: [NSLayoutConstraint] = self.makeExpandedConstraints()
7277

7378
private var messageView: UIView {
7479
return messageViewController.view
@@ -220,7 +225,10 @@ private extension BarcodeScannerViewController {
220225
NSLayoutConstraint.activate(
221226
cameraView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
222227
cameraView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
223-
cameraView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -75)
228+
cameraView.bottomAnchor.constraint(
229+
equalTo: view.bottomAnchor,
230+
constant: -BarcodeScannerViewController.footerHeight
231+
)
224232
)
225233

226234
if navigationController != nil {
@@ -241,7 +249,7 @@ private extension BarcodeScannerViewController {
241249
}
242250
}
243251

244-
private func makeExpandedMessageConstraints() -> [NSLayoutConstraint] {
252+
private func makeExpandedConstraints() -> [NSLayoutConstraint] {
245253
return [
246254
messageView.topAnchor.constraint(equalTo: view.topAnchor),
247255
messageView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
@@ -250,12 +258,14 @@ private extension BarcodeScannerViewController {
250258
]
251259
}
252260

253-
private func makeCollapsedMessageConstraints() -> [NSLayoutConstraint] {
261+
private func makeCollapsedConstraints() -> [NSLayoutConstraint] {
254262
return [
255263
messageView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
256264
messageView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
257265
messageView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
258-
messageView.heightAnchor.constraint(equalToConstant: 75)
266+
messageView.heightAnchor.constraint(
267+
equalToConstant: BarcodeScannerViewController.footerHeight
268+
)
259269
]
260270
}
261271
}

Sources/Controllers/CameraViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public final class CameraViewController: UIViewController {
1919

2020
/// Focus view type.
2121
public var barCodeFocusViewType: FocusViewType = .animated
22+
public var showsCameraButton: Bool = false {
23+
didSet {
24+
cameraButton.isHidden = showsCameraButton
25+
}
26+
}
2227
/// `AVCaptureMetadataOutput` metadata object types.
2328
var metadata = [AVMetadataObject.ObjectType]()
2429

@@ -411,6 +416,7 @@ private extension CameraViewController {
411416
func makeCameraButton() -> UIButton {
412417
let button = UIButton(type: .custom)
413418
button.setImage(imageNamed("cameraRotate"), for: UIControlState())
419+
button.isHidden = showsCameraButton
414420
return button
415421
}
416422
}

0 commit comments

Comments
 (0)