code review items
This commit is contained in:
parent
a19003f240
commit
b4f8e42817
@ -6,9 +6,9 @@
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
class ScreenBrightnessModifierBehavior: PageVisibilityBehavior {
|
||||
public class ScreenBrightnessModifierBehavior: PageVisibilityBehavior {
|
||||
|
||||
static var identifier = "screenBrightnessModifier"
|
||||
public static var identifier = "screenBrightnessModifier"
|
||||
|
||||
@Clamping(range: 0...1) var screenBrightness: CGFloat
|
||||
|
||||
@ -16,38 +16,36 @@ class ScreenBrightnessModifierBehavior: PageVisibilityBehavior {
|
||||
|
||||
//MARK:- PageVisibilityBehavior
|
||||
|
||||
func onPageShown() {
|
||||
public func onPageShown() {
|
||||
changeScreenBrightness()
|
||||
}
|
||||
|
||||
func onPageHidden() {
|
||||
public func onPageHidden() {
|
||||
restoreScreenBrightness()
|
||||
}
|
||||
|
||||
//MARK:- Behavior
|
||||
|
||||
func changeScreenBrightness() {
|
||||
if originalScreenBrightness == nil {
|
||||
originalScreenBrightness = UIScreen.main.brightness
|
||||
UIScreen.main.brightness = screenBrightness
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(didEnterBackground), name: UIApplication.willResignActiveNotification, object: nil)
|
||||
}
|
||||
if originalScreenBrightness != nil { return }
|
||||
originalScreenBrightness = UIScreen.main.brightness
|
||||
UIScreen.main.brightness = screenBrightness
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(willResignActive), name: UIApplication.willResignActiveNotification, object: nil)
|
||||
}
|
||||
|
||||
func restoreScreenBrightness() {
|
||||
if let originalScreenBrightness = originalScreenBrightness {
|
||||
UIScreen.main.brightness = originalScreenBrightness
|
||||
self.originalScreenBrightness = nil
|
||||
NotificationCenter.default.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil)
|
||||
}
|
||||
guard let originalScreenBrightness = originalScreenBrightness else { return }
|
||||
UIScreen.main.brightness = originalScreenBrightness
|
||||
self.originalScreenBrightness = nil
|
||||
NotificationCenter.default.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil)
|
||||
}
|
||||
|
||||
@objc func didEnterBackground() {
|
||||
@objc func willResignActive() {
|
||||
restoreScreenBrightness()
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(didEnterForeground), name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
}
|
||||
|
||||
@objc func didEnterForeground() {
|
||||
@objc func didBecomeActive() {
|
||||
NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
changeScreenBrightness()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user