Merge branch 'bugfix/CXTDT_74295' into 'release/7_6_0'
fix for CXTDT_74295 See merge request BPHV_MIPS/mvm_core_ui!391
This commit is contained in:
commit
9186ca0839
@ -25,13 +25,13 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Holds the on and off colors for the container.
|
/// Holds the on and off colors for the container.
|
||||||
public var containerTintColor: (on: UIColor?, off: UIColor?)? = (on: .mvmGreen, off: .mvmBlack)
|
public var containerTintColor: (on: UIColor, off: UIColor) = (on: .mvmGreen, off: .mvmBlack)
|
||||||
|
|
||||||
/// Holds the on and off colors for the knob.
|
/// Holds the on and off colors for the knob.
|
||||||
public var knobTintColor: (on: UIColor?, off: UIColor?)? = (on: .mvmWhite, off: .mvmWhite)
|
public var knobTintColor: (on: UIColor, off: UIColor) = (on: .mvmWhite, off: .mvmWhite)
|
||||||
|
|
||||||
/// Holds the on and off colors for the disabled state..
|
/// Holds the on and off colors for the disabled state..
|
||||||
public var disabledTintColor: (container: UIColor?, knob: UIColor?)? = (container: .mvmCoolGray3, knob: .mvmWhite)
|
public var disabledTintColor: (container: UIColor, knob: UIColor) = (container: .mvmCoolGray3, knob: .mvmWhite)
|
||||||
|
|
||||||
/// Set this flag to false if you do not want to animate state changes.
|
/// Set this flag to false if you do not want to animate state changes.
|
||||||
public var isAnimated = true
|
public var isAnimated = true
|
||||||
@ -62,8 +62,8 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
didSet {
|
didSet {
|
||||||
isUserInteractionEnabled = isEnabled
|
isUserInteractionEnabled = isEnabled
|
||||||
changeStateNoAnimation(isEnabled ? isOn : false)
|
changeStateNoAnimation(isEnabled ? isOn : false)
|
||||||
backgroundColor = isEnabled ? containerTintColor?.off : disabledTintColor?.container
|
backgroundColor = isEnabled ? (isOn ? containerTintColor.on : containerTintColor.off) : disabledTintColor.container
|
||||||
knobView.backgroundColor = isEnabled ? knobTintColor?.off : disabledTintColor?.knob
|
knobView.backgroundColor = isEnabled ? (isOn ? knobTintColor.on : knobTintColor.off) : disabledTintColor.knob
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,12 +80,12 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
if isAnimated {
|
if isAnimated {
|
||||||
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {
|
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {
|
||||||
if self.isOn {
|
if self.isOn {
|
||||||
self.knobView.backgroundColor = self.knobTintColor?.on
|
self.knobView.backgroundColor = self.knobTintColor.on
|
||||||
self.backgroundColor = self.containerTintColor?.on
|
self.backgroundColor = self.containerTintColor.on
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
self.knobView.backgroundColor = self.knobTintColor?.off
|
self.knobView.backgroundColor = self.knobTintColor.off
|
||||||
self.backgroundColor = self.containerTintColor?.off
|
self.backgroundColor = self.containerTintColor.off
|
||||||
}
|
}
|
||||||
}, completion: nil)
|
}, completion: nil)
|
||||||
|
|
||||||
@ -96,12 +96,12 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
}, completion: nil)
|
}, completion: nil)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
backgroundColor = isOn ? containerTintColor?.on : containerTintColor?.off
|
backgroundColor = isOn ? containerTintColor.on : containerTintColor.off
|
||||||
knobView.backgroundColor = isOn ? knobTintColor?.on : knobTintColor?.off
|
knobView.backgroundColor = isOn ? knobTintColor.on : knobTintColor.off
|
||||||
self.constrainKnob()
|
self.constrainKnob()
|
||||||
}
|
}
|
||||||
|
|
||||||
(model as? ToggleModel)?.state = isOn
|
toggleModel?.state = isOn
|
||||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||||
accessibilityValue = isOn ? MVMCoreUIUtility.hardcodedString(withKey: "AccOn") : MVMCoreUIUtility.hardcodedString(withKey: "AccOff")
|
accessibilityValue = isOn ? MVMCoreUIUtility.hardcodedString(withKey: "AccOn") : MVMCoreUIUtility.hardcodedString(withKey: "AccOff")
|
||||||
setNeedsLayout()
|
setNeedsLayout()
|
||||||
@ -109,6 +109,10 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var toggleModel: ToggleModel? {
|
||||||
|
return model as? ToggleModel
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Delegate
|
// MARK: - Delegate
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -189,7 +193,7 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
|
|
||||||
public override func setupView() {
|
public override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
guard subviews.isEmpty else { return }
|
|
||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
accessibilityTraits = .button
|
accessibilityTraits = .button
|
||||||
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "AccToggleHint")
|
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "AccToggleHint")
|
||||||
@ -202,7 +206,7 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
widthConstraint?.isActive = true
|
widthConstraint?.isActive = true
|
||||||
|
|
||||||
layer.cornerRadius = Self.containerSize.height / 2.0
|
layer.cornerRadius = Self.containerSize.height / 2.0
|
||||||
backgroundColor = containerTintColor?.off
|
backgroundColor = containerTintColor.off
|
||||||
|
|
||||||
addSubview(knobView)
|
addSubview(knobView)
|
||||||
|
|
||||||
@ -222,9 +226,9 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
public override func reset() {
|
public override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
|
|
||||||
backgroundColor = containerTintColor?.off
|
backgroundColor = containerTintColor.off
|
||||||
knobView.backgroundColor = knobTintColor?.off
|
knobView.backgroundColor = knobTintColor.off
|
||||||
isAnimated = false
|
isAnimated = true
|
||||||
isOn = false
|
isOn = false
|
||||||
constrainKnob()
|
constrainKnob()
|
||||||
didToggleAction = nil
|
didToggleAction = nil
|
||||||
@ -344,26 +348,14 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
|
|
||||||
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
|
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
|
||||||
|
|
||||||
if let color = model.onTintColor?.uiColor {
|
containerTintColor.on = model.onTintColor.uiColor
|
||||||
containerTintColor?.on = color
|
containerTintColor.off = model.offTintColor.uiColor
|
||||||
}
|
knobTintColor.on = model.onKnobTintColor.uiColor
|
||||||
|
knobTintColor.off = model.offKnobTintColor.uiColor
|
||||||
if let color = model.offTintColor?.uiColor {
|
|
||||||
containerTintColor?.off = color
|
|
||||||
}
|
|
||||||
|
|
||||||
if let color = model.onKnobTintColor?.uiColor {
|
|
||||||
knobTintColor?.on = color
|
|
||||||
}
|
|
||||||
|
|
||||||
if let color = model.offKnobTintColor?.uiColor {
|
|
||||||
knobTintColor?.off = color
|
|
||||||
}
|
|
||||||
|
|
||||||
changeStateNoAnimation(model.state)
|
changeStateNoAnimation(model.state)
|
||||||
isAnimated = model.animated
|
isAnimated = model.animated
|
||||||
isEnabled = model.enabled
|
isEnabled = model.enabled
|
||||||
|
|
||||||
if let actionMap = model.action?.toJSON() {
|
if let actionMap = model.action?.toJSON() {
|
||||||
didToggleAction = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) }
|
didToggleAction = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,12 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol, EnableableModelProtocol {
|
|
||||||
|
|
||||||
|
public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol, EnableableModelProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var identifier: String = "toggle"
|
public static var identifier: String = "toggle"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var state: Bool = false
|
public var state: Bool = false
|
||||||
@ -18,10 +22,10 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol, EnableableMo
|
|||||||
public var action: ActionModelProtocol?
|
public var action: ActionModelProtocol?
|
||||||
public var alternateAction: ActionModelProtocol?
|
public var alternateAction: ActionModelProtocol?
|
||||||
public var accessibilityText: String?
|
public var accessibilityText: String?
|
||||||
public var onTintColor: Color?
|
public var onTintColor: Color = Color(uiColor: .mvmGreen)
|
||||||
public var offTintColor: Color?
|
public var offTintColor: Color = Color(uiColor: .mvmBlack)
|
||||||
public var onKnobTintColor: Color?
|
public var onKnobTintColor: Color = Color(uiColor: .mvmWhite)
|
||||||
public var offKnobTintColor: Color?
|
public var offKnobTintColor: Color = Color(uiColor: .mvmWhite)
|
||||||
|
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String = FormValidator.defaultGroupName
|
public var groupName: String = FormValidator.defaultGroupName
|
||||||
@ -75,19 +79,35 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol, EnableableMo
|
|||||||
if let state = try typeContainer.decodeIfPresent(Bool.self, forKey: .state) {
|
if let state = try typeContainer.decodeIfPresent(Bool.self, forKey: .state) {
|
||||||
self.state = state
|
self.state = state
|
||||||
}
|
}
|
||||||
|
|
||||||
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
if let animated = try typeContainer.decodeIfPresent(Bool.self, forKey: .animated) {
|
if let animated = try typeContainer.decodeIfPresent(Bool.self, forKey: .animated) {
|
||||||
self.animated = animated
|
self.animated = animated
|
||||||
}
|
}
|
||||||
|
|
||||||
action = try typeContainer.decodeModelIfPresent(codingKey: .action)
|
action = try typeContainer.decodeModelIfPresent(codingKey: .action)
|
||||||
alternateAction = try typeContainer.decodeModelIfPresent(codingKey: .alternateAction)
|
alternateAction = try typeContainer.decodeModelIfPresent(codingKey: .alternateAction)
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
onTintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .onTintColor)
|
|
||||||
offTintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .offTintColor)
|
if let onTintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .onTintColor) {
|
||||||
onKnobTintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .onKnobTintColor)
|
self.onTintColor = onTintColor
|
||||||
offKnobTintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .offKnobTintColor)
|
}
|
||||||
|
|
||||||
|
if let offTintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .offTintColor) {
|
||||||
|
self.offTintColor = offTintColor
|
||||||
|
}
|
||||||
|
|
||||||
|
if let onKnobTintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .onKnobTintColor) {
|
||||||
|
self.onKnobTintColor = onKnobTintColor
|
||||||
|
}
|
||||||
|
|
||||||
|
if let offKnobTintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .offKnobTintColor) {
|
||||||
|
self.offKnobTintColor = offKnobTintColor
|
||||||
|
}
|
||||||
|
|
||||||
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
|
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
|
||||||
|
|
||||||
baseValue = state
|
baseValue = state
|
||||||
@ -106,10 +126,10 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol, EnableableMo
|
|||||||
try container.encode(state, forKey: .state)
|
try container.encode(state, forKey: .state)
|
||||||
try container.encode(animated, forKey: .animated)
|
try container.encode(animated, forKey: .animated)
|
||||||
try container.encode(enabled, forKey: .enabled)
|
try container.encode(enabled, forKey: .enabled)
|
||||||
try container.encodeIfPresent(onTintColor, forKey: .onTintColor)
|
try container.encode(onTintColor, forKey: .onTintColor)
|
||||||
try container.encodeIfPresent(onKnobTintColor, forKey: .onKnobTintColor)
|
try container.encode(onKnobTintColor, forKey: .onKnobTintColor)
|
||||||
try container.encodeIfPresent(onKnobTintColor, forKey: .onKnobTintColor)
|
try container.encode(onKnobTintColor, forKey: .onKnobTintColor)
|
||||||
try container.encodeIfPresent(offKnobTintColor, forKey: .offKnobTintColor)
|
try container.encode(offKnobTintColor, forKey: .offKnobTintColor)
|
||||||
try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText)
|
try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText)
|
||||||
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
||||||
try container.encodeIfPresent(groupName, forKey: .groupName)
|
try container.encodeIfPresent(groupName, forKey: .groupName)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user