From 143ebccb3410be3ea0990e06b5bcd149d5d40a4c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 13 Jan 2022 10:57:18 -0600 Subject: [PATCH] remove readOnly from the Views and now using the isEnabled and model is controlling this based off enabled & readOnly Signed-off-by: Matt Bruce --- .../TextFields/DigitEntryField.swift | 8 ------- .../BaseDropdownEntryField.swift | 10 +------- .../FormFields/TextFields/EntryField.swift | 16 ++----------- .../TextFields/TextEntryField.swift | 2 +- .../TextFields/TextViewEntryField.swift | 23 +----------------- .../Atomic/Atoms/Selectors/Checkbox.swift | 24 ++++--------------- MVMCoreUI/Atomic/Atoms/Selectors/Heart.swift | 11 ++++----- .../Atomic/Atoms/Selectors/RadioBox.swift | 15 ++++-------- .../Atomic/Atoms/Selectors/RadioButton.swift | 7 +++--- .../Atomic/Atoms/Selectors/RadioSwatch.swift | 18 ++++---------- MVMCoreUI/Atomic/Atoms/Selectors/Toggle.swift | 17 ++++--------- .../CarouselIndicator/BarsIndicatorView.swift | 18 +++----------- .../NumericIndicatorView.swift | 8 ++----- MVMCoreUI/BaseClasses/Control.swift | 8 ------- .../Views/EntryFieldContainer.swift | 15 ------------ 15 files changed, 36 insertions(+), 164 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DigitEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DigitEntryField.swift index f3fa96ba..c70d458e 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DigitEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DigitEntryField.swift @@ -90,14 +90,6 @@ import UIKit } } - public override var isReadOnly: Bool { - get { super.isReadOnly } - set (readOnly){ - digitBoxes.forEach { $0.isReadOnly = readOnly } - super.isReadOnly = readOnly - } - } - public override var showError: Bool { get { super.showError } set (error) { diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/Dropdown Fields/BaseDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/Dropdown Fields/BaseDropdownEntryField.swift index f70b0ce0..6e8be5f1 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/Dropdown Fields/BaseDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/Dropdown Fields/BaseDropdownEntryField.swift @@ -44,15 +44,7 @@ import UIKit super.isEnabled = enabled } } - - @objc public override var isReadOnly: Bool { - get { super.isReadOnly } - set (readOnly) { - dropDownCaretView.isEnabled = !readOnly - super.isReadOnly = readOnly - } - } - + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryField.swift index 1a64a0a5..891594a4 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryField.swift @@ -90,18 +90,7 @@ import UIKit titleLabel.isRequired = isRequired } } - - /// Toggles readOnly (original) or disabled UI. - public var isReadOnly: Bool { - get { entryFieldContainer.isReadOnly } - set (readOnly) { - if(entryFieldContainer.isReadOnly != readOnly){ - entryFieldContainer.isReadOnly = readOnly - entryFieldModel?.readOnly = readOnly - } - } - } - + /// Toggles error or original UI. public var showError: Bool { get { entryFieldContainer.showError } @@ -317,8 +306,7 @@ import UIKit titleLabel.setup(model: model.titleStateLabel, delegateObject, additionalData) feedbackLabel.setup(model: model.feedbackStateLabel, delegateObject, additionalData) - isEnabled = model.enabled - isReadOnly = model.readOnly + isEnabled = model.enabled && !model.readOnly isRequired = model.required model.updateUI = { [weak self] in MVMCoreDispatchUtility.performBlock(onMainThread: { diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextEntryField.swift index cd0adf61..7973d652 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextEntryField.swift @@ -69,7 +69,7 @@ import UIKit guard let self = self else { return } self.textField.isEnabled = enabled - self.textField.textColor = enabled && !self.isReadOnly ? self.textEntryFieldModel?.enabledTextColor.uiColor : self.textEntryFieldModel?.disabledTextColor.uiColor + self.textField.textColor = enabled ? self.textEntryFieldModel?.enabledTextColor.uiColor : self.textEntryFieldModel?.disabledTextColor.uiColor } } } diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryField.swift index 8c1cafa8..3221f043 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryField.swift @@ -46,25 +46,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele if self.textView.isShowingPlaceholder { self.textView.textColor = self.textView.placeholderTextColor } else { - self.textView.textColor = (enabled && !self.isReadOnly ? self.textViewEntryFieldModel?.enabledTextColor : self.textViewEntryFieldModel?.disabledTextColor)?.uiColor - } - } - } - } - - public override var isReadOnly: Bool { - get { super.isReadOnly } - set (readOnly) { - super.isReadOnly = readOnly - - DispatchQueue.main.async { [weak self] in - guard let self = self else { return } - - self.textView.isEnabled = !readOnly - if self.textView.isShowingPlaceholder { - self.textView.textColor = self.textView.placeholderTextColor - } else { - self.textView.textColor = (!readOnly ? self.textViewEntryFieldModel?.enabledTextColor : self.textViewEntryFieldModel?.disabledTextColor)?.uiColor + self.textView.textColor = (self.textView.isEnabled ? self.textViewEntryFieldModel?.enabledTextColor : self.textViewEntryFieldModel?.disabledTextColor)?.uiColor } } } @@ -300,8 +282,5 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele adjustMarginConstraints(constant: 0) } - if !model.enabled { - isEnabled = false - } } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index 8fbb2bea..4bd64c7c 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -84,7 +84,7 @@ import MVMCore isUserInteractionEnabled = isEnabled - if isEnabled && !self.isReadOnly { + if isEnabled { layer.borderColor = borderColor.cgColor backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor setShapeLayerStrokeColor(checkColor) @@ -95,21 +95,7 @@ import MVMCore } } } - - public override var isReadOnly: Bool { - didSet{ - if isReadOnly { - layer.borderColor = disabledBorderColor.cgColor - backgroundColor = disabledBackgroundColor - setShapeLayerStrokeColor(disabledCheckColor) - } else { - layer.borderColor = borderColor.cgColor - backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor - setShapeLayerStrokeColor(checkColor) - } - } - } - + public var disabledBackgroundColor: UIColor = .clear public var disabledBorderColor: UIColor = .mvmCoolGray3 public var disabledCheckColor: UIColor = .mvmCoolGray3 @@ -253,7 +239,7 @@ import MVMCore self.shapeLayer = shapeLayer shapeLayer.frame = bounds layer.addSublayer(shapeLayer) - shapeLayer.strokeColor = isEnabled || !isReadOnly ? checkColor.cgColor : disabledCheckColor.cgColor + shapeLayer.strokeColor = isEnabled ? checkColor.cgColor : disabledCheckColor.cgColor shapeLayer.fillColor = UIColor.clear.cgColor shapeLayer.path = checkMarkPath() shapeLayer.lineJoin = .miter @@ -382,7 +368,6 @@ import MVMCore super.reset() isEnabled = true - isReadOnly = false shapeLayer?.removeAllAnimations() shapeLayer?.removeFromSuperlayer() shapeLayer = nil @@ -445,8 +430,7 @@ import MVMCore }) } - isEnabled = model.enabled - isReadOnly = model.readOnly + isEnabled = model.enabled && !model.readOnly if (model.action != nil || model.offAction != nil) { actionBlock = { [weak self] in diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Heart.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Heart.swift index cd423dca..eb0b0b4c 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Heart.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Heart.swift @@ -62,7 +62,7 @@ import UIKit heartPath.close() heart.path = heartPath.cgPath heart.fillColor = isSelected ? heartModel?.activeColor.cgColor : heartModel?.inActiveColor.cgColor - heart.opacity = isEnabled || !isReadOnly ? 1.0 : 0.5 + heart.opacity = isEnabled ? 1.0 : 0.5 heart.lineWidth = 1 heart.strokeColor = isSelected ? UIColor.clear.cgColor : UIColor.mvmBlack.cgColor return heart @@ -88,8 +88,7 @@ import UIKit self.additionalData = additionalData guard let model = model as? HeartModel else { return } isSelected = model.isActive - isEnabled = model.enabled - isReadOnly = model.readOnly + isEnabled = model.enabled && !model.readOnly updateAccessibilityLabel() } @@ -98,13 +97,13 @@ import UIKit //-------------------------------------------------- /// Adjust accessibility label based on selection of Heart. func updateAccessibilityLabel() { - accessibilityHint = isEnabled || !isReadOnly ? MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "heart_unfavorite_action_hint" : "heart_favorite_action_hint") : nil - accessibilityTraits = isEnabled || !isReadOnly ? .button : .none + accessibilityHint = isEnabled ? MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "heart_unfavorite_action_hint" : "heart_favorite_action_hint") : nil + accessibilityTraits = isEnabled ? .button : .none accessibilityLabel = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "heart_selected_state" : "heart_not_selected_state") } func tapAction() { - guard isEnabled, !isReadOnly else { return } + guard isEnabled else { return } isSelected = !isSelected if let heartModel = heartModel { Button.performButtonAction(with: heartModel.action, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: heartModel) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift index 693fe2a4..27323048 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift @@ -39,11 +39,7 @@ open class RadioBox: Control, MFButtonProtocol { public override var isEnabled: Bool { didSet { updateAccessibility() } } - - public override var isReadOnly: Bool { - didSet { updateAccessibility() } - } - + //-------------------------------------------------- // MARK: - MVMCoreViewProtocol //-------------------------------------------------- @@ -93,8 +89,7 @@ open class RadioBox: Control, MFButtonProtocol { accentColor = color } isSelected = model.selected - isEnabled = model.enabled - isReadOnly = model.readOnly + isEnabled = model.enabled && !model.readOnly } open override func reset() { @@ -129,7 +124,7 @@ open class RadioBox: Control, MFButtonProtocol { // Handle Mask maskLayer?.removeFromSuperlayer() - if !isEnabled || isReadOnly { + if !isEnabled { let mask = getMaskLayer() layer.mask = mask maskLayer = mask @@ -143,7 +138,7 @@ open class RadioBox: Control, MFButtonProtocol { } @objc open func selectBox() { - guard isEnabled, !isReadOnly, !isSelected else { return } + guard isEnabled, !isSelected else { return } isSelected = true radioBoxModel?.selected = isSelected if let radioBoxModel = radioBoxModel, let actionModel = radioBoxModel.action { @@ -242,7 +237,7 @@ open class RadioBox: Control, MFButtonProtocol { accessibilityTraits.insert(.selected) } - if !isEnabled || isReadOnly { + if !isEnabled { accessibilityTraits.insert(.notEnabled) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift index 11b917b0..1854f943 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift @@ -66,7 +66,7 @@ import UIKit open override func draw(_ rect: CGRect) { guard let context = UIGraphicsGetCurrentContext() else { return } - let color = (isReadOnly == true || isEnabled == false) ? disabledColor.cgColor : enabledColor.cgColor + let color = isEnabled == false ? disabledColor.cgColor : enabledColor.cgColor layer.cornerRadius = bounds.width * 0.5 layer.borderColor = color layer.borderWidth = bounds.width * 0.0333 @@ -88,7 +88,7 @@ import UIKit /// The action performed when tapped. func tapAction() { - if !isEnabled || isReadOnly { + if !isEnabled { return } @@ -163,8 +163,7 @@ import UIKit guard let model = model as? RadioButtonModel else { return } isSelected = model.state - isEnabled = model.enabled - isReadOnly = model.readOnly + isEnabled = model.enabled && !model.readOnly RadioButtonSelectionHelper.setupForRadioButtonGroup(model, self, delegateObject: delegateObject) } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift index f927f7e9..eb569810 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift @@ -38,13 +38,7 @@ open class RadioSwatch: Control, MFButtonProtocol { updateAccessibility() } } - - public override var isReadOnly: Bool { - didSet { - updateAccessibility() - } - } - + //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- @@ -70,8 +64,7 @@ open class RadioSwatch: Control, MFButtonProtocol { self.additionalData = additionalData bottomText.text = model.text isSelected = model.selected - isEnabled = model.enabled - isReadOnly = model.readOnly + isEnabled = model.enabled && !model.readOnly } public override func reset() { @@ -79,7 +72,6 @@ open class RadioSwatch: Control, MFButtonProtocol { bottomText.text = nil isSelected = false isEnabled = true - isReadOnly = false } //------------------------------------------------------ @@ -114,7 +106,7 @@ open class RadioSwatch: Control, MFButtonProtocol { //Handle Mask maskLayer?.removeFromSuperlayer() - if !isEnabled || isReadOnly { + if !isEnabled { let mask = getMaskLayer() layer.mask = mask maskLayer = mask @@ -128,7 +120,7 @@ open class RadioSwatch: Control, MFButtonProtocol { } @objc open func selectSwatch() { - guard isEnabled, !isReadOnly, !isSelected else { return } + guard isEnabled, !isSelected else { return } isSelected = true radioSwatchModel?.selected = isSelected if let radioSwatchModel = radioSwatchModel, let actionModel = radioSwatchModel.action { @@ -201,7 +193,7 @@ open class RadioSwatch: Control, MFButtonProtocol { if isSelected { accessibilityTraits.insert(.selected) } - if !isEnabled || isReadOnly { + if !isEnabled { accessibilityTraits.insert(.notEnabled) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Toggle.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Toggle.swift index a76424f0..04c34da2 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Toggle.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Toggle.swift @@ -66,15 +66,7 @@ public typealias ActionBlockConfirmation = () -> (Bool) accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: isEnabled ? "AccToggleHint" : "AccDisabled") } } - - public override var isReadOnly: Bool { - didSet{ - changeStateNoAnimation(!isReadOnly ? isOn : false) - setToggleAppearanceFromState() - accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: !isReadOnly ? "AccToggleHint" : "AccDisabled") - } - } - + /// Simple means to prevent user interaction with the toggle. public var isLocked: Bool = false { didSet { isUserInteractionEnabled = !isLocked } @@ -358,8 +350,8 @@ public typealias ActionBlockConfirmation = () -> (Bool) public func setToggleAppearanceFromState() { - backgroundColor = isEnabled || !isReadOnly ? isOn ? containerTintColor.on : containerTintColor.off : disabledTintColor.container - knobView.backgroundColor = isEnabled || !isReadOnly ? isOn ? knobTintColor.on : knobTintColor.off : disabledTintColor.knob + backgroundColor = isEnabled ? isOn ? containerTintColor.on : containerTintColor.off : disabledTintColor.container + knobView.backgroundColor = isEnabled ? isOn ? knobTintColor.on : knobTintColor.off : disabledTintColor.knob } public func knobReformAnimation() { @@ -392,8 +384,7 @@ public typealias ActionBlockConfirmation = () -> (Bool) isOn = model.selected changeStateNoAnimation(isOn) isAnimated = model.animated - isEnabled = model.enabled - isReadOnly = model.readOnly + isEnabled = model.enabled && !model.readOnly if let accessibileString = model.accessibilityText { accessibilityLabel = accessibileString diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift index 1f2e7346..381b8112 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift @@ -72,26 +72,14 @@ open class BarsIndicatorView: CarouselIndicator { didSet { for (i, indicatorBar) in barReferences.enumerated() { if i == currentIndex { - indicatorBar.backgroundColor = isEnabled && !isReadOnly ? currentIndicatorColor : disabledIndicatorColor + indicatorBar.backgroundColor = isEnabled ? currentIndicatorColor : disabledIndicatorColor } else { - indicatorBar.backgroundColor = isEnabled && !isReadOnly ? indicatorColor : disabledIndicatorColor + indicatorBar.backgroundColor = isEnabled ? indicatorColor : disabledIndicatorColor } } } } - - open override var isReadOnly: Bool { - didSet { - for (i, indicatorBar) in barReferences.enumerated() { - if i == currentIndex { - indicatorBar.backgroundColor = !isReadOnly ? currentIndicatorColor : disabledIndicatorColor - } else { - indicatorBar.backgroundColor = !isReadOnly ? indicatorColor : disabledIndicatorColor - } - } - } - } - + /// Colors the currently selected index, unique from other indicators public var currentIndicatorColor: UIColor { get { barsCarouselIndicatorModel?.currentIndicatorColor.uiColor ?? indicatorColor } diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift index e888fff8..f07fe123 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift @@ -42,13 +42,9 @@ open class NumericIndicatorView: CarouselIndicator { //-------------------------------------------------- open override var isEnabled: Bool { - didSet { setViewColor(isEnabled && !isReadOnly ? indicatorColor : disabledIndicatorColor) } + didSet { setViewColor(isEnabled ? indicatorColor : disabledIndicatorColor) } } - - open override var isReadOnly: Bool { - didSet { setViewColor(!isReadOnly ? indicatorColor : disabledIndicatorColor) } - } - + /// Sets the color for pageCount text, left arrow and right arrow. public override var indicatorColor: UIColor { get { super.indicatorColor } diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index 3aebaf7e..865e3a8e 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -13,14 +13,6 @@ import UIKit //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- - public var isReadOnly: Bool = false{ - didSet{ - //don't allow touches - isUserInteractionEnabled = !isReadOnly - setNeedsDisplay() - } - } - open var model: MoleculeModelProtocol? private var initialSetupPerformed = false diff --git a/MVMCoreUI/Containers/Views/EntryFieldContainer.swift b/MVMCoreUI/Containers/Views/EntryFieldContainer.swift index f567d01f..9ccd1d25 100644 --- a/MVMCoreUI/Containers/Views/EntryFieldContainer.swift +++ b/MVMCoreUI/Containers/Views/EntryFieldContainer.swift @@ -55,7 +55,6 @@ import UIKit private var _showError: Bool = false private var _isLocked: Bool = false private var _isSelected: Bool = false - private var _isReadOnly: Bool = false public var isEnabled: Bool { get { return _isEnabled } @@ -70,20 +69,6 @@ import UIKit } } - public var isReadOnly: Bool { - get { return _isReadOnly } - set (readOnly) { - - _isEnabled = true - _isLocked = false - _isSelected = false - _showError = false - _isReadOnly = readOnly - - fieldState = readOnly ? .disabled : .original - } - } - public var showError: Bool { get { return _showError } set (error) {