From 39b752d01b556b9fd0581c7fe2dd728b0920c4f0 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 12 Dec 2019 13:37:18 -0500 Subject: [PATCH] Included reset function. accounted for isAnimated state when changing isOn without animations. --- MVMCoreUI/Atoms/Views/Toggle.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Views/Toggle.swift b/MVMCoreUI/Atoms/Views/Toggle.swift index 2d056d24..aff1abb3 100644 --- a/MVMCoreUI/Atoms/Views/Toggle.swift +++ b/MVMCoreUI/Atoms/Views/Toggle.swift @@ -220,6 +220,18 @@ public typealias ActionBlockConfirmation = () -> (Bool) accessibilityLabel = MVMCoreUIUtility.hardcodedString(withKey: "Toggle_buttonlabel") } + public override func reset() { + super.reset() + + backgroundColor = containerTintColor?.off + knobView.backgroundColor = knobTintColor?.off + isAnimated = false + isOn = false + constrainKnob() + didToggleAction = nil + shouldToggleAction = { return true } + } + class func getContainerWidth() -> CGFloat { let containerWidth = Toggle.containerSize.width return (MFSizeObject(standardSize: containerWidth, standardiPadPortraitSize: CGFloat(Toggle.containerSize.width * 1.5)))?.getValueBasedOnApplicationWidth() ?? containerWidth @@ -265,9 +277,12 @@ public typealias ActionBlockConfirmation = () -> (Bool) private func changeStateNoAnimation(_ state: Bool) { + // Hold state in case User wanted isAnimated to remain off. + let isAnimatedState = isAnimated + isAnimated = false isOn = state - isAnimated = true + isAnimated = isAnimatedState } //--------------------------------------------------