Skip to content
This repository was archived by the owner on Nov 24, 2021. It is now read-only.

Commit 56834b9

Browse files
authored
Merge pull request #145 from mronus/master
Add dynamic background colour
2 parents 21e7774 + f66807b commit 56834b9

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

Source/ViewableController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ class ViewableController: UIViewController {
116116
var viewable: Viewable?
117117
var indexPath: IndexPath?
118118

119+
var viewableBackgroundColor: UIColor = .black
120+
119121
var playerViewController: AVPlayerViewController?
120122

121123
var hasZoomed: Bool {
@@ -172,7 +174,7 @@ class ViewableController: UIViewController {
172174
super.viewDidLoad()
173175

174176
self.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
175-
self.view.backgroundColor = .black
177+
self.view.backgroundColor = self.viewableBackgroundColor
176178

177179
self.zoomingScrollView.addSubview(self.imageView)
178180
self.view.addSubview(self.zoomingScrollView)

Source/ViewerController.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public class ViewerController: UIViewController {
5454
*/
5555
public var autoplayVideos: Bool = false
5656

57+
/**
58+
Viewable background color
59+
*/
60+
public var viewableBackgroundColor: UIColor = .black
5761
/**
5862
Cache for the reused ViewableControllers
5963
*/
@@ -87,7 +91,7 @@ public class ViewerController: UIViewController {
8791
/**
8892
Keeps track of where the status bar should be light or not
8993
*/
90-
fileprivate var shouldUseLightStatusBar = true
94+
public var shouldUseLightStatusBar = true
9195

9296
/**
9397
Critical button visibility state tracker, it's used to force the buttons to keep being hidden when they are toggled
@@ -106,7 +110,7 @@ public class ViewerController: UIViewController {
106110

107111
fileprivate lazy var overlayView: UIView = {
108112
let view = UIView(frame: UIScreen.main.bounds)
109-
view.backgroundColor = .black
113+
view.backgroundColor = self.viewableBackgroundColor
110114
view.alpha = 0
111115
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
112116

@@ -322,7 +326,7 @@ extension ViewerController {
322326
}
323327

324328
viewableController.update(with: viewable, at: indexPath)
325-
329+
viewableController.viewableBackgroundColor = self.viewableBackgroundColor
326330
return viewableController
327331
}
328332

@@ -500,7 +504,7 @@ extension ViewerController {
500504
@objc func panAction(_ gesture: UIPanGestureRecognizer) {
501505
let controller = self.findOrCreateViewableController(self.currentIndexPath)
502506
guard !controller.hasZoomed else { return }
503-
507+
504508
let viewHeight = controller.imageView.frame.size.height
505509
let viewHalfHeight = viewHeight / 2
506510
var translatedPoint = gesture.translation(in: controller.imageView)
@@ -524,7 +528,7 @@ extension ViewerController {
524528

525529
controller.dimControls(alpha)
526530
controller.imageView.center = translatedPoint
527-
controller.view.backgroundColor = UIColor.black.withAlphaComponent(alpha)
531+
controller.view.backgroundColor = self.viewableBackgroundColor.withAlphaComponent(alpha)
528532

529533
if self.buttonsAreVisible {
530534
self.fadeButtons(alpha)
@@ -539,22 +543,21 @@ extension ViewerController {
539543
self.isDragging = false
540544
UIView.animate(withDuration: 0.20, animations: {
541545
controller.imageView.center = self.originalDraggedCenter
542-
controller.view.backgroundColor = .black
546+
controller.view.backgroundColor = self.viewableBackgroundColor
543547
controller.dimControls(1.0)
544548

545549
if self.buttonsAreVisible {
546550
self.fadeButtons(1)
547551
}
548552

549553
self.shouldHideStatusBar = !self.buttonsAreVisible
550-
self.shouldUseLightStatusBar = true
551554

552555
#if os(iOS)
553556
self.setNeedsStatusBarAppearanceUpdate()
554557
#endif
555558
}, completion: { _ in
556559
controller.display()
557-
self.view.backgroundColor = .black
560+
self.view.backgroundColor = self.viewableBackgroundColor
558561
})
559562
}
560563
}

0 commit comments

Comments
 (0)