Merge branch 'feature/page_behavior_poc' into 'develop'
page behavior protocol See merge request BPHV_MIPS/mvm_core_ui!430
This commit is contained in:
commit
07a66b17a7
@ -110,6 +110,8 @@
|
||||
0AE98BB523FF18D2004C5109 /* Arrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB423FF18D2004C5109 /* Arrow.swift */; };
|
||||
0AE98BB723FF18E9004C5109 /* ArrowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */; };
|
||||
279B1569242BBC2F00921D6C /* ActionModelAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 279B1568242BBC2F00921D6C /* ActionModelAdapter.swift */; };
|
||||
27F973532466074500CAB5C5 /* PageBehavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27F973522466074500CAB5C5 /* PageBehavior.swift */; };
|
||||
27F9736A246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27F97369246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift */; };
|
||||
31BE15CB23D8924D00452370 /* CheckboxLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */; };
|
||||
31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15CA23D8924C00452370 /* CheckboxModel.swift */; };
|
||||
522679C123FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522679BF23FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift */; };
|
||||
@ -525,6 +527,8 @@
|
||||
0AE98BB423FF18D2004C5109 /* Arrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arrow.swift; sourceTree = "<group>"; };
|
||||
0AE98BB623FF18E9004C5109 /* ArrowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrowModel.swift; sourceTree = "<group>"; };
|
||||
279B1568242BBC2F00921D6C /* ActionModelAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionModelAdapter.swift; sourceTree = "<group>"; };
|
||||
27F973522466074500CAB5C5 /* PageBehavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageBehavior.swift; sourceTree = "<group>"; };
|
||||
27F97369246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenBrightnessModifierBehavior.swift; sourceTree = "<group>"; };
|
||||
31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxLabelModel.swift; sourceTree = "<group>"; };
|
||||
31BE15CA23D8924C00452370 /* CheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxModel.swift; sourceTree = "<group>"; };
|
||||
522679BF23FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListLeftVariableCheckboxAllTextAndLinks.swift; sourceTree = "<group>"; };
|
||||
@ -957,6 +961,15 @@
|
||||
path = Adapters;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
27F973512466071600CAB5C5 /* Behaviors */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
27F973522466074500CAB5C5 /* PageBehavior.swift */,
|
||||
27F97369246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift */,
|
||||
);
|
||||
path = Behaviors;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
5206F150241144A900658DC5 /* Headers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -1396,6 +1409,7 @@
|
||||
D29DF0CE21E404D4003B2FB9 /* MVMCoreUI */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
27F973512466071600CAB5C5 /* Behaviors */,
|
||||
D2C78CD324252F4E00B69FDE /* Atomic */,
|
||||
012A88EF23985E0100FE3DA1 /* CustomPrimitives */,
|
||||
D2B18B7D236090D500A9AEDC /* BaseClasses */,
|
||||
@ -2140,6 +2154,7 @@
|
||||
AA69AAF62445BF5700AF3D3B /* ListLeftVariableCheckboxBodyText.swift in Sources */,
|
||||
D264FAA3243E632F00D98315 /* ProgrammaticCollectionViewController.swift in Sources */,
|
||||
D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */,
|
||||
27F9736A246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift in Sources */,
|
||||
D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */,
|
||||
526A265E240D200500B0D828 /* ListTwoColumnCompareChanges.swift in Sources */,
|
||||
8D24041523E7FC0B009E23BE /* ListLeftVariableIconWithRightCaretModel.swift in Sources */,
|
||||
@ -2232,6 +2247,7 @@
|
||||
D2A5146122121FBF00345BFB /* MoleculeStackTemplate.swift in Sources */,
|
||||
D2E2A9A323E096B1000B42E6 /* DisableableModelProtocol.swift in Sources */,
|
||||
D29DF11821E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.m in Sources */,
|
||||
27F973532466074500CAB5C5 /* PageBehavior.swift in Sources */,
|
||||
94C2D9A323872C110006CF46 /* LabelAttributeStrikeThroughModel.swift in Sources */,
|
||||
D28A838523CCCA8900DFE4FC /* ScrollerModel.swift in Sources */,
|
||||
D29DF26C21E6AA0B003B2FB9 /* FLAnimatedImage.m in Sources */,
|
||||
|
||||
@ -201,6 +201,9 @@ import Foundation
|
||||
try? ModelRegistry.register(ActionTopAlertModel.self)
|
||||
try? ModelRegistry.register(ActionCollapseNotificationModel.self)
|
||||
try? ModelRegistry.register(ActionOpenPanelModel.self)
|
||||
|
||||
// Behaviors
|
||||
try? ModelRegistry.register(ScreenBrightnessModifierBehavior.self)
|
||||
}
|
||||
|
||||
/// Convenience function to get required modules for a give model
|
||||
|
||||
@ -28,6 +28,7 @@ import Foundation
|
||||
public var screenHeading: String?
|
||||
public var navigationItem: (NavigationItemModelProtocol & MoleculeModelProtocol)?
|
||||
public var formRules: [FormGroupRule]?
|
||||
public var behaviors: [PageBehaviorProtocol]?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializer
|
||||
@ -47,6 +48,7 @@ import Foundation
|
||||
case screenHeading
|
||||
case backgroundColor
|
||||
case formRules
|
||||
case behaviors
|
||||
case navigationItem
|
||||
}
|
||||
|
||||
@ -60,6 +62,7 @@ import Foundation
|
||||
screenHeading = try typeContainer.decodeIfPresent(String.self, forKey: .screenHeading)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
formRules = try typeContainer.decodeIfPresent([FormGroupRule].self, forKey: .formRules)
|
||||
behaviors = try typeContainer.decodeModelsIfPresent(codingKey: .behaviors)
|
||||
navigationItem = try typeContainer.decodeModelIfPresent(codingKey: .navigationItem)
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,6 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol MVMControllerModelProtocol: TemplateModelProtocol, FormHolderModelProtocol {
|
||||
public protocol MVMControllerModelProtocol: TemplateModelProtocol, FormHolderModelProtocol, PageBehaviorsTemplateProtocol {
|
||||
|
||||
}
|
||||
|
||||
@ -310,6 +310,18 @@ import UIKit
|
||||
MVMCoreUISession.sharedGlobal()?.currentPageType = pageType
|
||||
MVMCoreUILoggingHandler.shared()?.defaultLogPageState(forController: self)
|
||||
}
|
||||
|
||||
executeBehaviors { (behavior: PageVisibilityBehavior) in
|
||||
behavior.onPageShown()
|
||||
}
|
||||
}
|
||||
|
||||
open override func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
|
||||
executeBehaviors { (behavior: PageVisibilityBehavior) in
|
||||
behavior.onPageHidden()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
@ -424,4 +436,9 @@ import UIKit
|
||||
selectedField = nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Behavior Execution
|
||||
func executeBehaviors<T>(_ behaviorBlock:(_ behavior:T)->Void) {
|
||||
pageModel?.behaviors?.compactMap({ $0 as? T }).forEach({ behaviorBlock($0) })
|
||||
}
|
||||
}
|
||||
|
||||
44
MVMCoreUI/Behaviors/PageBehavior.swift
Normal file
44
MVMCoreUI/Behaviors/PageBehavior.swift
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// PageBehaviors.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Kyle on 5/8/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol PageBehaviorProtocol: ModelProtocol {
|
||||
|
||||
// The type of rule
|
||||
var behaviorName: String { get }
|
||||
|
||||
}
|
||||
|
||||
public extension PageBehaviorProtocol {
|
||||
|
||||
var behaviorName: String {
|
||||
get { return Self.identifier }
|
||||
}
|
||||
|
||||
static var categoryCodingKey: String {
|
||||
return "behaviorName"
|
||||
}
|
||||
|
||||
static var categoryName: String {
|
||||
return "\(PageBehaviorProtocol.self)"
|
||||
}
|
||||
}
|
||||
|
||||
public protocol PageVisibilityBehavior: PageBehaviorProtocol {
|
||||
|
||||
func onPageShown()
|
||||
func onPageHidden()
|
||||
|
||||
}
|
||||
|
||||
public protocol PageBehaviorsTemplateProtocol {
|
||||
|
||||
var behaviors: [PageBehaviorProtocol]? { get }
|
||||
|
||||
}
|
||||
68
MVMCoreUI/Behaviors/ScreenBrightnessModifierBehavior.swift
Normal file
68
MVMCoreUI/Behaviors/ScreenBrightnessModifierBehavior.swift
Normal file
@ -0,0 +1,68 @@
|
||||
//
|
||||
// ScreenBrightnessModifierBehavior.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Kyle on 5/9/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
public class ScreenBrightnessModifierBehavior: PageVisibilityBehavior {
|
||||
|
||||
public static var identifier = "screenBrightnessModifier"
|
||||
|
||||
@Clamping(range: 0...1) var screenBrightness: CGFloat
|
||||
|
||||
var originalScreenBrightness: CGFloat?
|
||||
|
||||
//MARK:- PageVisibilityBehavior
|
||||
|
||||
public func onPageShown() {
|
||||
changeScreenBrightness()
|
||||
}
|
||||
|
||||
public func onPageHidden() {
|
||||
restoreScreenBrightness()
|
||||
}
|
||||
|
||||
//MARK:- Behavior
|
||||
|
||||
func changeScreenBrightness() {
|
||||
guard originalScreenBrightness == nil else { return }
|
||||
originalScreenBrightness = UIScreen.main.brightness
|
||||
UIScreen.main.brightness = screenBrightness
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(willResignActive), name: UIApplication.willResignActiveNotification, object: nil)
|
||||
}
|
||||
|
||||
func restoreScreenBrightness() {
|
||||
guard let originalScreenBrightness = originalScreenBrightness else { return }
|
||||
UIScreen.main.brightness = originalScreenBrightness
|
||||
self.originalScreenBrightness = nil
|
||||
NotificationCenter.default.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil)
|
||||
}
|
||||
|
||||
@objc func willResignActive() {
|
||||
restoreScreenBrightness()
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
}
|
||||
|
||||
@objc func didBecomeActive() {
|
||||
NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
changeScreenBrightness()
|
||||
}
|
||||
|
||||
//MARK:- Codable
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case screenBrightness
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
screenBrightness = try typeContainer.decode(CGFloat.self, forKey: .screenBrightness)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(screenBrightness, forKey: .screenBrightness)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user