Commit af81c22e by Daniel Dahan

minor cleanup for extension reference in Switch

parent ec3e3e8c
...@@ -371,7 +371,9 @@ extension Switch { ...@@ -371,7 +371,9 @@ extension Switch {
open func setSwitchState(state: SwitchState, animated: Bool = true, completion: ((Switch) -> Void)? = nil) { open func setSwitchState(state: SwitchState, animated: Bool = true, completion: ((Switch) -> Void)? = nil) {
updateSwitchState(state: state, animated: animated, isTriggeredByUserInteraction: false, completion: completion) updateSwitchState(state: state, animated: animated, isTriggeredByUserInteraction: false, completion: completion)
} }
}
fileprivate extension Switch {
/** /**
Set the switchState property with an option to animate. Set the switchState property with an option to animate.
- Parameter state: The SwitchState to set. - Parameter state: The SwitchState to set.
...@@ -414,14 +416,12 @@ extension Switch { ...@@ -414,14 +416,12 @@ extension Switch {
delegate?.switchDidChangeState(control: self, state: internalSwitchState) delegate?.switchDidChangeState(control: self, state: internalSwitchState)
} }
} }
}
extension Switch {
/** /**
Updates the coloring for the enabled state. Updates the coloring for the enabled state.
- Parameter state: SwitchState. - Parameter state: SwitchState.
*/ */
fileprivate func updateColorForState(state: SwitchState) { func updateColorForState(state: SwitchState) {
if .on == state { if .on == state {
button.backgroundColor = buttonOnColor button.backgroundColor = buttonOnColor
track.backgroundColor = trackOnColor track.backgroundColor = trackOnColor
...@@ -435,7 +435,7 @@ extension Switch { ...@@ -435,7 +435,7 @@ extension Switch {
Updates the coloring for the disabled state. Updates the coloring for the disabled state.
- Parameter state: SwitchState. - Parameter state: SwitchState.
*/ */
fileprivate func updateColorForDisabledState(state: SwitchState) { func updateColorForDisabledState(state: SwitchState) {
if .on == state { if .on == state {
button.backgroundColor = buttonOnDisabledColor button.backgroundColor = buttonOnDisabledColor
track.backgroundColor = trackOnDisabledColor track.backgroundColor = trackOnDisabledColor
...@@ -449,22 +449,23 @@ extension Switch { ...@@ -449,22 +449,23 @@ extension Switch {
Updates the style based on the state. Updates the style based on the state.
- Parameter state: The SwitchState to set the style to. - Parameter state: The SwitchState to set the style to.
*/ */
fileprivate func styleForState(state: SwitchState) { func styleForState(state: SwitchState) {
if isEnabled { if isEnabled {
updateColorForState(state: state) updateColorForState(state: state)
} else { } else {
updateColorForDisabledState(state: state) updateColorForDisabledState(state: state)
} }
} }
} }
extension Switch { fileprivate extension Switch {
/** /**
Set the switchState property with an animate. Set the switchState property with an animate.
- Parameter state: The SwitchState to set. - Parameter state: The SwitchState to set.
- Parameter completion: An Optional completion block. - Parameter completion: An Optional completion block.
*/ */
fileprivate func animateToState(state: SwitchState, completion: ((Switch) -> Void)? = nil) { func animateToState(state: SwitchState, completion: ((Switch) -> Void)? = nil) {
isUserInteractionEnabled = false isUserInteractionEnabled = false
UIView.animate(withDuration: 0.15, UIView.animate(withDuration: 0.15,
delay: 0.05, delay: 0.05,
...@@ -496,14 +497,14 @@ extension Switch { ...@@ -496,14 +497,14 @@ extension Switch {
} }
} }
extension Switch { fileprivate extension Switch {
/** /**
Handle the TouchUpOutside and TouchCancel moments. Handle the TouchUpOutside and TouchCancel moments.
- Parameter sender: A UIButton. - Parameter sender: A UIButton.
- Parameter event: A UIEvent. - Parameter event: A UIEvent.
*/ */
@objc @objc
fileprivate func handleTouchUpOutsideOrCanceled(sender: FABButton, event: UIEvent) { func handleTouchUpOutsideOrCanceled(sender: FABButton, event: UIEvent) {
guard let v = event.touches(for: sender)?.first else { guard let v = event.touches(for: sender)?.first else {
return return
} }
...@@ -514,7 +515,7 @@ extension Switch { ...@@ -514,7 +515,7 @@ extension Switch {
/// Handles the TouchUpInside event. /// Handles the TouchUpInside event.
@objc @objc
fileprivate func handleTouchUpInside() { func handleTouchUpInside() {
updateSwitchState(state: isOn ? .off : .on, animated: true, isTriggeredByUserInteraction: true) updateSwitchState(state: isOn ? .off : .on, animated: true, isTriggeredByUserInteraction: true)
} }
...@@ -524,7 +525,7 @@ extension Switch { ...@@ -524,7 +525,7 @@ extension Switch {
- Parameter event: A UIEvent. - Parameter event: A UIEvent.
*/ */
@objc @objc
fileprivate func handleTouchDragInside(sender: FABButton, event: UIEvent) { func handleTouchDragInside(sender: FABButton, event: UIEvent) {
guard let v = event.touches(for: sender)?.first else { guard let v = event.touches(for: sender)?.first else {
return return
} }
...@@ -539,14 +540,14 @@ extension Switch { ...@@ -539,14 +540,14 @@ extension Switch {
} }
} }
extension Switch { fileprivate extension Switch {
/// Prepares the track. /// Prepares the track.
fileprivate func prepareTrack() { func prepareTrack() {
addSubview(track) addSubview(track)
} }
/// Prepares the button. /// Prepares the button.
fileprivate func prepareButton() { func prepareButton() {
button.addTarget(self, action: #selector(handleTouchUpInside), for: .touchUpInside) button.addTarget(self, action: #selector(handleTouchUpInside), for: .touchUpInside)
button.addTarget(self, action: #selector(handleTouchDragInside), for: .touchDragInside) button.addTarget(self, action: #selector(handleTouchDragInside), for: .touchDragInside)
button.addTarget(self, action: #selector(handleTouchUpOutsideOrCanceled), for: .touchCancel) button.addTarget(self, action: #selector(handleTouchUpOutsideOrCanceled), for: .touchCancel)
...@@ -559,7 +560,7 @@ extension Switch { ...@@ -559,7 +560,7 @@ extension Switch {
init to set the state value and have an effect. init to set the state value and have an effect.
- Parameter state: The SwitchState to set. - Parameter state: The SwitchState to set.
*/ */
fileprivate func prepareSwitchState(state: SwitchState = .off) { func prepareSwitchState(state: SwitchState = .off) {
updateSwitchState(state: state, animated: false, isTriggeredByUserInteraction: false) updateSwitchState(state: state, animated: false, isTriggeredByUserInteraction: false)
} }
...@@ -568,7 +569,7 @@ extension Switch { ...@@ -568,7 +569,7 @@ extension Switch {
init to set the state value and have an effect. init to set the state value and have an effect.
- Parameter style: The SwitchStyle to set. - Parameter style: The SwitchStyle to set.
*/ */
fileprivate func prepareSwitchStyle(style: SwitchStyle = .light) { func prepareSwitchStyle(style: SwitchStyle = .light) {
switchStyle = style switchStyle = style
} }
...@@ -577,7 +578,7 @@ extension Switch { ...@@ -577,7 +578,7 @@ extension Switch {
init to set the size value and have an effect. init to set the size value and have an effect.
- Parameter size: The SwitchSize to set. - Parameter size: The SwitchSize to set.
*/ */
fileprivate func prepareSwitchSize(size: SwitchSize = .medium) { func prepareSwitchSize(size: SwitchSize = .medium) {
switchSize = size switchSize = size
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment