Merge branch 'feature/in_store_toggle_support' into 'develop'
Feature/in store toggle support See merge request BPHV_MIPS/mvm_core_ui!515
This commit is contained in:
commit
4c0cf1ae28
@ -392,8 +392,23 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
accessibilityLabel = accessibileString
|
accessibilityLabel = accessibileString
|
||||||
}
|
}
|
||||||
|
|
||||||
if let actionMap = model.action?.toJSON() {
|
let actionMap = model.action?.toJSON()
|
||||||
didToggleAction = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) }
|
let alternateActionMap = model.alternateAction?.toJSON()
|
||||||
|
if actionMap != nil || alternateActionMap != nil {
|
||||||
|
didToggleAction = { [weak self] in
|
||||||
|
guard let self = self else { return }
|
||||||
|
if self.isOn {
|
||||||
|
if actionMap != nil {
|
||||||
|
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if alternateActionMap != nil {
|
||||||
|
MVMCoreActionHandler.shared()?.handleAction(with: alternateActionMap, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
|
} else if actionMap != nil {
|
||||||
|
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,16 +11,23 @@ import Foundation
|
|||||||
public protocol TemplateProtocol: AnyObject {
|
public protocol TemplateProtocol: AnyObject {
|
||||||
associatedtype TemplateModel: TemplateModelProtocol
|
associatedtype TemplateModel: TemplateModelProtocol
|
||||||
var templateModel: TemplateModel? { get set }
|
var templateModel: TemplateModel? { get set }
|
||||||
|
|
||||||
|
func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> TemplateModel
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension TemplateProtocol where Self: ViewController {
|
public extension TemplateProtocol where Self: ViewController {
|
||||||
|
|
||||||
func parseTemplate(json: [AnyHashable: Any]?) throws {
|
func parseTemplate(json: [AnyHashable: Any]?) throws {
|
||||||
guard let pageJSON = json else { return }
|
guard let pageJSON = json else { return }
|
||||||
let data = try JSONSerialization.data(withJSONObject: pageJSON)
|
let data = try JSONSerialization.data(withJSONObject: pageJSON)
|
||||||
let decoder = JSONDecoder()
|
let decoder = JSONDecoder()
|
||||||
try decoder.add(delegateObject: delegateObjectIVar)
|
try decoder.add(delegateObject: delegateObjectIVar)
|
||||||
let templateModel = try decoder.decode(TemplateModel.self, from: data)
|
self.templateModel = try decodeTemplate(using: decoder, from: data)
|
||||||
self.templateModel = templateModel
|
|
||||||
self.pageModel = templateModel as? MVMControllerModelProtocol
|
self.pageModel = templateModel as? MVMControllerModelProtocol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> TemplateModel {
|
||||||
|
return try decoder.decode(TemplateModel.self, from: data)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@objcMembers public class ListPageTemplateModel: ThreeLayerModelBase {
|
@objcMembers open class ListPageTemplateModel: ThreeLayerModelBase {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public override class var identifier: String {
|
open override class var identifier: String {
|
||||||
return "list"
|
return "list"
|
||||||
}
|
}
|
||||||
public var molecules: [ListItemModelProtocol & MoleculeModelProtocol]?
|
public var molecules: [ListItemModelProtocol & MoleculeModelProtocol]?
|
||||||
@ -49,7 +49,7 @@ import Foundation
|
|||||||
try super.init(from: decoder)
|
try super.init(from: decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func encode(to encoder: Encoder) throws {
|
open override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encodeModelsIfPresent(molecules, forKey: .molecules)
|
try container.encodeModelsIfPresent(molecules, forKey: .molecules)
|
||||||
|
|||||||
@ -28,6 +28,11 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
|||||||
try super.parsePageJSON()
|
try super.parsePageJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For subclassing the model.
|
||||||
|
open func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> ListPageTemplateModel {
|
||||||
|
return try decoder.decode(ListPageTemplateModel.self, from: data)
|
||||||
|
}
|
||||||
|
|
||||||
open override var loadObject: MVMCoreLoadObject? {
|
open override var loadObject: MVMCoreLoadObject? {
|
||||||
didSet {
|
didSet {
|
||||||
guard loadObject != oldValue else { return }
|
guard loadObject != oldValue else { return }
|
||||||
|
|||||||
@ -9,7 +9,8 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
@objcMembers public class TemplateModel: MVMControllerModelProtocol, TabPageModelProtocol {
|
@objcMembers open class TemplateModel: MVMControllerModelProtocol, TabPageModelProtocol {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@objcMembers public class ThreeLayerModelBase: TemplateModel, ThreeLayerTemplateModelProtocol {
|
@objcMembers open class ThreeLayerModelBase: TemplateModel, ThreeLayerTemplateModelProtocol {
|
||||||
public var anchorHeader: Bool = false
|
public var anchorHeader: Bool = false
|
||||||
public var header: MoleculeModelProtocol?
|
public var header: MoleculeModelProtocol?
|
||||||
public var anchorFooter: Bool = false
|
public var anchorFooter: Bool = false
|
||||||
|
|||||||
@ -158,7 +158,7 @@ import UIKit
|
|||||||
|
|
||||||
open func parsePageJSON() throws {
|
open func parsePageJSON() throws {
|
||||||
}
|
}
|
||||||
|
|
||||||
open class func verifyRequiredModulesLoaded(for loadObject: MVMCoreLoadObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject>) -> Bool {
|
open class func verifyRequiredModulesLoaded(for loadObject: MVMCoreLoadObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject>) -> Bool {
|
||||||
guard let pageType = loadObject?.pageType, var modulesRequired = MVMCoreUIViewControllerMappingObject.shared()?.modulesRequired(forPageType: pageType),
|
guard let pageType = loadObject?.pageType, var modulesRequired = MVMCoreUIViewControllerMappingObject.shared()?.modulesRequired(forPageType: pageType),
|
||||||
!modulesRequired.isEmpty else { return true }
|
!modulesRequired.isEmpty else { return true }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user