From 83370956c1b43cdec3a389e23d59d078e43f1993 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 10 Dec 2019 10:34:08 -0500 Subject: [PATCH] movemt,. --- MVMCoreUI/Atoms/Views/Switch.swift | 34 ++++++++++++------------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Switch.swift b/MVMCoreUI/Atoms/Views/Switch.swift index 8ea86227..da2c13bf 100644 --- a/MVMCoreUI/Atoms/Views/Switch.swift +++ b/MVMCoreUI/Atoms/Views/Switch.swift @@ -9,8 +9,6 @@ import MVMCore import UIKit -public typealias ValueChangeBlock = () -> () - /** A custom implementation of Apple's UISwitch. @@ -27,11 +25,11 @@ public typealias ValueChangeBlock = () -> () public var disabledTintColor: (track: UIColor?, thumb: UIColor?)? = (track: .mfSilver(), thumb: .white) private var valueShouldChange = false - private var canChangeValue = false +// private var canChangeValue = false private var shouldTouchToSwitch = false - private var valueChangedBlock: ValueChangeBlock? - private var actionBlock: ValueChangeBlock? + private var valueChangedBlock: ActionBlock? + private var actionBlock: ActionBlock? // Sizes are from InVision design specs. static let trackSize = CGSize(width: 46, height: 24) @@ -90,13 +88,13 @@ public typealias ValueChangeBlock = () -> () self.init(frame: .zero) } - public convenience init(isOn: Bool, changeBlock: ValueChangeBlock?) { + public convenience init(isOn: Bool, changeBlock: ActionBlock?) { self.init(frame: .zero) self.isOn = isOn valueChangedBlock = changeBlock } - public convenience init(changeBlock: ValueChangeBlock?) { + public convenience init(changeBlock: ActionBlock?) { self.init(frame: .zero) valueChangedBlock = changeBlock } @@ -116,19 +114,19 @@ public typealias ValueChangeBlock = () -> () heightConstraint?.constant = Switch.getTrackHeight() widthConstraint?.constant = Switch.getTrackWidth() - layer.cornerRadius = Switch.getTrackHeight() / 2.0 - thumbView.layer.cornerRadius = Switch.getThumbHeight() / 2.0 - thumbHeightConstraint?.constant = Switch.getThumbHeight() thumbWidthConstraint?.constant = Switch.getThumbWidth() + + layer.cornerRadius = Switch.getTrackHeight() / 2.0 + thumbView.layer.cornerRadius = Switch.getThumbHeight() / 2.0 } public override func setupView() { super.setupView() - guard !subviews.isEmpty else { return } + guard subviews.isEmpty else { return } - canChangeValue = true +// canChangeValue = true shouldTouchToSwitch = true valueShouldChange = true @@ -263,11 +261,6 @@ public typealias ValueChangeBlock = () -> () valueShouldChange = true } - open override func touchesEnded(_ touches: Set, with event: UIEvent?) { - - sendActions(for: .touchUpInside) - } - public func touchesMoved(_ touches: Set, with event: UIEvent) { if shouldTouchToSwitch { @@ -304,14 +297,13 @@ public typealias ValueChangeBlock = () -> () if shouldTouchToSwitch { thumbReformAnimation(true) - canChangeValue = true } sendActions(for: .touchCancel) } //-------------------------------------------------- - // MARK: - Animation + // MARK: - Animations //-------------------------------------------------- public func thumbEnlargeAnimation() { @@ -443,10 +435,10 @@ extension Switch { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) self.delegateObject = delegateObject - guard let dictionary = json else { return } - FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol) + guard let dictionary = json else { return } + if let color = dictionary["onTintColor"] as? String { trackTintColor?.on = UIColor.mfGet(forHex: color) }