update for changes discussed today
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
30530bc4e1
commit
c075323ce7
@ -9,6 +9,7 @@
|
|||||||
import MVMCore
|
import MVMCore
|
||||||
import UIKit
|
import UIKit
|
||||||
import VDS
|
import VDS
|
||||||
|
import Combine
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A custom implementation of Apple's UISwitch.
|
A custom implementation of Apple's UISwitch.
|
||||||
@ -25,8 +26,8 @@ open class Toggle: ToggleBase, VDSMoleculeViewProtocol {
|
|||||||
public var viewModel: ToggleModel!
|
public var viewModel: ToggleModel!
|
||||||
public var delegateObject: MVMCoreUIDelegateObject?
|
public var delegateObject: MVMCoreUIDelegateObject?
|
||||||
public var additionalData: [AnyHashable: Any]?
|
public var additionalData: [AnyHashable: Any]?
|
||||||
public var didToggleAction: ActionBlock?
|
public var valueChangedCancellable: AnyCancellable?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -34,22 +35,37 @@ open class Toggle: ToggleBase, VDSMoleculeViewProtocol {
|
|||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
self.isOn = isOn
|
self.isOn = isOn
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func initialSetup() {
|
open override func initialSetup() {
|
||||||
super.initialSetup()
|
super.initialSetup()
|
||||||
|
|
||||||
publisher(for: .touchUpInside)
|
publisher(for: .touchUpInside)
|
||||||
.sink {[weak self] toggle in
|
.sink {[weak self] toggle in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
self.toggle()
|
self.toggle()
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
//this is logic that will always need to be run
|
||||||
|
//and is added into the array of Set<AnyCancellables>
|
||||||
publisher(for: .valueChanged)
|
publisher(for: .valueChanged)
|
||||||
.sink {[weak self] _ in
|
.sink {[weak self] _ in
|
||||||
guard let self = self else { return }
|
guard let self = self, let viewModel = self.viewModel else { return }
|
||||||
self.valueChanged()
|
//sync the value on the viewModel
|
||||||
|
viewModel.selected = self.isOn
|
||||||
|
|
||||||
|
//tell the form you changed
|
||||||
|
_ = FormValidator.validate(delegate: self.delegateObject?.formHolderDelegate)
|
||||||
|
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
//register the defaultActionExecuter
|
||||||
|
//this can then be overwritten by a subclass
|
||||||
|
valueChangedCancellable = publisher(for: .valueChanged)
|
||||||
|
.sink {[weak self] _ in
|
||||||
|
guard let self = self else { return }
|
||||||
|
self.executeDefaultAction()
|
||||||
|
}
|
||||||
|
|
||||||
accessibilityLabelEnabled = MVMCoreUIUtility.hardcodedString(withKey: "Toggle_buttonlabel")
|
accessibilityLabelEnabled = MVMCoreUIUtility.hardcodedString(withKey: "Toggle_buttonlabel")
|
||||||
accessibilityLabelDisabled = MVMCoreUIUtility.hardcodedString(withKey: "Toggle_buttonlabel")
|
accessibilityLabelDisabled = MVMCoreUIUtility.hardcodedString(withKey: "Toggle_buttonlabel")
|
||||||
accessibilityHintEnabled = MVMCoreUIUtility.hardcodedString(withKey: "AccToggleHint")
|
accessibilityHintEnabled = MVMCoreUIUtility.hardcodedString(withKey: "AccToggleHint")
|
||||||
@ -57,9 +73,9 @@ open class Toggle: ToggleBase, VDSMoleculeViewProtocol {
|
|||||||
accessibilityValueEnabled = MVMCoreUIUtility.hardcodedString(withKey: "AccOn")
|
accessibilityValueEnabled = MVMCoreUIUtility.hardcodedString(withKey: "AccOn")
|
||||||
accessibilityValueDisabled = MVMCoreUIUtility.hardcodedString(withKey: "AccOff")
|
accessibilityValueDisabled = MVMCoreUIUtility.hardcodedString(withKey: "AccOff")
|
||||||
}
|
}
|
||||||
|
|
||||||
open func updateView(_ size: CGFloat) {}
|
open func updateView(_ size: CGFloat) {}
|
||||||
|
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
super.updateView()
|
super.updateView()
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
@ -67,20 +83,13 @@ open class Toggle: ToggleBase, VDSMoleculeViewProtocol {
|
|||||||
|
|
||||||
open func viewModelDidUpdate() {
|
open func viewModelDidUpdate() {
|
||||||
guard let viewModel else { return }
|
guard let viewModel else { return }
|
||||||
|
|
||||||
|
//send toggle.model to the Form
|
||||||
FormValidator.setupValidation(for: viewModel, delegate: delegateObject?.formHolderDelegate)
|
FormValidator.setupValidation(for: viewModel, delegate: delegateObject?.formHolderDelegate)
|
||||||
additionalData = additionalData.dictionaryAdding(key: KeySourceModel, value: viewModel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func valueChanged(){
|
public func executeDefaultAction() {
|
||||||
guard let viewModel else { return }
|
guard let viewModel else { return }
|
||||||
//sync the value on the viewModel
|
|
||||||
viewModel.selected = isOn
|
|
||||||
|
|
||||||
//tell the form you changed
|
|
||||||
_ = FormValidator.validate(delegate: self.delegateObject?.formHolderDelegate)
|
|
||||||
|
|
||||||
didToggleAction?()
|
|
||||||
|
|
||||||
if viewModel.action != nil || viewModel.alternateAction != nil {
|
if viewModel.action != nil || viewModel.alternateAction != nil {
|
||||||
var action: ActionModelProtocol?
|
var action: ActionModelProtocol?
|
||||||
if isOn {
|
if isOn {
|
||||||
@ -97,19 +106,12 @@ open class Toggle: ToggleBase, VDSMoleculeViewProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Return the same height as the internal ToggleBase.toggleContainerSize.height
|
||||||
|
//since this is a class func, we can't reference it directly
|
||||||
public static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
public static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||||
return 44
|
return 44
|
||||||
}
|
}
|
||||||
|
|
||||||
private typealias ActionDefinition = (model: ActionModelProtocol,
|
|
||||||
sourceModel: MoleculeModelProtocol?)
|
|
||||||
|
|
||||||
private func performActionUnstructured(definition: ActionDefinition) {
|
|
||||||
MVMCoreUIActionHandler.performActionUnstructured(with: definition.model,
|
|
||||||
sourceModel: definition.sourceModel,
|
|
||||||
additionalData: additionalData,
|
|
||||||
delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCoreUIViewConstrainingProtocol
|
// MARK: - MVMCoreUIViewConstrainingProtocol
|
||||||
|
|||||||
@ -24,6 +24,7 @@ extension VDSMoleculeViewProtocol {
|
|||||||
public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
guard let castedModel = model as? ViewModel else { return }
|
guard let castedModel = model as? ViewModel else { return }
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
|
self.additionalData = additionalData
|
||||||
viewModel = castedModel
|
viewModel = castedModel
|
||||||
viewModelDidUpdate()
|
viewModelDidUpdate()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user