From f133bad78cf9f7824d0265e33967766386ae5f87 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 26 Mar 2020 12:48:23 -0400 Subject: [PATCH] accessibile togle --- MVMCoreUI/Atoms/Views/Toggle.swift | 3 ++- MVMCoreUI/Atoms/Views/ToggleModel.swift | 3 ++- MVMCoreUI/SupportingFiles/Strings/en.lproj/Localizable.strings | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Toggle.swift b/MVMCoreUI/Atoms/Views/Toggle.swift index e5d0c00b..90a5197d 100644 --- a/MVMCoreUI/Atoms/Views/Toggle.swift +++ b/MVMCoreUI/Atoms/Views/Toggle.swift @@ -127,6 +127,7 @@ public typealias ActionBlockConfirmation = () -> (Bool) private var widthConstraint: NSLayoutConstraint? private func constrainKnob() { + knobLeadingConstraint?.isActive = !isOn knobTrailingConstraint?.isActive = isOn } @@ -343,7 +344,7 @@ public typealias ActionBlockConfirmation = () -> (Bool) guard let model = model as? ToggleModel else { return } accessibilityLabel = model.accessibilityText ?? MVMCoreUIUtility.hardcodedString(withKey: "Toggle_buttonlabel") - + isOn = model.state FormValidator.setupValidation(molecule: model, delegate: delegateObject?.formHolderDelegate) setWithJSON(model.toJSON(), delegateObject: delegateObject, additionalData: additionalData) } diff --git a/MVMCoreUI/Atoms/Views/ToggleModel.swift b/MVMCoreUI/Atoms/Views/ToggleModel.swift index ce599083..53244dce 100644 --- a/MVMCoreUI/Atoms/Views/ToggleModel.swift +++ b/MVMCoreUI/Atoms/Views/ToggleModel.swift @@ -15,7 +15,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol { public static var identifier: String = "toggle" public var backgroundColor: Color? - public var state: Bool = true + public var state: Bool = false public var action: ActionModelProtocol? public var alternateAction: ActionModelProtocol? public var accessibilityText: String? @@ -60,6 +60,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol { required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + if let state = try typeContainer.decodeIfPresent(Bool.self, forKey: .state) { self.state = state } diff --git a/MVMCoreUI/SupportingFiles/Strings/en.lproj/Localizable.strings b/MVMCoreUI/SupportingFiles/Strings/en.lproj/Localizable.strings index cbf2611a..a7f4cdf2 100644 --- a/MVMCoreUI/SupportingFiles/Strings/en.lproj/Localizable.strings +++ b/MVMCoreUI/SupportingFiles/Strings/en.lproj/Localizable.strings @@ -46,7 +46,7 @@ // Switch / Toggle "mfswitch_buttonlabel" = "Switch Button"; -"Toggle_buttonlabel" = "Toggle Button" +"Toggle_buttonlabel" = "Toggle Button"; "AccOn" = "on"; "AccOff" = "off"; "AccToggleHint" = "double tap to toggle";