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:
commit
fea4b3a90a
@ -206,6 +206,11 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
title = try typeContainer.decode(String.self, forKey: .title)
|
||||
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) {
|
||||
self.style = style
|
||||
setFacade(by: style)
|
||||
|
||||
@ -49,16 +49,19 @@ import UIKit
|
||||
public init() {
|
||||
super.init(frame: .zero)
|
||||
model = LineModel(type: .secondary)
|
||||
setStyle(.secondary)
|
||||
}
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
model = LineModel(type: .secondary)
|
||||
setStyle(.secondary)
|
||||
}
|
||||
|
||||
public required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
model = LineModel(type: .secondary)
|
||||
setStyle(.secondary)
|
||||
}
|
||||
|
||||
public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
|
||||
|
||||
@ -58,11 +58,11 @@ import VDSColorTokens
|
||||
/// Sets the item colors.
|
||||
private func set(tabItemAppearance: UITabBarItemAppearance, model: TabBarModel) {
|
||||
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.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)
|
||||
}
|
||||
|
||||
|
||||
@ -50,13 +50,17 @@ public class TwoButtonViewModel: ParentMoleculeModelProtocol {
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
primaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .primaryButton)
|
||||
if primaryButton?.style == nil {
|
||||
primaryButton?.style = .primary
|
||||
|
||||
//set context value for 'primary' style to be set for the primaryButton in case the
|
||||
//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 {
|
||||
secondaryButton?.style = .secondary
|
||||
|
||||
//set context value for 'secondary' style to be set for the primaryButton in case the
|
||||
//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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
|
||||
open var additionalLeftButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]?
|
||||
open var additionalRightButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]?
|
||||
open var titleView: MoleculeModelProtocol?
|
||||
open var titleOffset: UIOffset?
|
||||
open var titleOffset: UIOffset? = UIOffset(horizontal: -CGFloat.greatestFiniteMagnitude, vertical: 0)
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializer
|
||||
@ -114,7 +114,9 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
|
||||
additionalRightButtons = try typeContainer.decodeModelsIfPresent(codingKey: .additionalRightButtons)
|
||||
titleView = try typeContainer.decodeModelIfPresent(codingKey: .titleView)
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@ -33,11 +33,7 @@ public extension TemplateProtocol {
|
||||
guard let pageJSON = json else { return }
|
||||
let delegateObject = (self as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
|
||||
let data = try JSONSerialization.data(withJSONObject: pageJSON)
|
||||
let decoder = JSONDecoder()
|
||||
if let delegateObject = delegateObject {
|
||||
// Add the delegate to access mid parsing if applicable.
|
||||
try decoder.add(delegateObject: delegateObject)
|
||||
}
|
||||
let decoder = JSONDecoder.create(with: delegateObject)
|
||||
templateModel = try decodeTemplate(using: decoder, from: data)
|
||||
|
||||
// Add additional required behaviors if applicable.
|
||||
|
||||
@ -75,7 +75,7 @@ public class AddRemoveMoleculesBehavior: PageCustomActionHandlerBehavior, PageMo
|
||||
self.delegate = delegateObject
|
||||
}
|
||||
|
||||
public func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject) {
|
||||
public func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) {
|
||||
guard let list = delegate?.moleculeListDelegate else { return }
|
||||
for case let model as (MoleculeModelProtocol & ListItemModelProtocol & AddMolecules) in rootMolecules {
|
||||
if let moleculesToAdd = model.getRecursiveMoleculesToAdd(),
|
||||
|
||||
@ -19,7 +19,7 @@ public protocol PageBehaviorProtocol: ModelHandlerProtocol {
|
||||
|
||||
public protocol PageMoleculeTransformationBehavior: PageBehaviorProtocol {
|
||||
|
||||
func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject)
|
||||
func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?)
|
||||
}
|
||||
|
||||
public protocol PageVisibilityBehavior: PageBehaviorProtocol {
|
||||
|
||||
@ -66,7 +66,7 @@ public extension UINavigationController {
|
||||
/// Convenience function for setting the navigation bar ui
|
||||
func setNavigationBarUI(with model: NavigationItemModelProtocol) {
|
||||
let navigationBar = navigationBar
|
||||
let font = MFStyler.fontBoldBodySmall(false)
|
||||
let font = MFStyler.fontBoldBodyLarge(false)
|
||||
let backgroundColor = model.backgroundColor?.uiColor
|
||||
let tint = model.tintColor.uiColor
|
||||
navigationBar.tintColor = tint
|
||||
|
||||
@ -19,7 +19,7 @@ open class SubNavManagerController: ViewController, MVMCoreViewManagerProtocol,
|
||||
|
||||
/// Used to layout the ui.
|
||||
public lazy var stackView: UIStackView = {
|
||||
let stackView = UIStackView(arrangedSubviews: [tabs, line, subNavigationController.view])
|
||||
let stackView = UIStackView(arrangedSubviews: [tabs, subNavigationController.view])
|
||||
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
stackView.isAccessibilityElement = false
|
||||
stackView.axis = .vertical
|
||||
@ -33,10 +33,6 @@ open class SubNavManagerController: ViewController, MVMCoreViewManagerProtocol,
|
||||
return tabs
|
||||
}()
|
||||
|
||||
public lazy var line: Line = {
|
||||
return Line(model: LineModel(type: .secondary), delegateObjectIVar, nil)
|
||||
}()
|
||||
|
||||
public lazy var subNavigationController: UINavigationController = {
|
||||
let subNavigationController = SubNavManagerNavigationController(rootViewController: viewController)
|
||||
subNavigationController.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
@ -125,8 +125,6 @@
|
||||
|
||||
- (void)openURLInSafariWebView:(nonnull NSURL *)url {
|
||||
SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:url];
|
||||
safariViewController.preferredBarTintColor = [UIColor whiteColor];
|
||||
safariViewController.preferredControlTintColor = [UIColor blackColor];
|
||||
[[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:safariViewController animated:YES];
|
||||
}
|
||||
|
||||
|
||||
@ -69,10 +69,7 @@ open class TopNotificationModel: Codable {
|
||||
/// Decodes the top alert json to a model.
|
||||
public static func decode(json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) throws -> Self {
|
||||
let data = try JSONSerialization.data(withJSONObject: json)
|
||||
let decoder = JSONDecoder()
|
||||
if let delegateObject = delegateObject {
|
||||
try decoder.add(delegateObject: delegateObject)
|
||||
}
|
||||
let decoder = JSONDecoder.create(with: delegateObject)
|
||||
return try decoder.decode(self, from: data)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user