Merge branch 'release/10_0_0' into 'feature/develop_mvp_3'

updated models for use of Decoder Context

See merge request BPHV_MIPS/mvm_core_ui!866
This commit is contained in:
Pfeil, Scott Robert 2022-06-20 14:52:17 +00:00
commit fea4b3a90a
12 changed files with 30 additions and 29 deletions

View File

@ -206,6 +206,11 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
title = try typeContainer.decode(String.self, forKey: .title) title = try typeContainer.decode(String.self, forKey: .title)
action = try typeContainer.decodeModel(codingKey: .action) action = try typeContainer.decodeModel(codingKey: .action)
if let style = decoder.context?.value(forKey: CodingKeys.style.stringValue) as? Styler.Button.Style{
self.style = style
setFacade(by: style)
}
if let style = try typeContainer.decodeIfPresent(Styler.Button.Style.self, forKey: .style) { if let style = try typeContainer.decodeIfPresent(Styler.Button.Style.self, forKey: .style) {
self.style = style self.style = style
setFacade(by: style) setFacade(by: style)

View File

@ -49,16 +49,19 @@ import UIKit
public init() { public init() {
super.init(frame: .zero) super.init(frame: .zero)
model = LineModel(type: .secondary) model = LineModel(type: .secondary)
setStyle(.secondary)
} }
public override init(frame: CGRect) { public override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
model = LineModel(type: .secondary) model = LineModel(type: .secondary)
setStyle(.secondary)
} }
public required init?(coder: NSCoder) { public required init?(coder: NSCoder) {
super.init(coder: coder) super.init(coder: coder)
model = LineModel(type: .secondary) model = LineModel(type: .secondary)
setStyle(.secondary)
} }
public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {

View File

@ -58,11 +58,11 @@ import VDSColorTokens
/// Sets the item colors. /// Sets the item colors.
private func set(tabItemAppearance: UITabBarItemAppearance, model: TabBarModel) { private func set(tabItemAppearance: UITabBarItemAppearance, model: TabBarModel) {
tabItemAppearance.normal.iconColor = model.unSelectedColor.uiColor tabItemAppearance.normal.iconColor = model.unSelectedColor.uiColor
tabItemAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: model.unSelectedColor.uiColor, NSAttributedString.Key.font: MFFonts.mfFontTXRegular(10)] tabItemAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: model.unSelectedColor.uiColor, NSAttributedString.Key.font: MFFonts.mfFontTXBold(10)]
tabItemAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3) tabItemAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
tabItemAppearance.selected.iconColor = model.selectedColor.uiColor tabItemAppearance.selected.iconColor = model.selectedColor.uiColor
tabItemAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: model.selectedColor.uiColor, NSAttributedString.Key.font: MFFonts.mfFontTXRegular(10)] tabItemAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: model.selectedColor.uiColor, NSAttributedString.Key.font: MFFonts.mfFontTXBold(10)]
tabItemAppearance.selected.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3) tabItemAppearance.selected.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
} }

View File

@ -50,13 +50,17 @@ public class TwoButtonViewModel: ParentMoleculeModelProtocol {
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
primaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .primaryButton)
if primaryButton?.style == nil { //set context value for 'primary' style to be set for the primaryButton in case the
primaryButton?.style = .primary //property is not returned in the JSON and once decoded, this value is removed from the context
try decoder.setContext(value: Styler.Button.Style.primary, for: "style") {
self.primaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .primaryButton)
} }
secondaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .secondaryButton)
if secondaryButton?.style == nil { //set context value for 'secondary' style to be set for the primaryButton in case the
secondaryButton?.style = .secondary //property is not returned in the JSON and once decoded, this value is removed from the context
try decoder.setContext(value: Styler.Button.Style.secondary, for: "style") {
self.secondaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .secondaryButton)
} }
} }

View File

@ -61,7 +61,7 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
open var additionalLeftButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]? open var additionalLeftButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]?
open var additionalRightButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]? open var additionalRightButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]?
open var titleView: MoleculeModelProtocol? open var titleView: MoleculeModelProtocol?
open var titleOffset: UIOffset? open var titleOffset: UIOffset? = UIOffset(horizontal: -CGFloat.greatestFiniteMagnitude, vertical: 0)
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
@ -114,7 +114,9 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
additionalRightButtons = try typeContainer.decodeModelsIfPresent(codingKey: .additionalRightButtons) additionalRightButtons = try typeContainer.decodeModelsIfPresent(codingKey: .additionalRightButtons)
titleView = try typeContainer.decodeModelIfPresent(codingKey: .titleView) titleView = try typeContainer.decodeModelIfPresent(codingKey: .titleView)
style = try typeContainer.decodeIfPresent(NavigationItemStyle.self, forKey: .style) style = try typeContainer.decodeIfPresent(NavigationItemStyle.self, forKey: .style)
titleOffset = try typeContainer.decodeIfPresent(UIOffset.self, forKey: .titleOffset) ?? UIOffset(horizontal: -CGFloat.greatestFiniteMagnitude, vertical: 0) if let titleOffset = try typeContainer.decodeIfPresent(UIOffset.self, forKey: .titleOffset) {
self.titleOffset = titleOffset
}
line?.inverted = style == .dark line?.inverted = style == .dark
} }

