From bf9562d2646716018bab192630a72c27728ec484 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 3 Aug 2022 11:44:35 -0500 Subject: [PATCH] refactored ViewProtocol removed @objcMembers from components Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 2 +- VDS/Classes/VDSControl.swift | 14 ++++++-------- VDS/Classes/VDSView.swift | 10 +++++----- VDS/Components/Checkbox/VDSCheckbox.swift | 19 ++++++------------- VDS/Components/Toggle/VDSToggle.swift | 21 ++++----------------- 5 files changed, 22 insertions(+), 44 deletions(-) diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 77873b97..7b0d076f 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -226,9 +226,9 @@ EA3361B4288B2A360071C351 /* Classes */ = { isa = PBXGroup; children = ( - EA3361B5288B2A410071C351 /* VDSControl.swift */, EA3C3B4B2894823E000CA526 /* AnyProxy-PropertyWrapper.swift */, EAF7F09D289AAEC000B287F5 /* VDSConstants.swift */, + EA3361B5288B2A410071C351 /* VDSControl.swift */, EAF7F09F289AB7EC00B287F5 /* VDSView.swift */, ); path = Classes; diff --git a/VDS/Classes/VDSControl.swift b/VDS/Classes/VDSControl.swift index 98c17788..8798a721 100644 --- a/VDS/Classes/VDSControl.swift +++ b/VDS/Classes/VDSControl.swift @@ -52,10 +52,10 @@ open class VDSControl: UIControl, ModelHandlerable, ViewPro public func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true - setupView() - } - cancellable = $model.debounce(for: .seconds(VDSConstants.ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] viewModel in - self?.onStateChange(viewModel: viewModel) + cancellable = $model.debounce(for: .seconds(VDSConstants.ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] viewModel in + self?.onStateChange(viewModel: viewModel) + } + setup() } } @@ -63,11 +63,9 @@ open class VDSControl: UIControl, ModelHandlerable, ViewPro backgroundColor = .clear } - // MARK: - ViewProtocol - open func updateView(_ size: CGFloat) { } - + // MARK: - ViewProtocol /// Will be called only once. - open func setupView() { + open func setup() { translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false } diff --git a/VDS/Classes/VDSView.swift b/VDS/Classes/VDSView.swift index 56174c0b..ed699316 100644 --- a/VDS/Classes/VDSView.swift +++ b/VDS/Classes/VDSView.swift @@ -52,10 +52,10 @@ open class VDSView: UIView, ModelHandlerable, ViewProtocol public func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true - setupView() - } - cancellable = $model.debounce(for: .seconds(VDSConstants.ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] viewModel in - self?.onStateChange(viewModel: viewModel) + cancellable = $model.debounce(for: .seconds(VDSConstants.ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] viewModel in + self?.onStateChange(viewModel: viewModel) + } + setup() } } @@ -67,7 +67,7 @@ open class VDSView: UIView, ModelHandlerable, ViewProtocol open func updateView(_ size: CGFloat) { } /// Will be called only once. - open func setupView() { + open func setup() { translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false } diff --git a/VDS/Components/Checkbox/VDSCheckbox.swift b/VDS/Components/Checkbox/VDSCheckbox.swift index f0804f2c..f2f15815 100644 --- a/VDS/Components/Checkbox/VDSCheckbox.swift +++ b/VDS/Components/Checkbox/VDSCheckbox.swift @@ -19,9 +19,9 @@ import Combine Knob: The circular indicator that slides on the container. */ -@objcMembers public class VDSCheckbox: VDSCheckboxBase{} +public class VDSCheckbox: VDSCheckboxBase{} -@objcMembers open class VDSCheckboxBase: VDSControl, Changable { +open class VDSCheckboxBase: VDSControl, Changable { //-------------------------------------------------- // MARK: - Private Properties @@ -185,16 +185,9 @@ import Combine //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - - public override func updateView(_ size: CGFloat) { - super.updateView(size) - - checkboxHeightConstraint?.constant = checkboxSize.height - checkboxWidthConstraint?.constant = checkboxSize.width - } - - public override func setupView() { - super.setupView() + + open override func setup() { + super.setup() self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(VDSCheckbox.toggleAndAction))) isAccessibilityElement = true @@ -398,7 +391,7 @@ import Combine } /// This will checkbox the state of the Checkbox and execute the actionBlock if provided. - public func toggleAndAction() { + @objc public func toggleAndAction() { isOn.toggle() onChange?() } diff --git a/VDS/Components/Toggle/VDSToggle.swift b/VDS/Components/Toggle/VDSToggle.swift index ca3412fd..3e41953b 100644 --- a/VDS/Components/Toggle/VDSToggle.swift +++ b/VDS/Components/Toggle/VDSToggle.swift @@ -18,9 +18,9 @@ import Combine Knob: The circular indicator that slides on the container. */ -@objcMembers public class VDSToggle: VDSToggleBase{} +public class VDSToggle: VDSToggleBase{} -@objcMembers open class VDSToggleBase: VDSControl, Changable { +open class VDSToggleBase: VDSControl, Changable { //-------------------------------------------------- // MARK: - Private Properties @@ -271,21 +271,8 @@ import Combine //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - public override func updateView(_ size: CGFloat) { - super.updateView(size) - - toggleHeightConstraint?.constant = toggleSize.height - toggleWidthConstraint?.constant = toggleSize.width - - knobHeightConstraint?.constant = knobSize.height - knobWidthConstraint?.constant = knobSize.width - - toggleView.layer.cornerRadius = toggleSize.height / 2.0 - knobView.layer.cornerRadius = toggleSize.height / 2.0 - } - - public override func setupView() { - super.setupView() + open override func setup() { + super.setup() isAccessibilityElement = true accessibilityTraits = .button