Merge branch 'feature/atomic_vds_buttonGroup' into feature/vds_batch_two
This commit is contained in:
commit
87a8051bbe
@ -18,6 +18,7 @@ import VDS
|
|||||||
open var viewModel: ButtonGroupModel!
|
open var viewModel: ButtonGroupModel!
|
||||||
open var delegateObject: MVMCoreUIDelegateObject?
|
open var delegateObject: MVMCoreUIDelegateObject?
|
||||||
open var additionalData: [AnyHashable : Any]?
|
open var additionalData: [AnyHashable : Any]?
|
||||||
|
open var previousModel: ButtonGroupModel?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - MoleculeViewProtocol
|
// MARK: - MoleculeViewProtocol
|
||||||
@ -31,25 +32,48 @@ import VDS
|
|||||||
return PillButton.estimatedHeight(with: buttonModel, delegateObject)
|
return PillButton.estimatedHeight(with: buttonModel, delegateObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func viewModelDidUpdate() {
|
public func viewModelDidUpdate() {
|
||||||
var buttonBases = [ButtonBase]()
|
|
||||||
viewModel.buttons.forEach { buttonModel in
|
|
||||||
if let buttonBaseType = try? ModelRegistry.getHandler(buttonModel) as? MoleculeViewProtocol.Type,
|
|
||||||
let button = buttonBaseType.init(model: buttonModel, delegateObject, additionalData) as? VDS.ButtonBase {
|
|
||||||
buttonBases.append(button)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
surface = viewModel.surface
|
surface = viewModel.surface
|
||||||
isEnabled = viewModel.enabled
|
isEnabled = viewModel.enabled
|
||||||
alignment = viewModel.alignment
|
alignment = viewModel.alignment
|
||||||
rowQuantityPhone = viewModel.rowQuantityPhone
|
rowQuantityPhone = viewModel.rowQuantityPhone
|
||||||
rowQuantityTablet = viewModel.rowQuantityTablet
|
rowQuantityTablet = viewModel.rowQuantityTablet
|
||||||
|
|
||||||
if let childWidthValue = viewModel.childWidthValue {
|
if let childWidthValue = viewModel.childWidthValue {
|
||||||
childWidth = .value(childWidthValue)
|
childWidth = .value(childWidthValue)
|
||||||
} else if let childWidthPercentage = viewModel.childWidthPercentage {
|
} else if let childWidthPercentage = viewModel.childWidthPercentage {
|
||||||
childWidth = .percentage(childWidthPercentage)
|
childWidth = .percentage(childWidthPercentage)
|
||||||
|
} else {
|
||||||
|
childWidth = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// create / set the moleculeViews
|
||||||
|
if (previousModel == nil) || Self.nameForReuse(with: previousModel!, delegateObject) != Self.nameForReuse(with: viewModel, delegateObject) {
|
||||||
|
previousModel = viewModel
|
||||||
|
var buttonBases = [ButtonBase]()
|
||||||
|
viewModel.buttons.forEach { buttonModel in
|
||||||
|
do {
|
||||||
|
let buttonBaseType = try ModelRegistry.getHandler(buttonModel) as! MoleculeViewProtocol.Type
|
||||||
|
let button = buttonBaseType.init(model: buttonModel, delegateObject, additionalData) as! VDS.ButtonBase
|
||||||
|
buttonBases.append(button)
|
||||||
|
} catch {
|
||||||
|
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: #function) {
|
||||||
|
MVMCoreLoggingHandler.shared()?.addError(toLog: errorObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buttons = buttonBases
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// only set the molecule views
|
||||||
|
for (index, buttonBase) in buttons.enumerated() {
|
||||||
|
if let button = buttonBase as? MoleculeViewProtocol, index < viewModel.buttons.count {
|
||||||
|
button.set(with: viewModel.buttons[index], delegateObject, additionalData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// force redraw
|
||||||
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
buttons = buttonBases
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -66,4 +90,22 @@ import VDS
|
|||||||
public func updateView(_ size: CGFloat) {
|
public func updateView(_ size: CGFloat) {
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||||
|
// This will aggregate names of molecules to make an id.
|
||||||
|
guard let model = model as? ButtonGroupModel else {
|
||||||
|
return "buttonGroup<>"
|
||||||
|
}
|
||||||
|
var name = "buttonGroup<"
|
||||||
|
for case let item in model.buttons {
|
||||||
|
if let moleculeClass = ModelRegistry.getMoleculeClass(item),
|
||||||
|
let nameForReuse = moleculeClass.nameForReuse(with: item, delegateObject) {
|
||||||
|
name.append(nameForReuse + ",")
|
||||||
|
} else {
|
||||||
|
name.append(item.moleculeName + ",")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
name.append(">")
|
||||||
|
return name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,8 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import VDS
|
import VDS
|
||||||
|
|
||||||
public class ButtonGroupModel: MoleculeModelProtocol {
|
public class ButtonGroupModel: ParentMoleculeModelProtocol {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -17,7 +18,8 @@ public class ButtonGroupModel: MoleculeModelProtocol {
|
|||||||
public static var identifier: String = "buttonGroup"
|
public static var identifier: String = "buttonGroup"
|
||||||
public var id: String = UUID().uuidString
|
public var id: String = UUID().uuidString
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
|
public var children: [MoleculeModelProtocol] { buttons }
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - VDS Properties
|
// MARK: - VDS Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -29,8 +29,8 @@
|
|||||||
|
|
||||||
if let _ = molecule as? ButtonModel {
|
if let _ = molecule as? ButtonModel {
|
||||||
horizontalAlignment = .fill
|
horizontalAlignment = .fill
|
||||||
} else if let model = molecule as? TwoButtonViewModel,
|
} else if let model = molecule as? TwoButtonViewModel {
|
||||||
model.primaryButton == nil || model.secondaryButton == nil {
|
model.fillContainer = true
|
||||||
horizontalAlignment = .fill
|
horizontalAlignment = .fill
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,7 +34,6 @@ import VDS
|
|||||||
buttonGroup.alignment = .center
|
buttonGroup.alignment = .center
|
||||||
buttonGroup.rowQuantityPhone = 2
|
buttonGroup.rowQuantityPhone = 2
|
||||||
buttonGroup.rowQuantityTablet = 2
|
buttonGroup.rowQuantityTablet = 2
|
||||||
buttonGroup.childWidth = .percentage(50)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -43,10 +42,6 @@ import VDS
|
|||||||
|
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
primaryButton.reset()
|
|
||||||
secondaryButton.reset()
|
|
||||||
primaryButton.use = .primary
|
|
||||||
secondaryButton.use = .secondary
|
|
||||||
buttonGroup.reset()
|
buttonGroup.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,8 +64,12 @@ import VDS
|
|||||||
primaryButton.set(with: primaryModel, delegateObject, additionalData)
|
primaryButton.set(with: primaryModel, delegateObject, additionalData)
|
||||||
buttons.append(primaryButton)
|
buttons.append(primaryButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buttonGroup.childWidth = viewModel.fillContainer ? .percentage(100) : nil
|
||||||
|
|
||||||
buttonGroup.buttons = buttons
|
if buttons.count != buttonGroup.buttons.count {
|
||||||
|
buttonGroup.buttons = buttons
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -84,6 +83,7 @@ import VDS
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - MVMCoreViewProtocol
|
// MARK: - MVMCoreViewProtocol
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func updateView(_ size: CGFloat) {
|
public func updateView(_ size: CGFloat) {
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,10 +19,9 @@ public class TwoButtonViewModel: ParentMoleculeModelProtocol {
|
|||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var primaryButton: ButtonModel?
|
public var primaryButton: ButtonModel?
|
||||||
public var secondaryButton: ButtonModel?
|
public var secondaryButton: ButtonModel?
|
||||||
|
public var fillContainer: Bool = false
|
||||||
|
|
||||||
public var children: [MoleculeModelProtocol] {
|
public var children: [MoleculeModelProtocol] { [primaryButton, secondaryButton].compactMap { $0 } }
|
||||||
return [primaryButton, secondaryButton].compactMap { $0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Keys
|
// MARK: - Keys
|
||||||
|
|||||||
@ -35,7 +35,6 @@ import VDS
|
|||||||
buttonGroup.alignment = .center
|
buttonGroup.alignment = .center
|
||||||
buttonGroup.rowQuantityPhone = 2
|
buttonGroup.rowQuantityPhone = 2
|
||||||
buttonGroup.rowQuantityTablet = 2
|
buttonGroup.rowQuantityTablet = 2
|
||||||
buttonGroup.childWidth = .percentage(50)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -43,8 +42,6 @@ import VDS
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
leftLink.reset()
|
|
||||||
rightLink.reset()
|
|
||||||
buttonGroup.reset()
|
buttonGroup.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +100,8 @@ import VDS
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func viewModelDidUpdate() {
|
public func viewModelDidUpdate() {
|
||||||
|
buttons.removeAll()
|
||||||
|
|
||||||
if let model = viewModel.leftLink {
|
if let model = viewModel.leftLink {
|
||||||
leftLink.set(with: model, delegateObject, additionalData)
|
leftLink.set(with: model, delegateObject, additionalData)
|
||||||
buttons.append(leftLink)
|
buttons.append(leftLink)
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public class TwoLinkViewModel: MoleculeModelProtocol {
|
public class TwoLinkViewModel: ParentMoleculeModelProtocol {
|
||||||
public static var identifier: String = "twoLinkView"
|
public static var identifier: String = "twoLinkView"
|
||||||
public var id: String = UUID().uuidString
|
public var id: String = UUID().uuidString
|
||||||
|
|
||||||
@ -16,6 +16,8 @@ public class TwoLinkViewModel: MoleculeModelProtocol {
|
|||||||
public var rightLink: LinkModel?
|
public var rightLink: LinkModel?
|
||||||
public var leftLink: LinkModel?
|
public var leftLink: LinkModel?
|
||||||
|
|
||||||
|
public var children: [MoleculeModelProtocol] { [rightLink, leftLink].compactMap{ $0 } }
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case id
|
case id
|
||||||
case moleculeName
|
case moleculeName
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user