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
|
||||
}
|
||||
|
||||
if let actionMap = model.action?.toJSON() {
|
||||
didToggleAction = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) }
|
||||
let actionMap = model.action?.toJSON()
|
||||
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 {
|
||||
associatedtype TemplateModel: TemplateModelProtocol
|
||||
var templateModel: TemplateModel? { get set }
|
||||
|
||||
func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> TemplateModel
|
||||
}
|
||||
|
||||
public extension TemplateProtocol where Self: ViewController {
|
||||
|
||||
func parseTemplate(json: [AnyHashable: Any]?) throws {
|
||||
guard let pageJSON = json else { return }
|
||||
let data = try JSONSerialization.data(withJSONObject: pageJSON)
|
||||
let decoder = JSONDecoder()
|
||||
try decoder.add(delegateObject: delegateObjectIVar)
|
||||
let templateModel = try decoder.decode(TemplateModel.self, from: data)
|
||||
self.templateModel = templateModel
|
||||
self.templateModel = try decodeTemplate(using: decoder, from: data)
|
||||
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
|
||||
|
||||
@objcMembers public class ListPageTemplateModel: ThreeLayerModelBase {
|
||||
@objcMembers open class ListPageTemplateModel: ThreeLayerModelBase {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
public override class var identifier: String {
|
||||
open override class var identifier: String {
|
||||
return "list"
|
||||
}
|
||||
public var molecules: [ListItemModelProtocol & MoleculeModelProtocol]?
|
||||
@ -49,7 +49,7 @@ import Foundation
|
||||
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)
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeModelsIfPresent(molecules, forKey: .molecules)
|
||||
|
||||
@ -28,6 +28,11 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
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? {
|
||||
didSet {
|
||||
guard loadObject != oldValue else { return }
|
||||
|
||||
@ -9,7 +9,8 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
@objcMembers public class TemplateModel: MVMControllerModelProtocol, TabPageModelProtocol {
|
||||
@objcMembers open class TemplateModel: MVMControllerModelProtocol, TabPageModelProtocol {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
@objcMembers public class ThreeLayerModelBase: TemplateModel, ThreeLayerTemplateModelProtocol {
|
||||
@objcMembers open class ThreeLayerModelBase: TemplateModel, ThreeLayerTemplateModelProtocol {
|
||||
public var anchorHeader: Bool = false
|
||||
public var header: MoleculeModelProtocol?
|
||||
public var anchorFooter: Bool = false
|
||||
|
||||
@ -158,7 +158,7 @@ import UIKit
|
||||
|
||||
open func parsePageJSON() throws {
|
||||
}
|
||||
|
||||
|
||||
open class func verifyRequiredModulesLoaded(for loadObject: MVMCoreLoadObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject>) -> Bool {
|
||||
guard let pageType = loadObject?.pageType, var modulesRequired = MVMCoreUIViewControllerMappingObject.shared()?.modulesRequired(forPageType: pageType),
|
||||
!modulesRequired.isEmpty else { return true }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user