@@ -28,18 +28,17 @@ public protocol BarcodeScannerDismissalDelegate: class {
2828 - Not found error message
2929 */
3030open class BarcodeScannerController : UIViewController {
31-
3231 /// Video capture device. This may be nil when running in Simulator.
33- lazy var captureDevice : AVCaptureDevice ! = AVCaptureDevice . default ( for: AVMediaType . video)
32+ private lazy var captureDevice : AVCaptureDevice ! = AVCaptureDevice . default ( for: AVMediaType . video)
3433
3534 /// Capture session.
36- lazy var captureSession : AVCaptureSession = AVCaptureSession ( )
35+ private lazy var captureSession : AVCaptureSession = AVCaptureSession ( )
3736
3837 /// Header view with title and close button.
39- lazy var headerView : HeaderView = HeaderView ( )
38+ private lazy var headerView : HeaderView = HeaderView ( )
4039
4140 /// Information view with description label.
42- lazy var infoView : InfoView = InfoView ( )
41+ private lazy var infoView : InfoView = InfoView ( )
4342
4443 /// Button to change torch mode.
4544 public lazy var flashButton : UIButton = { [ unowned self] in
@@ -49,7 +48,7 @@ open class BarcodeScannerController: UIViewController {
4948 } ( )
5049
5150 /// Animated focus view.
52- lazy var focusView : UIView = {
51+ private lazy var focusView : UIView = {
5352 let view = UIView ( )
5453 view. layer. borderColor = UIColor . white. cgColor
5554 view. layer. borderWidth = 2
@@ -64,7 +63,7 @@ open class BarcodeScannerController: UIViewController {
6463 } ( )
6564
6665 /// Button that opens settings to allow camera usage.
67- lazy var settingsButton : UIButton = { [ unowned self] in
66+ private lazy var settingsButton : UIButton = { [ unowned self] in
6867 let button = UIButton ( type: . system)
6968 let title = NSAttributedString ( string: SettingsButton . text,
7069 attributes: [
@@ -80,10 +79,10 @@ open class BarcodeScannerController: UIViewController {
8079 } ( )
8180
8281 /// Video preview layer.
83- var videoPreviewLayer : AVCaptureVideoPreviewLayer ?
82+ private var videoPreviewLayer : AVCaptureVideoPreviewLayer ?
8483
8584 /// The current controller's status mode.
86- var status : Status = Status ( state: . scanning) {
85+ private var status : Status = Status ( state: . scanning) {
8786 didSet {
8887 let duration = status. animated &&
8988 ( status. state == . processing
@@ -128,7 +127,7 @@ open class BarcodeScannerController: UIViewController {
128127 public var barCodeFocusViewType : FocusViewType = . animated
129128
130129 /// The current torch mode on the capture device.
131- var torchMode : TorchMode = . off {
130+ private var torchMode : TorchMode = . off {
132131 didSet {
133132 guard let captureDevice = captureDevice, captureDevice. hasFlash else { return }
134133
@@ -143,7 +142,7 @@ open class BarcodeScannerController: UIViewController {
143142 }
144143
145144 /// Calculated frame for the info view.
146- var infoFrame : CGRect {
145+ private var infoFrame : CGRect {
147146 let height = status. state != . processing ? 75 : view. bounds. height
148147 return CGRect ( x: 0 , y: view. bounds. height - height,
149148 width: view. bounds. width, height: height)
@@ -163,7 +162,7 @@ open class BarcodeScannerController: UIViewController {
163162 public weak var dismissalDelegate : BarcodeScannerDismissalDelegate ?
164163
165164 /// Flag to lock session from capturing.
166- var locked = false
165+ private var locked = false
167166
168167 // MARK: - Initialization
169168
@@ -228,7 +227,7 @@ open class BarcodeScannerController: UIViewController {
228227 /**
229228 `UIApplicationWillEnterForegroundNotification` action.
230229 */
231- @objc func appWillEnterForeground( ) {
230+ @objc private func appWillEnterForeground( ) {
232231 torchMode = . off
233232 animateFocusView ( )
234233 }
@@ -238,7 +237,7 @@ open class BarcodeScannerController: UIViewController {
238237 /**
239238 Sets up camera and checks for camera permissions.
240239 */
241- func setupCamera( ) {
240+ private func setupCamera( ) {
242241 let authorizationStatus = AVCaptureDevice . authorizationStatus ( for: AVMediaType . video)
243242
244243 if authorizationStatus == . authorized {
@@ -263,7 +262,7 @@ open class BarcodeScannerController: UIViewController {
263262 /**
264263 Sets up capture input, output and session.
265264 */
266- func setupSession( ) {
265+ private func setupSession( ) {
267266 guard let captureDevice = captureDevice else {
268267 return
269268 }
@@ -307,7 +306,7 @@ open class BarcodeScannerController: UIViewController {
307306 /**
308307 Resets the current state.
309308 */
310- func resetState( ) {
309+ private func resetState( ) {
311310 let alpha : CGFloat = status. state == . scanning ? 1 : 0
312311
313312 torchMode = . off
@@ -323,32 +322,25 @@ open class BarcodeScannerController: UIViewController {
323322 }
324323
325324 // MARK: - Layout
326- func setupFrame( ) {
325+ private func setupFrame( ) {
327326 let flashButtonSize : CGFloat = 37
328327 let isLandscape = view. frame. width > view. frame. height
328+ let insets = view. viewInsets
329+ // On iPhone X devices, extend the size of the top nav bar
330+ let navbarSize : CGFloat = isLandscape ? 32 : insets. top > 0 ? 88 : 64
329331
330- var rightSafeAreaInset : CGFloat = 0
331- var topSafeAreaInset : CGFloat = 0
332- if #available( iOS 11 . 0 , * ) {
333- rightSafeAreaInset = view. safeAreaInsets. right
334- topSafeAreaInset = view. safeAreaInsets. top
335- }
336-
337- var navbarSize : CGFloat = 0
338- if ( isLandscape) {
339- navbarSize = 32
340- }
341- else {
342- // On iPhone X devices, extend the size of the top nav bar
343- navbarSize = topSafeAreaInset > 0 ? 88 : 64
344- }
345-
346332 headerView. frame = CGRect ( x: 0 , y: 0 , width: view. frame. width, height: navbarSize)
347- flashButton. frame = CGRect ( x: view. frame. width - 50 - rightSafeAreaInset, y: navbarSize + 10 + ( flashButtonSize / 2 ) , width: flashButtonSize, height: flashButtonSize)
333+ flashButton. frame = CGRect (
334+ x: view. frame. width - 50 - insets. right,
335+ y: navbarSize + 10 + ( flashButtonSize / 2 ) ,
336+ width: flashButtonSize,
337+ height: flashButtonSize
338+ )
348339 infoView. frame = infoFrame
349340
350341 if let videoPreviewLayer = videoPreviewLayer {
351342 videoPreviewLayer. frame = view. layer. bounds
343+
352344 if let connection = videoPreviewLayer. connection, connection. isVideoOrientationSupported {
353345 switch ( UIApplication . shared. statusBarOrientation) {
354346 case . portrait: connection. videoOrientation = . portrait
@@ -365,6 +357,7 @@ open class BarcodeScannerController: UIViewController {
365357 } else {
366358 center ( subview: focusView, inSize: CGSize ( width: 218 , height: 150 ) )
367359 }
360+
368361 center ( subview: settingsButton, inSize: CGSize ( width: 150 , height: 50 ) )
369362 }
370363
@@ -374,12 +367,13 @@ open class BarcodeScannerController: UIViewController {
374367 - Parameter subview: The subview.
375368 - Parameter size: A new size.
376369 */
377- func center( subview: UIView , inSize size: CGSize ) {
370+ private func center( subview: UIView , inSize size: CGSize ) {
378371 subview. frame = CGRect (
379372 x: ( view. frame. width - size. width) / 2 ,
380373 y: ( view. frame. height - size. height) / 2 ,
381374 width: size. width,
382- height: size. height)
375+ height: size. height
376+ )
383377 }
384378
385379 // MARK: - Animations
@@ -389,7 +383,7 @@ open class BarcodeScannerController: UIViewController {
389383
390384 - Parameter processing: Flag to set the current state to `.Processing`.
391385 */
392- func animateFlash( whenProcessing: Bool = false ) {
386+ private func animateFlash( whenProcessing: Bool = false ) {
393387 let flashView = UIView ( frame: view. bounds)
394388 flashView. backgroundColor = UIColor . white
395389 flashView. alpha = 1
@@ -413,7 +407,7 @@ open class BarcodeScannerController: UIViewController {
413407 /**
414408 Performs focus view animation.
415409 */
416- func animateFocusView( ) {
410+ private func animateFocusView( ) {
417411 focusView. layer. removeAllAnimations ( )
418412 focusView. isHidden = false
419413
@@ -434,7 +428,7 @@ open class BarcodeScannerController: UIViewController {
434428 /**
435429 Opens setting to allow camera usage.
436430 */
437- @objc func settingsButtonDidPress( ) {
431+ @objc private func settingsButtonDidPress( ) {
438432 DispatchQueue . main. async {
439433 if let settingsURL = URL ( string: UIApplicationOpenSettingsURLString) {
440434 UIApplication . shared. openURL ( settingsURL)
@@ -445,16 +439,17 @@ open class BarcodeScannerController: UIViewController {
445439 /**
446440 Sets the next torch mode.
447441 */
448- @objc func flashButtonDidPress( ) {
442+ @objc private func flashButtonDidPress( ) {
449443 torchMode = torchMode. next
450444 }
451445}
452446
453447// MARK: - AVCaptureMetadataOutputObjectsDelegate
454448
455449extension BarcodeScannerController : AVCaptureMetadataOutputObjectsDelegate {
456-
457- public func metadataOutput( _ output: AVCaptureMetadataOutput , didOutput metadataObjects: [ AVMetadataObject ] , from connection: AVCaptureConnection ) {
450+ public func metadataOutput( _ output: AVCaptureMetadataOutput ,
451+ didOutput metadataObjects: [ AVMetadataObject ] ,
452+ from connection: AVCaptureConnection ) {
458453 guard !locked else { return }
459454 guard !metadataObjects. isEmpty else { return }
460455
@@ -485,7 +480,6 @@ extension BarcodeScannerController: AVCaptureMetadataOutputObjectsDelegate {
485480// MARK: - HeaderViewDelegate
486481
487482extension BarcodeScannerController : HeaderViewDelegate {
488-
489483 func headerViewDidPressClose( _ headerView: HeaderView ) {
490484 dismissalDelegate? . barcodeScannerDidDismiss ( self )
491485 }
0 commit comments