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