updated tilet atom
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
715012aea4
commit
27cc79c542
@ -13,176 +13,57 @@ import VDS
|
|||||||
/**
|
/**
|
||||||
This class expects its height and width to be equal.
|
This class expects its height and width to be equal.
|
||||||
*/
|
*/
|
||||||
open class Tilet: VDS.Tilet, MVMCoreUIViewConstrainingProtocol, MoleculeViewProtocol {
|
open class Tilet: VDS.Tilet, VDSMoleculeViewProtocol {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
public var viewModel: TiletModel!
|
||||||
var delegateObject: MVMCoreUIDelegateObject?
|
public var delegateObject: MVMCoreUIDelegateObject?
|
||||||
|
public var additionalData: [AnyHashable: Any]?
|
||||||
public var checkboxModel: CheckboxModel?
|
|
||||||
|
|
||||||
/// Disables all selection logic when setting the value of isSelected, reducing it to a stored property.
|
|
||||||
public var updateSelectionOnly: Bool = false
|
|
||||||
|
|
||||||
/// Action Block called when the switch is selected.
|
|
||||||
public var actionBlock: ActionBlock?
|
|
||||||
|
|
||||||
/**
|
|
||||||
The represented state of the Checkbox.
|
|
||||||
|
|
||||||
Setting updateSelectionOnly to true bypasses the animation logic inherent with setting this property.
|
|
||||||
*/
|
|
||||||
override open var isSelected: Bool {
|
|
||||||
didSet {
|
|
||||||
if !updateSelectionOnly {
|
|
||||||
checkboxModel?.selected = isSelected
|
|
||||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
|
||||||
updateAccessibilityLabel()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
override public init(frame: CGRect) {
|
|
||||||
super.init(frame: frame)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// There is currently no intention on using xib files.
|
|
||||||
required public init?(coder aDecoder: NSCoder) {
|
|
||||||
super.init(coder: aDecoder)
|
|
||||||
fatalError("xib file is not implemented for Checkbox.")
|
|
||||||
}
|
|
||||||
|
|
||||||
public convenience required init() {
|
public convenience required init() {
|
||||||
self.init(frame:.zero)
|
|
||||||
}
|
|
||||||
|
|
||||||
public convenience init(isChecked: Bool) {
|
|
||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
checkAndBypassAnimations(selected: isChecked)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Lifecycle
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
open override func initialSetup() {
|
|
||||||
super.initialSetup()
|
|
||||||
|
|
||||||
publisher(for: .touchUpInside)
|
|
||||||
.sink {[weak self] toggle in
|
|
||||||
guard let self = self else { return }
|
|
||||||
self.toggleAndAction()
|
|
||||||
}.store(in: &subscribers)
|
|
||||||
|
|
||||||
accessibilityHintEnabled = MVMCoreUIUtility.hardcodedString(withKey: "checkbox_action_hint")
|
|
||||||
updateAccessibilityLabel()
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Actions
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
/// This will toggle the state of the Checkbox and execute the actionBlock if provided.
|
|
||||||
public func toggleAndAction() {
|
|
||||||
isSelected.toggle()
|
|
||||||
actionBlock?()
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Methods
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
/// Programmatic means to check/uncheck the box.
|
|
||||||
/// - parameter selected: state of the check box: true = checked OR false = unchecked.
|
|
||||||
/// - parameter animated: allows the state of the checkbox to change with or without animation.
|
|
||||||
public func updateSelection(to selected: Bool, animated: Bool) {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.checkAndBypassAnimations(selected: selected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Adjust accessibility label based on state of Checkbox.
|
|
||||||
func updateAccessibilityLabel() {
|
|
||||||
// Attention: This needs to be addressed with the accessibility team.
|
|
||||||
// NOTE: Currently emptying description part of MVMCoreUICheckBox accessibility label to avoid crashing!
|
|
||||||
if let state = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "checkbox_checked_state" : "checkbox_unchecked_state") {
|
|
||||||
accessibilityLabel = String(format: MVMCoreUIUtility.hardcodedString(withKey: "checkbox_desc_state") ?? "%@%@", "", state)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func checkAndBypassAnimations(selected: Bool) {
|
|
||||||
updateSelectionOnly = true
|
|
||||||
isSelected = selected
|
|
||||||
updateSelectionOnly = false
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - UITouch
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
override open func accessibilityActivate() -> Bool {
|
|
||||||
guard isEnabled else { return false }
|
|
||||||
sendActions(for: .touchUpInside)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Molecular
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
open func needsToBeConstrained() -> Bool { true }
|
|
||||||
|
|
||||||
open func updateView(_ size: CGFloat) {}
|
open func updateView(_ size: CGFloat) {}
|
||||||
|
|
||||||
open override func reset() {
|
open override func updateView() {
|
||||||
super.reset()
|
super.updateView()
|
||||||
|
//we want to overwrite the VDS color that is set in the ToggleBase
|
||||||
isEnabled = true
|
//for surface since the Atomic controls doesn't look at
|
||||||
checkAndBypassAnimations(selected: false)
|
//surface today for its views. We just want to show whatever
|
||||||
|
//the current parent's background color.
|
||||||
|
backgroundColor = .clear
|
||||||
}
|
}
|
||||||
|
|
||||||
private func performCheckboxAction(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
public func viewModelDidUpdate() {
|
||||||
MVMCoreUIActionHandler.performActionUnstructured(with: actionModel, sourceModel: checkboxModel, additionalData: additionalData, delegateObject: delegateObject)
|
surface = viewModel.surface
|
||||||
|
titleModel = viewModel.title
|
||||||
|
subTitleModel = viewModel.subTitle
|
||||||
|
badgeModel = viewModel.badge
|
||||||
|
descriptiveIconModel = viewModel.descriptiveIcon
|
||||||
|
directionalIconModel = viewModel.directionalIcon
|
||||||
|
width = viewModel.width
|
||||||
|
textWidth = viewModel.textWidth
|
||||||
|
textPercentage = viewModel.textPercentage
|
||||||
|
}
|
||||||
|
|
||||||
|
//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? {
|
||||||
|
nil
|
||||||
}
|
}
|
||||||
|
|
||||||
public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
}
|
||||||
self.delegateObject = delegateObject
|
|
||||||
|
// MARK: - MVMCoreUIViewConstrainingProtocol
|
||||||
guard let model = model as? CheckboxModel else { return }
|
extension Tilet: MVMCoreUIViewConstrainingProtocol {
|
||||||
checkboxModel = model
|
|
||||||
|
public func needsToBeConstrained() -> Bool { true }
|
||||||
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
|
|
||||||
|
public func horizontalAlignment() -> UIStackView.Alignment { .trailing }
|
||||||
if model.selected {
|
|
||||||
checkAndBypassAnimations(selected: model.selected)
|
|
||||||
}
|
|
||||||
|
|
||||||
model.updateUI = { [weak self] in
|
|
||||||
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
|
||||||
guard let self = self else { return }
|
|
||||||
self.isEnabled = model.enabled && !model.readOnly
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled = model.enabled && !model.readOnly
|
|
||||||
|
|
||||||
if (model.action != nil || model.offAction != nil) {
|
|
||||||
actionBlock = { [weak self] in
|
|
||||||
guard let self = self else { return }
|
|
||||||
|
|
||||||
if let offAction = model.offAction, !self.isSelected {
|
|
||||||
self.performCheckboxAction(with: offAction, delegateObject: delegateObject, additionalData: additionalData)
|
|
||||||
|
|
||||||
} else if let action = model.action {
|
|
||||||
self.performCheckboxAction(with: action, delegateObject: delegateObject, additionalData: additionalData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,9 +20,9 @@ open class TiletModel: MoleculeModelProtocol {
|
|||||||
public var badge: TiletBadgeModel?
|
public var badge: TiletBadgeModel?
|
||||||
public var title: TiletTitleModel?
|
public var title: TiletTitleModel?
|
||||||
public var subTitle: TiletSubTitleModel?
|
public var subTitle: TiletSubTitleModel?
|
||||||
public var desriptiveIcon: TiletDescriptiveIcon?
|
public var descriptiveIcon: TiletDescriptiveIcon?
|
||||||
public var directionalIcon: TiletDirectionalIcon?
|
public var directionalIcon: TiletDirectionalIcon?
|
||||||
public var width: Double?
|
public var width: CGFloat?
|
||||||
public var textWidth: Double?
|
public var textWidth: CGFloat?
|
||||||
public var textPercentage: Double?
|
public var textPercentage: CGFloat?
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user