convert to kyle code for default handlers
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c975f2b06e
commit
61c5d5adf8
@ -92,19 +92,7 @@ open class Control<ModelType: Modelable>: UIControl, ModelHandlerable, ViewProto
|
|||||||
sendActions(for: .touchUpInside)
|
sendActions(for: .touchUpInside)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Actions
|
|
||||||
//--------------------------------------------------
|
|
||||||
open override func sendActions(for controlEvents: UIControl.Event) {
|
|
||||||
super.sendActions(for: controlEvents)
|
|
||||||
if controlEvents.contains(.touchUpInside) && executeDefaultAction{
|
|
||||||
defaultAction()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
open func defaultAction() { }
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -11,7 +11,15 @@ import VDSColorTokens
|
|||||||
import VDSFormControlsTokens
|
import VDSFormControlsTokens
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
public class Checkbox: CheckboxBase<DefaultCheckboxModel>{}
|
public class Checkbox: CheckboxBase<DefaultCheckboxModel>{
|
||||||
|
public override func initialSetup() {
|
||||||
|
super.initialSetup()
|
||||||
|
publisher(for: .touchUpInside)
|
||||||
|
.sink { control in
|
||||||
|
control.toggle()
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open class CheckboxBase<ModelType: CheckboxModel>: Control<ModelType>, Changable {
|
open class CheckboxBase<ModelType: CheckboxModel>: Control<ModelType>, Changable {
|
||||||
|
|
||||||
@ -210,7 +218,7 @@ open class CheckboxBase<ModelType: CheckboxModel>: Control<ModelType>, Changable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This will checkbox the state of the Selector and execute the actionBlock if provided.
|
/// This will checkbox the state of the Selector and execute the actionBlock if provided.
|
||||||
open override func defaultAction() {
|
open func toggle() {
|
||||||
//removed error
|
//removed error
|
||||||
if hasError && isSelected == false {
|
if hasError && isSelected == false {
|
||||||
hasError.toggle()
|
hasError.toggle()
|
||||||
|
|||||||
@ -11,7 +11,15 @@ import VDSColorTokens
|
|||||||
import VDSFormControlsTokens
|
import VDSFormControlsTokens
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
public class RadioBox: RadioBoxBase<DefaultRadioBoxModel>{}
|
public class RadioBox: RadioBoxBase<DefaultRadioBoxModel>{
|
||||||
|
public override func initialSetup() {
|
||||||
|
super.initialSetup()
|
||||||
|
publisher(for: .touchUpInside)
|
||||||
|
.sink { control in
|
||||||
|
control.toggle()
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open class RadioBoxBase<ModelType: RadioBoxModel>: Control<ModelType>, Changable {
|
open class RadioBoxBase<ModelType: RadioBoxModel>: Control<ModelType>, Changable {
|
||||||
|
|
||||||
@ -209,7 +217,7 @@ open class RadioBoxBase<ModelType: RadioBoxModel>: Control<ModelType>, Changable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This will radioBox the state of the Selector and execute the actionBlock if provided.
|
/// This will radioBox the state of the Selector and execute the actionBlock if provided.
|
||||||
open override func defaultAction() {
|
open func toggle() {
|
||||||
//removed error
|
//removed error
|
||||||
if hasError && isSelected == false {
|
if hasError && isSelected == false {
|
||||||
hasError.toggle()
|
hasError.toggle()
|
||||||
|
|||||||
@ -10,7 +10,17 @@ import UIKit
|
|||||||
import VDSColorTokens
|
import VDSColorTokens
|
||||||
import VDSFormControlsTokens
|
import VDSFormControlsTokens
|
||||||
|
|
||||||
public class RadioButton: RadioButtonBase<DefaultRadioButtonModel>{}
|
public class RadioButton: RadioButtonBase<DefaultRadioButtonModel>{ }
|
||||||
|
|
||||||
|
public class SoloRadioButton: RadioButtonBase<DefaultRadioButtonModel>{
|
||||||
|
public override func initialSetup() {
|
||||||
|
super.initialSetup()
|
||||||
|
publisher(for: .touchUpInside)
|
||||||
|
.sink { control in
|
||||||
|
control.toggle()
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open class RadioButtonBase<ModelType: RadioButtonModel>: Control<ModelType>, Changable {
|
open class RadioButtonBase<ModelType: RadioButtonModel>: Control<ModelType>, Changable {
|
||||||
|
|
||||||
@ -209,7 +219,7 @@ open class RadioButtonBase<ModelType: RadioButtonModel>: Control<ModelType>, Cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This will checkbox the state of the Selector and execute the actionBlock if provided.
|
/// This will checkbox the state of the Selector and execute the actionBlock if provided.
|
||||||
open override func defaultAction() {
|
open func toggle() {
|
||||||
guard !isSelected else { return }
|
guard !isSelected else { return }
|
||||||
|
|
||||||
//removed error
|
//removed error
|
||||||
|
|||||||
@ -11,7 +11,15 @@ import VDSColorTokens
|
|||||||
import VDSFormControlsTokens
|
import VDSFormControlsTokens
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
public class RadioSwatch: RadioSwatchBase<DefaultRadioSwatchModel>{}
|
public class RadioSwatch: RadioSwatchBase<DefaultRadioSwatchModel>{
|
||||||
|
public override func initialSetup() {
|
||||||
|
super.initialSetup()
|
||||||
|
publisher(for: .touchUpInside)
|
||||||
|
.sink { control in
|
||||||
|
control.toggle()
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open class RadioSwatchBase<ModelType: RadioSwatchModel>: Control<ModelType>, Changable {
|
open class RadioSwatchBase<ModelType: RadioSwatchModel>: Control<ModelType>, Changable {
|
||||||
|
|
||||||
@ -126,7 +134,7 @@ open class RadioSwatchBase<ModelType: RadioSwatchModel>: Control<ModelType>, Cha
|
|||||||
onChange = nil
|
onChange = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func defaultAction() {
|
open func toggle() {
|
||||||
isSelected.toggle()
|
isSelected.toggle()
|
||||||
sendActions(for: .valueChanged)
|
sendActions(for: .valueChanged)
|
||||||
onChange?()
|
onChange?()
|
||||||
@ -213,7 +221,6 @@ open class RadioSwatchBase<ModelType: RadioSwatchModel>: Control<ModelType>, Cha
|
|||||||
let borderColor = viewModel.selected ? radioSwatchBorderColorConfiguration.getColor(viewModel) : .clear
|
let borderColor = viewModel.selected ? radioSwatchBorderColorConfiguration.getColor(viewModel) : .clear
|
||||||
let fillBorderColor = radioSwatchFillBorderColorConfiguration.getColor(viewModel)
|
let fillBorderColor = radioSwatchFillBorderColorConfiguration.getColor(viewModel)
|
||||||
selectorView.backgroundColor = backgroundColor
|
selectorView.backgroundColor = backgroundColor
|
||||||
print("input: \(viewModel.inputId) enabled: \(viewModel.disabled) surface: \(viewModel.surface) selected: \(viewModel.selected) backgroundColor: \(backgroundColor.hexString)")
|
|
||||||
selectorView.layer.borderColor = borderColor.cgColor
|
selectorView.layer.borderColor = borderColor.cgColor
|
||||||
selectorView.layer.cornerRadius = selectorView.bounds.width * 0.5
|
selectorView.layer.cornerRadius = selectorView.bounds.width * 0.5
|
||||||
selectorView.layer.borderWidth = viewModel.selected ? selectorBorderWidth : 0
|
selectorView.layer.borderWidth = viewModel.selected ? selectorBorderWidth : 0
|
||||||
|
|||||||
@ -18,7 +18,15 @@ import Combine
|
|||||||
Knob: The circular indicator that slides on the container.
|
Knob: The circular indicator that slides on the container.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Toggle: ToggleBase<DefaultToggleModel>{}
|
public class Toggle: ToggleBase<DefaultToggleModel>{
|
||||||
|
public override func initialSetup() {
|
||||||
|
super.initialSetup()
|
||||||
|
publisher(for: .touchUpInside)
|
||||||
|
.sink { control in
|
||||||
|
control.toggle()
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open class ToggleBase<ModelType: ToggleModel>: Control<ModelType>, Changable {
|
open class ToggleBase<ModelType: ToggleModel>: Control<ModelType>, Changable {
|
||||||
|
|
||||||
@ -316,7 +324,7 @@ open class ToggleBase<ModelType: ToggleModel>: Control<ModelType>, Changable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This will toggle the state of the Toggle and execute the actionBlock if provided.
|
/// This will toggle the state of the Toggle and execute the actionBlock if provided.
|
||||||
open override func defaultAction() {
|
open func toggle() {
|
||||||
isOn.toggle()
|
isOn.toggle()
|
||||||
sendActions(for: .valueChanged)
|
sendActions(for: .valueChanged)
|
||||||
onChange?()
|
onChange?()
|
||||||
|
|||||||
@ -70,16 +70,14 @@ extension SelectorGroupModelHandlerable {
|
|||||||
|
|
||||||
///MARK: Groups that allow single selections
|
///MARK: Groups that allow single selections
|
||||||
public protocol SelectorGroupSelectedModelHandlerable: SelectorGroupModelHandlerable {
|
public protocol SelectorGroupSelectedModelHandlerable: SelectorGroupModelHandlerable {
|
||||||
var selectedInputId: String? { get set }
|
func didSelect(_ selectedControl: ModelHandlerType)
|
||||||
func didSelect(selector: ModelHandlerType.ModelType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SelectorGroupSelectedModelHandlerable {
|
extension SelectorGroupSelectedModelHandlerable {
|
||||||
|
|
||||||
public var selectedModel: ModelHandlerType.ModelType? {
|
public var selectedModel: ModelHandlerType.ModelType? {
|
||||||
guard let selectedInputId else { return nil }
|
|
||||||
if let index = model.selectors.firstIndex(where: { element in
|
if let index = model.selectors.firstIndex(where: { element in
|
||||||
return element.inputId == selectedInputId
|
return element.selected == true
|
||||||
}) {
|
}) {
|
||||||
return model.selectors[index]
|
return model.selectors[index]
|
||||||
} else {
|
} else {
|
||||||
@ -92,43 +90,35 @@ extension SelectorGroupSelectedModelHandlerable {
|
|||||||
let newSelectorView = ModelHandlerType(with: selector)
|
let newSelectorView = ModelHandlerType(with: selector)
|
||||||
|
|
||||||
//add the selectedPublisher for the change
|
//add the selectedPublisher for the change
|
||||||
newSelectorView.publisher(for: .valueChanged)
|
newSelectorView
|
||||||
.sink(receiveValue: { [weak self] control in
|
.publisher(for: .touchUpInside)
|
||||||
guard self?.model.selectors.count ?? 0 > 0 else { return }
|
.sink { [weak self] control in
|
||||||
self?.didSelect(selector: control.model)
|
self?.didSelect(control)
|
||||||
})
|
|
||||||
.store(in: &subscribers)
|
|
||||||
|
|
||||||
//add model update to the subscribers
|
|
||||||
newSelectorView.handlerPublisher()
|
|
||||||
.sink { [weak self] model in
|
|
||||||
if let cached = self?.getCachedSelector(viewModel: model), newSelectorView.shouldUpdateView(viewModel: cached) {
|
|
||||||
self?.replace(viewModel: model)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.store(in: &subscribers)
|
.store(in: &subscribers)
|
||||||
|
|
||||||
|
|
||||||
return newSelectorView
|
return newSelectorView
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func didSelect(selector: ModelHandlerType.ModelType) {
|
public func didSelect(_ selectedControl: ModelHandlerType) {
|
||||||
|
//only changes local model in control,
|
||||||
if let selectedModel, let cached = getCachedSelector(viewModel: selectedModel) {
|
//this is now disconnected from the parent model
|
||||||
let oldSelectedModel = cached.copyWith {
|
selectorViews.forEach { control in
|
||||||
$0.selected = false
|
//only change the old and new
|
||||||
|
if control == selectedControl {
|
||||||
|
if var cached = getCachedSelector(viewModel: control.model) {
|
||||||
|
cached.selected = true
|
||||||
|
replace(viewModel: cached)
|
||||||
|
}
|
||||||
|
} else if control.isSelected {
|
||||||
|
if var cached = getCachedSelector(viewModel: control.model) {
|
||||||
|
cached.selected = false
|
||||||
|
replace(viewModel: cached)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
replace(viewModel: oldSelectedModel)
|
|
||||||
}
|
|
||||||
|
|
||||||
//only select is selected
|
|
||||||
if selector.selected {
|
|
||||||
var newSelectedModel = selector
|
|
||||||
newSelectedModel.selected = true
|
|
||||||
replace(viewModel: newSelectedModel)
|
|
||||||
selectedInputId = selector.inputId
|
|
||||||
} else {
|
|
||||||
//ensure current value is removed
|
|
||||||
selectedInputId = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user