View File

@ -33,11 +33,7 @@ public extension TemplateProtocol {
guard let pageJSON = json else { return } guard let pageJSON = json else { return }
let delegateObject = (self as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject let delegateObject = (self as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
let data = try JSONSerialization.data(withJSONObject: pageJSON) let data = try JSONSerialization.data(withJSONObject: pageJSON)
let decoder = JSONDecoder() let decoder = JSONDecoder.create(with: delegateObject)
if let delegateObject = delegateObject {
// Add the delegate to access mid parsing if applicable.
try decoder.add(delegateObject: delegateObject)
}
templateModel = try decodeTemplate(using: decoder, from: data) templateModel = try decodeTemplate(using: decoder, from: data)
// Add additional required behaviors if applicable. // Add additional required behaviors if applicable.

View File

@ -75,7 +75,7 @@ public class AddRemoveMoleculesBehavior: PageCustomActionHandlerBehavior, PageMo
self.delegate = delegateObject self.delegate = delegateObject
} }
public func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject) { public func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) {
guard let list = delegate?.moleculeListDelegate else { return } guard let list = delegate?.moleculeListDelegate else { return }
for case let model as (MoleculeModelProtocol & ListItemModelProtocol & AddMolecules) in rootMolecules { for case let model as (MoleculeModelProtocol & ListItemModelProtocol & AddMolecules) in rootMolecules {
if let moleculesToAdd = model.getRecursiveMoleculesToAdd(), if let moleculesToAdd = model.getRecursiveMoleculesToAdd(),

View File

@ -19,7 +19,7 @@ public protocol PageBehaviorProtocol: ModelHandlerProtocol {
public protocol PageMoleculeTransformationBehavior: PageBehaviorProtocol { public protocol PageMoleculeTransformationBehavior: PageBehaviorProtocol {
func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject) func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?)
} }
public protocol PageVisibilityBehavior: PageBehaviorProtocol { public protocol PageVisibilityBehavior: PageBehaviorProtocol {

View File

@ -66,7 +66,7 @@ public extension UINavigationController {
/// Convenience function for setting the navigation bar ui /// Convenience function for setting the navigation bar ui
func setNavigationBarUI(with model: NavigationItemModelProtocol) { func setNavigationBarUI(with model: NavigationItemModelProtocol) {
let navigationBar = navigationBar let navigationBar = navigationBar
let font = MFStyler.fontBoldBodySmall(false) let font = MFStyler.fontBoldBodyLarge(false)
let backgroundColor = model.backgroundColor?.uiColor let backgroundColor = model.backgroundColor?.uiColor
let tint = model.tintColor.uiColor let tint = model.tintColor.uiColor
navigationBar.tintColor = tint navigationBar.tintColor = tint

View File

@ -19,7 +19,7 @@ open class SubNavManagerController: ViewController, MVMCoreViewManagerProtocol,
/// Used to layout the ui. /// Used to layout the ui.
public lazy var stackView: UIStackView = { public lazy var stackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [tabs, line, subNavigationController.view]) let stackView = UIStackView(arrangedSubviews: [tabs, subNavigationController.view])
stackView.translatesAutoresizingMaskIntoConstraints = false stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.isAccessibilityElement = false stackView.isAccessibilityElement = false
stackView.axis = .vertical stackView.axis = .vertical
@ -33,10 +33,6 @@ open class SubNavManagerController: ViewController, MVMCoreViewManagerProtocol,
return tabs return tabs
}() }()
public lazy var line: Line = {
return Line(model: LineModel(type: .secondary), delegateObjectIVar, nil)
}()
public lazy var subNavigationController: UINavigationController = { public lazy var subNavigationController: UINavigationController = {
let subNavigationController = SubNavManagerNavigationController(rootViewController: viewController) let subNavigationController = SubNavManagerNavigationController(rootViewController: viewController)
subNavigationController.view.translatesAutoresizingMaskIntoConstraints = false subNavigationController.view.translatesAutoresizingMaskIntoConstraints = false

View File

@ -125,8 +125,6 @@
- (void)openURLInSafariWebView:(nonnull NSURL *)url { - (void)openURLInSafariWebView:(nonnull NSURL *)url {
SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:url]; SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:url];
safariViewController.preferredBarTintColor = [UIColor whiteColor];
safariViewController.preferredControlTintColor = [UIColor blackColor];
[[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:safariViewController animated:YES]; [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:safariViewController animated:YES];
} }

View File

@ -69,10 +69,7 @@ open class TopNotificationModel: Codable {
/// Decodes the top alert json to a model. /// Decodes the top alert json to a model.
public static func decode(json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) throws -> Self { public static func decode(json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) throws -> Self {
let data = try JSONSerialization.data(withJSONObject: json) let data = try JSONSerialization.data(withJSONObject: json)
let decoder = JSONDecoder() let decoder = JSONDecoder.create(with: delegateObject)
if let delegateObject = delegateObject {
try decoder.add(delegateObject: delegateObject)
}
return try decoder.decode(self, from: data) return try decoder.decode(self, from: data)
} }