diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index fc435de1..6b5b0a14 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -348,6 +348,7 @@ D236E5B4241FEB1000C38625 /* ListTwoColumnPriceDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = D236E5B2241FEB1000C38625 /* ListTwoColumnPriceDescription.swift */; }; D236E5B5241FEB1000C38625 /* ListTwoColumnPriceDescriptionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D236E5B3241FEB1000C38625 /* ListTwoColumnPriceDescriptionModel.swift */; }; D236E5B7242007C500C38625 /* MVMControllerModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D236E5B6242007C500C38625 /* MVMControllerModelProtocol.swift */; }; + D23A8FD9260CE004007E14CE /* MFStyler+PaddingExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D23A8FD5260CDF01007E14CE /* MFStyler+PaddingExtension.swift */; }; D23A8FEB26122F69007E14CE /* VisibleBehaviorForVideoModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D23A8FEA26122F69007E14CE /* VisibleBehaviorForVideoModel.swift */; }; D23A8FEE26122F7D007E14CE /* VisibleBehaviorForVideo.swift in Sources */ = {isa = PBXBuildFile; fileRef = D23A8FED26122F7D007E14CE /* VisibleBehaviorForVideo.swift */; }; D23A8FF82612308D007E14CE /* PageBehaviorProtocolRequirer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D23A8FF72612308D007E14CE /* PageBehaviorProtocolRequirer.swift */; }; @@ -912,6 +913,7 @@ D236E5B2241FEB1000C38625 /* ListTwoColumnPriceDescription.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListTwoColumnPriceDescription.swift; sourceTree = ""; }; D236E5B3241FEB1000C38625 /* ListTwoColumnPriceDescriptionModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListTwoColumnPriceDescriptionModel.swift; sourceTree = ""; }; D236E5B6242007C500C38625 /* MVMControllerModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMControllerModelProtocol.swift; sourceTree = ""; }; + D23A8FD5260CDF01007E14CE /* MFStyler+PaddingExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFStyler+PaddingExtension.swift"; sourceTree = ""; }; D23A8FEA26122F69007E14CE /* VisibleBehaviorForVideoModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisibleBehaviorForVideoModel.swift; sourceTree = ""; }; D23A8FED26122F7D007E14CE /* VisibleBehaviorForVideo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisibleBehaviorForVideo.swift; sourceTree = ""; }; D23A8FF72612308D007E14CE /* PageBehaviorProtocolRequirer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageBehaviorProtocolRequirer.swift; sourceTree = ""; }; @@ -2041,6 +2043,7 @@ D29DF13921E68637003B2FB9 /* MFStyler.m */, 0A6682A92435125F00AD3CA1 /* Styler.swift */, 0A6682AB243531C300AD3CA1 /* Padding.swift */, + D23A8FD5260CDF01007E14CE /* MFStyler+PaddingExtension.swift */, ); path = Styles; sourceTree = ""; @@ -2888,6 +2891,7 @@ D253BB9C245874F8002DE544 /* BGImageMolecule.swift in Sources */, D2C78CD224228BBD00B69FDE /* ActionOpenPanelModel.swift in Sources */, AA617AB02453010A00910B8F /* ListDeviceComplexLinkSmall.swift in Sources */, + D23A8FD9260CE004007E14CE /* MFStyler+PaddingExtension.swift in Sources */, C695A68123C9830D00BFB94E /* NumberedListModel.swift in Sources */, 01EB3684236097C0006832FA /* MoleculeModelProtocol.swift in Sources */, D27CD4102339057800C1DC07 /* EyebrowHeadlineBodyLink.swift in Sources */, diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift index 5ae68241..702c3238 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift @@ -59,12 +59,6 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { // MARK: - Lifecycle //------------------------------------------------------ - override open func layoutSubviews() { - - addCaretImageView() - super.layoutSubviews() - } - override public var isEnabled: Bool { didSet { changeCaretColor() } } @@ -135,7 +129,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { //------------------------------------------------------ public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - + addCaretImageView() guard let model = model as? CaretLinkModel else { return } if let color = model.backgroundColor { @@ -150,6 +144,11 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { setTitle(model.title, for: .normal) } + open override func reset() { + super.reset() + rightView?.removeFromSuperview() + } + public func needsToBeConstrained() -> Bool { true } open func horizontalAlignment() -> UIStackView.Alignment { .leading } diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift index 8eefe1d7..1bdf0234 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift @@ -168,10 +168,14 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { } open override var intrinsicContentSize: CGSize { - - let size = super.intrinsicContentSize - let width = size.width + (2 * getInnerPadding()) - return CGSize(width: max(width, getMinimumWidth()), height: getHeight()) + if buttonSize == .tiny { + let size = super.intrinsicContentSize + let width = size.width + (2 * getInnerPadding()) + return CGSize(width: max(width, getMinimumWidth()), height: getHeight()) + } else { + let width = Padding.Component.gutterForApplicationWidth + (2.0 * Padding.Component.columnFor(size: MVMCoreUISplitViewController.getApplicationViewWidth())) + return CGSize(width: min(292, width), height: getHeight()) + } } //-------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift index 4a596a35..e8f940a2 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift @@ -14,7 +14,7 @@ open class RadioBoxes: View { public var collectionViewHeight: NSLayoutConstraint! private let boxWidth: CGFloat = 151.0 private let boxHeight: CGFloat = 64.0 - private let itemSpacing: CGFloat = 8.0 + private var itemSpacing: CGFloat = 12.0 private var numberOfColumns: CGFloat = 2.0 private var radioBoxesModel: RadioBoxesModel? { return model as? RadioBoxesModel @@ -71,6 +71,7 @@ open class RadioBoxes: View { @objc override open func updateView(_ size: CGFloat) { super.updateView(size) self.size = size + itemSpacing = Padding.Component.gutterFor(size: size) collectionView.updateView(size) } diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift index f2b87c0a..975c7ebb 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift @@ -14,6 +14,37 @@ open class BarsIndicatorView: CarouselIndicator { // MARK: - Stored Properties //-------------------------------------------------- + /// Represents the data of each individual bar. + private class IndicatorBar: View { + // Dimensions are based on InVision Design Guidelines. + static let width: CGFloat = 24 + static let selectedHeight: CGFloat = 4 + static let unselectedHeight: CGFloat = 1 + + var constraint: NSLayoutConstraint? + + init() { + super.init(frame: .zero) + } + + public required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + fatalError("init(model:_:_:) has not been implemented") + } + + override func setupView() { + super.setupView() + isAccessibilityElement = true + accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "AccTabHint") + widthAnchor.constraint(equalToConstant: BarsIndicatorView.IndicatorBar.width).isActive = true + accessibilityTraits = .button + } + } + + /// Structured container to hold and layout the indicator bars. public let stackView: UIStackView = { let stackView = UIStackView() stackView.translatesAutoresizingMaskIntoConstraints = false @@ -25,11 +56,8 @@ open class BarsIndicatorView: CarouselIndicator { return stackView }() - public var barReferences: [(view: View, constraint: NSLayoutConstraint)] = [] - - // Dimensions are based on InVision Design Guidelines. - public static let indicatorBarWidth: CGFloat = 24 - public static let indicatorBarHeight: (selected: CGFloat, unselected: CGFloat) = (selected: 4, unselected: 1) + /// Reference to each bar displayed. + private var barReferences: [IndicatorBar] = [] //-------------------------------------------------- // MARK: - Computed Properties @@ -37,16 +65,16 @@ open class BarsIndicatorView: CarouselIndicator { /// Convenience to access the model. public var barsCarouselIndicatorModel: BarsCarouselIndicatorModel? { - return model as? BarsCarouselIndicatorModel + model as? BarsCarouselIndicatorModel } open override var isEnabled: Bool { didSet { - for (i, bar) in barReferences.enumerated() { + for (i, indicatorBar) in barReferences.enumerated() { if i == currentIndex { - bar.view.backgroundColor = isEnabled ? currentIndicatorColor : disabledIndicatorColor + indicatorBar.backgroundColor = isEnabled ? currentIndicatorColor : disabledIndicatorColor } else { - bar.view.backgroundColor = isEnabled ? indicatorColor : disabledIndicatorColor + indicatorBar.backgroundColor = isEnabled ? indicatorColor : disabledIndicatorColor } } } @@ -54,21 +82,22 @@ open class BarsIndicatorView: CarouselIndicator { /// Colors the currently selected index, unique from other indicators public var currentIndicatorColor: UIColor { - get { return barsCarouselIndicatorModel?.currentIndicatorColor.uiColor ?? indicatorColor } - set (newColor) { - barsCarouselIndicatorModel?.currentIndicatorColor = Color(uiColor: newColor) + get { barsCarouselIndicatorModel?.currentIndicatorColor.uiColor ?? indicatorColor } + set { + barsCarouselIndicatorModel?.currentIndicatorColor = Color(uiColor: newValue) if isEnabled && !barReferences.isEmpty { - barReferences[currentIndex].view.backgroundColor = newColor + barReferences[currentIndex].backgroundColor = newValue } } } + /// The color of the indicator bars. public override var indicatorColor: UIColor { - get { return super.indicatorColor } - set (newColor) { - super.indicatorColor = newColor - refreshBarColors(with: newColor) + get { super.indicatorColor } + set { + super.indicatorColor = newValue + refreshBarColors(with: newValue) } } @@ -84,7 +113,7 @@ open class BarsIndicatorView: CarouselIndicator { isAccessibilityElement = false NSLayoutConstraint.activate([ - stackView.heightAnchor.constraint(equalToConstant: 4), + stackView.heightAnchor.constraint(equalToConstant: Padding.One), heightAnchor.constraint(equalTo: stackView.heightAnchor), stackView.leadingAnchor.constraint(equalTo: leadingAnchor), stackView.topAnchor.constraint(equalTo: topAnchor), @@ -97,44 +126,95 @@ open class BarsIndicatorView: CarouselIndicator { // MARK: - Methods //-------------------------------------------------- + /// Updates the color of all indicator bars. private func refreshBarColors(with color: UIColor) { - if isEnabled { - for (i, barTuple) in barReferences.enumerated() { - barTuple.view.backgroundColor = i == currentIndex ? currentIndicatorColor : color - } + guard isEnabled else { return } + + for (i, indicatorBar) in barReferences.enumerated() { + indicatorBar.backgroundColor = i == currentIndex ? currentIndicatorColor : color } } + /// Creates all the indicato bars for display. func generateBars() { - var bars = [(View, NSLayoutConstraint)]() + var bars = [IndicatorBar]() for i in 0.. 0 { + // If positive, add n bars. + var copyBars = barReferences + + for _ in 0.. IndicatorBar { + + let bar = IndicatorBar() + setAccessibilityLabel(view: bar, index: index) + bar.backgroundColor = isEnabled ? (index == currentIndex ? currentIndicatorColor : indicatorColor) : disabledIndicatorColor + let barHeight = index == currentIndex ? BarsIndicatorView.IndicatorBar.selectedHeight : BarsIndicatorView.IndicatorBar.unselectedHeight + let heightConstraint = bar.heightAnchor.constraint(equalToConstant: barHeight) + heightConstraint.isActive = true + bar.constraint = heightConstraint + + return bar + } + + /// Refreshes the accessibility labels to read "x of n". + private func refreshAccessibilityLabels() { + for i in 0..= touchPoint_X && $0.0.frame.minX <= touchPoint_X } ?? 0 + currentIndex = barReferences.firstIndex { $0.frame.maxX >= touchPoint_X && $0.frame.minX <= touchPoint_X } ?? 0 performAction() } @@ -152,27 +232,40 @@ open class BarsIndicatorView: CarouselIndicator { public override func reset() { super.reset() - barReferences.forEach { $0.view.removeFromSuperview() } + barReferences.forEach { $0.removeFromSuperview() } barReferences = [] } public override func updateUI(previousIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) { - guard newIndex < totalCount else { return } - + // Ensure that at least one bar exists. guard !barReferences.isEmpty else { generateBars() return } - let expression = { - self.barReferences[previousIndex].view.backgroundColor = self.isEnabled ? self.indicatorColor : self.disabledIndicatorColor - self.barReferences[newIndex].view.backgroundColor = self.isEnabled ? self.currentIndicatorColor : self.disabledIndicatorColor - self.barReferences[previousIndex].constraint.constant = BarsIndicatorView.indicatorBarHeight.unselected - self.barReferences[newIndex].constraint.constant = BarsIndicatorView.indicatorBarHeight.selected - self.layoutIfNeeded() + guard newIndex < totalCount else { return } + + // Ensure the number of pages matches the number of bar references. + if (totalCount - barReferences.count) != 0 { + barReferences.forEach { + $0.backgroundColor = isEnabled ? indicatorColor : disabledIndicatorColor + $0.constraint?.constant = IndicatorBar.unselectedHeight + } + + balanceBarCount(numberOfPages - barReferences.count) + refreshAccessibilityLabels() } - isAnimated ? UIView.animate(withDuration: 0.3) { expression() } : expression() + let expression = { [self] in + barReferences[previousIndex].backgroundColor = isEnabled ? indicatorColor : disabledIndicatorColor + barReferences[previousIndex].constraint?.constant = IndicatorBar.unselectedHeight + barReferences[newIndex].backgroundColor = isEnabled ? currentIndicatorColor : disabledIndicatorColor + barReferences[newIndex].constraint?.constant = IndicatorBar.selectedHeight + layoutIfNeeded() + } + + // Perform the animation. + isAnimated ? UIView.animate(withDuration: 0.25) { expression() } : expression() } } diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift index 040657c5..6a82ef80 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift @@ -6,8 +6,6 @@ // Copyright © 2020 Verizon Wireless. All rights reserved. // -import Foundation - open class CarouselIndicator: Control, CarouselPageControlProtocol { //-------------------------------------------------- @@ -25,7 +23,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { /// Convenience to access the model. public var carouselIndicatorModel: CarouselIndicatorModel? { - return model as? CarouselIndicatorModel + model as? CarouselIndicatorModel } /// Set this closure to perform an action when a different indicator was selected. @@ -43,7 +41,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { private(set) var previousIndex = 0 public var currentIndex: Int { - get { return carouselIndicatorModel?.currentIndex ?? 0 } + get { carouselIndicatorModel?.currentIndex ?? 0 } set (newIndex) { previousIndex = currentIndex carouselIndicatorModel?.currentIndex = newIndex @@ -58,22 +56,22 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { /// Holds the total number of pages displayed by the carousel. /// Updating this property will potentially update the UI. public var numberOfPages: Int { - get { return carouselIndicatorModel?.numberOfPages ?? 0 } - set (newTotal) { - guard numberOfPages != newTotal else { return } + get { carouselIndicatorModel?.numberOfPages ?? 0 } + set { + guard numberOfPages != newValue else { return } - carouselIndicatorModel?.numberOfPages = newTotal + carouselIndicatorModel?.numberOfPages = newValue reset() - isHidden = (carouselIndicatorModel?.hidesForSinglePage ?? false) && newTotal <= 1 + isHidden = (carouselIndicatorModel?.hidesForSinglePage ?? false) && newValue <= 1 updateUI(previousIndex: previousIndex, newIndex: currentIndex, - totalCount: newTotal, + totalCount: newValue, isAnimated: carouselIndicatorModel?.animated ?? true) } } public var disabledIndicatorColor: UIColor { - get { return carouselIndicatorModel?.disabledIndicatorColor.uiColor ?? .mvmCoolGray3 } + get { carouselIndicatorModel?.disabledIndicatorColor.uiColor ?? .mvmCoolGray3 } set { carouselIndicatorModel?.disabledIndicatorColor = Color(uiColor: newValue) } } @@ -92,7 +90,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { } var accessibilityValueFormat: String? { - return MVMCoreUIUtility.hardcodedString(withKey: (carouselIndicatorModel?.accessibilityHasSlidesInsteadOfPage ?? false) ? "MVMCoreUIPageControlslides_currentpage_index" : "MVMCoreUIPageControl_currentpage_index") + MVMCoreUIUtility.hardcodedString(withKey: (carouselIndicatorModel?.accessibilityHasSlidesInsteadOfPage ?? false) ? "MVMCoreUIPageControlslides_currentpage_index" : "MVMCoreUIPageControl_currentpage_index") } //-------------------------------------------------- @@ -175,12 +173,14 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { assessTouchOf(touchPoint_X) } + /// Determines where a touch in the indicator translate to an index selection. func assessTouchOf(_ touchPoint_X: CGFloat) { } //-------------------------------------------------- // MARK: - Methods //-------------------------------------------------- + /// Called to update the Indicator UI with the latest values. open func updateUI(previousIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) { } public func performAction() { @@ -200,6 +200,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { guard let model = model as? CarouselIndicatorModel else { return } + previousIndex = 0 indicatorColor = model.inverted ? model.indicatorColor_inverted.uiColor : model.indicatorColor.uiColor disabledIndicatorColor = model.disabledIndicatorColor.uiColor currentIndex = model.currentIndex @@ -214,20 +215,18 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { //-------------------------------------------------- open override func accessibilityIncrement() { - adjustAccessibility(toPage: currentIndex + 1) } open override func accessibilityDecrement() { - adjustAccessibility(toPage: currentIndex - 1) } func formatAccessibilityValue(index: Int, total: Int) { guard let accessibleFormat = accessibilityValueFormat, - let accessibleIndex = MVMCoreUIUtility.getOrdinalString(forIndex: NSNumber(value: index)) - else { return } + let accessibleIndex = MVMCoreUIUtility.getOrdinalString(forIndex: NSNumber(value: index)) + else { return } accessibilityValue = String(format: accessibleFormat, accessibleIndex, total) } diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift index afbe30d4..eb3a8ebd 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/NumericIndicatorView.swift @@ -47,7 +47,7 @@ open class NumericIndicatorView: CarouselIndicator { /// Sets the color for pageCount text, left arrow and right arrow. public override var indicatorColor: UIColor { - get { return super.indicatorColor } + get { super.indicatorColor } set (newColor) { super.indicatorColor = newColor diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift index 9d9291e8..3129776b 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift @@ -6,7 +6,8 @@ // Copyright © 2020 Verizon Wireless. All rights reserved. // -public class ListLeftVariableIconWithRightCaretAllTextLinksModel: ListItemModel, MoleculeModelProtocol { +public class ListLeftVariableIconWithRightCaretAllTextLinksModel: ListItemModel, ParentMoleculeModelProtocol { + //----------------------------------------------------- // MARK: - Properties //----------------------------------------------------- @@ -16,6 +17,10 @@ public class ListLeftVariableIconWithRightCaretAllTextLinksModel: ListItemModel, public var eyebrowHeadlineBodyLink: EyebrowHeadlineBodyLinkModel public var rightLabel: LabelModel + public var children: [MoleculeModelProtocol] { + return [image, eyebrowHeadlineBodyLink, rightLabel] + } + //----------------------------------------------------- // MARK: - Methods //----------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnCompareChanges.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnCompareChanges.swift index 9f7895af..42284af9 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnCompareChanges.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnCompareChanges.swift @@ -20,7 +20,6 @@ //------------------------------------------------------ let containingStack: Stack - let stackSpacing: CGFloat = 5.0 //------------------------------------------------------ // MARK: - Initializers @@ -31,7 +30,7 @@ (view: rightHeadlineBodyLink, model: StackItemModel(percent: 50, verticalAlignment: .leading))], axis: .horizontal) - containingStack = Stack.createStack(with: [stackHeadline1], spacing: 0) + containingStack = Stack.createStack(with: [stackHeadline1], spacing: Padding.Component.gutterForApplicationWidth) super.init(style: style, reuseIdentifier: reuseIdentifier) } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnDropdownSelectors.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnDropdownSelectors.swift index eb8fb0ea..93350a63 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnDropdownSelectors.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnDropdownSelectors.swift @@ -23,7 +23,7 @@ public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { stack = Stack.createStack(with: [(view: leftDropDown, model: StackItemModel(percent: 50, horizontalAlignment: .fill)), (view: rightDropDown, model: StackItemModel(percent: 50, horizontalAlignment: .fill))], - axis: .horizontal, spacing: 9) + axis: .horizontal, spacing: Padding.Component.gutterForApplicationWidth) super.init(style: style, reuseIdentifier: reuseIdentifier) } diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabel.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabel.swift index 918871e7..eb7266a9 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabel.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabel.swift @@ -32,7 +32,7 @@ import UIKit if let rightView = createRightView() { addSubview(rightView) - rightView.leftAnchor.constraint(equalTo: radioButton.rightAnchor, constant: PaddingHorizontalBetweenRelatedItems).isActive = true + rightView.leftAnchor.constraint(equalTo: radioButton.rightAnchor, constant: Padding.Component.gutterForApplicationWidth).isActive = true rightView.rightAnchor.constraint(equalTo: layoutMarginsGuide.rightAnchor, constant: 0).isActive = true var constraint = rightView.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor, constant: PaddingOne) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift index 1ddd9412..f3ce24e5 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift @@ -198,11 +198,13 @@ extension Tabs: UICollectionViewDelegateFlowLayout { } public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { - if !paddingBeforeFirstTab && section == 0 { - return .zero - } else { + guard section == 0 else { return UIEdgeInsets(top: 0, left: sectionPadding, bottom: 0, right: 0) } + guard paddingBeforeFirstTab else { + return .zero + } + return UIEdgeInsets(top: 0, left: Padding.Component.horizontalPaddingForApplicationWidth, bottom: 0, right: 0) } public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift index 00b63ae4..5f846730 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -51,7 +51,7 @@ import UIKit stack.addArrangedSubview(primaryButton) NSLayoutConstraint.constraintPinSubview(toSuperview: stack) stack.axis = .horizontal - stack.spacing = 10 + stack.spacing = Padding.Component.gutterForApplicationWidth equalWidthConstraint = secondaryButton.widthAnchor.constraint(equalTo: primaryButton.widthAnchor, multiplier: 1) equalWidthConstraint?.isActive = true } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift index 8539c817..82983f4d 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift @@ -160,7 +160,7 @@ import Foundation /// Collapse if focus is no longer on this top alert. @objc func accessibilityFocusChanged(notification: Notification) { - if !MVMCoreUIUtility.viewContainsAccessiblityFocus(self) { + if (notification.userInfo?[UIAccessibility.focusedElementUserInfoKey] != nil) && !MVMCoreUIUtility.viewContainsAccessiblityFocus(self) { NotificationCenter.default.removeObserver(self, name: UIAccessibility.elementFocusedNotification, object: nil) collapse() } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift index 17b1aef7..bdcd3fe1 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift @@ -24,8 +24,8 @@ open class CollapsableNotificationModel: NotificationModel { super.init(with: headline) } - open override func setDefault() { - super.setDefault() + open override func setDefaults() { + super.setDefaults() if topLabel.textColor == nil { topLabel.textColor = Color(uiColor: .white) } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/Notification.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/Notification.swift index 09edbbcc..c17f43e0 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/Notification.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/Notification.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers open class NotificationView: View { +@objcMembers open class NotificationView: Container { //-------------------------------------------------- // MARK: - Outlets //-------------------------------------------------- @@ -43,19 +43,13 @@ import Foundation labelStack = Stack.createStack(with: [headline, body], spacing: 0) horizontalStack = Stack.createStack(with: [(view: labelStack, model: StackItemModel()),(view: button, model: StackItemModel(horizontalAlignment: .fill)),(view: closeButton, model: StackItemModel(horizontalAlignment: .fill))], axis: .horizontal) - addSubview(horizontalStack) - NSLayoutConstraint.constraintPinSubview(horizontalStack, pinTop: true, topConstant: PaddingTwo, pinBottom: true, bottomConstant: PaddingTwo, pinLeft: true, leftConstant: PaddingThree, pinRight: true, rightConstant: PaddingThree) + addAndContain(horizontalStack) labelStack.restack() horizontalStack.restack() heightAnchor.constraint(equalToConstant: Self.viewHeight).isActive = true } - open override func updateView(_ size: CGFloat) { - super.updateView(size) - horizontalStack.updateView(size) - } - open override func reset() { super.reset() backgroundColor = .mvmGreen() diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift index 3d02cecd..bd84b7fd 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift @@ -7,7 +7,22 @@ // -open class NotificationModel: MoleculeModelProtocol { +open class NotificationModel: ContainerModel, MoleculeModelProtocol { + + /** + The style of the notification: + - success, green background, white content + - error, orange background, black content + - \warning, yellow background, black content + - information, blue background, white content + */ + public enum Style: String, Codable { + case success + case error + case warning + case information + } + //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -19,6 +34,7 @@ open class NotificationModel: MoleculeModelProtocol { public var body: LabelModel? public var button: ButtonModel? public var closeButton: NotificationXButtonModel? + public var style: NotificationModel.Style = .success //-------------------------------------------------- // MARK: - Initializer @@ -26,28 +42,77 @@ open class NotificationModel: MoleculeModelProtocol { public init(with headline: LabelModel) { self.headline = headline + super.init() } //-------------------------------------------------- // MARK: - Default //-------------------------------------------------- - open func setDefault() { + open override func setDefaults() { + useHorizontalMargins = true + useVerticalMargins = true + topPadding = PaddingTwo + bottomPadding = PaddingTwo + if backgroundColor == nil { - backgroundColor = Color(uiColor: .mvmGreen) + switch style { + case .error: + backgroundColor = Color(uiColor: .mvmOrange) + case .warning: + backgroundColor = Color(uiColor: .mvmYellow) + case .information: + backgroundColor = Color(uiColor: .mvmBlue) + default: + backgroundColor = Color(uiColor: .mvmGreen) + } } if headline.textColor == nil { - headline.textColor = Color(uiColor: .mvmWhite) + switch style { + case .error, .warning: + headline.textColor = Color(uiColor: .mvmBlack) + default: + headline.textColor = Color(uiColor: .mvmWhite) + } } if body?.textColor == nil { - body?.textColor = Color(uiColor: .mvmWhite) + switch style { + case .error, .warning: + body?.textColor = Color(uiColor: .mvmBlack) + default: + body?.textColor = Color(uiColor: .mvmWhite) + } + } + + button?.size = .tiny + if button?.enabledTextColor == nil { + switch style { + case .error, .warning: + button?.enabledTextColor = Color(uiColor: .mvmBlack) + default: + button?.enabledTextColor = Color(uiColor: .mvmWhite) + } + } + if button?.enabledBorderColor == nil { + switch style { + case .error, .warning: + button?.enabledBorderColor = Color(uiColor: .mvmBlack) + default: + button?.enabledBorderColor = Color(uiColor: .mvmWhite) + } } if button?.style == nil { button?.style = .secondary } - button?.size = .tiny - button?.enabledTextColor = Color(uiColor: .mvmWhite) - button?.enabledBorderColor = Color(uiColor: .mvmWhite) + + if closeButton?.color == nil { + switch style { + case .error, .warning: + closeButton?.color = Color(uiColor: .mvmBlack) + default: + closeButton?.color = Color(uiColor: .mvmWhite) + } + } } //-------------------------------------------------- @@ -62,6 +127,7 @@ open class NotificationModel: MoleculeModelProtocol { case body case button case closeButton + case style } //-------------------------------------------------- @@ -76,10 +142,13 @@ open class NotificationModel: MoleculeModelProtocol { body = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body) button = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .button) closeButton = try typeContainer.decodeIfPresent(NotificationXButtonModel.self, forKey: .closeButton) - setDefault() + if let style = try typeContainer.decodeIfPresent(NotificationModel.Style.self, forKey: .style) { + self.style = style + } + super.init() } - - open func encode(to encoder: Encoder) throws { + + open override func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) @@ -88,5 +157,6 @@ open class NotificationModel: MoleculeModelProtocol { try container.encodeIfPresent(body, forKey: .body) try container.encodeIfPresent(button, forKey: .button) try container.encodeIfPresent(closeButton, forKey: .closeButton) + try container.encode(style, forKey: .style) } } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift index d2696722..204785cb 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift @@ -33,7 +33,7 @@ import Foundation open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { super.set(with: model, delegateObject, additionalData) guard let model = model as? NotificationXButtonModel else { return } - tintColor = model.color.uiColor + tintColor = model.color?.uiColor ?? .white // TODO: Temporary, consider action for dismissing top alert if model.action.actionType == ActionNoopModel.identifier { diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButtonModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButtonModel.swift index 81dae17e..59da1868 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButtonModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButtonModel.swift @@ -11,7 +11,7 @@ import Foundation public class NotificationXButtonModel: ButtonModelProtocol, MoleculeModelProtocol { public static var identifier: String = "notificationXButton" public var backgroundColor: Color? - public var color = Color(uiColor: .white) + public var color: Color? public var action: ActionModelProtocol = ActionNoopModel() private enum CodingKeys: String, CodingKey { @@ -24,7 +24,7 @@ public class NotificationXButtonModel: ButtonModelProtocol, MoleculeModelProtoco public required init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) ?? Color(uiColor: .white) + color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) if let action: ActionModelProtocol = try typeContainer.decodeModelIfPresent(codingKey: .action) { self.action = action } @@ -33,7 +33,7 @@ public class NotificationXButtonModel: ButtonModelProtocol, MoleculeModelProtoco public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encode(color, forKey: .color) + try container.encodeIfPresent(color, forKey: .color) try container.encodeModel(action, forKey: .action) } } diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLinkModel.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLinkModel.swift index ec646f86..83f5b4bd 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLinkModel.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLinkModel.swift @@ -73,7 +73,7 @@ public class EyebrowHeadlineBodyLinkModel: MoleculeModelProtocol, ParentMolecule backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) eyebrow = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .eyebrow) headline = try typeContainer.decodeMoleculeIfPresent(codingKey: .headline) - body = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body) + body = try typeContainer.decodeMoleculeIfPresent(codingKey: .body) link = try typeContainer.decodeIfPresent(LinkModel.self, forKey: .link) setDefaults() // TODO: This class initializers should ensure that atleast one item is set. diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift index 38081287..67e024ca 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift @@ -17,7 +17,7 @@ public protocol CarouselPageControlProtocol { } open class Carousel: View { - + public let collectionView: CollectionView = { let layout = CarouselCollectionLayout() layout.scrollDirection = .horizontal @@ -25,7 +25,7 @@ open class Carousel: View { layout.minimumLineSpacing = 0 return CollectionView(frame: .zero, collectionViewLayout: layout) }() - + /// The current index of the collection view. Includes dummy cells when looping. public var currentIndex = 0 @@ -53,8 +53,8 @@ open class Carousel: View { public var collectionViewHeight: NSLayoutConstraint? /// The view that we use for paging - public var pagingView: (UIView & CarouselPageControlProtocol)? - + public var pagingView: (MoleculeViewProtocol & CarouselPageControlProtocol)? + /// If the carousel should loop after scrolling past the first and final cells. public var loop = false @@ -85,10 +85,10 @@ open class Carousel: View { open func layoutCollection() { collectionView.collectionViewLayout.invalidateLayout() showPeaking(false) - + // Go to current cell. layoutIfNeeded is needed otherwise cellForItem returns nil for peaking logic. The dispatch is a sad way to ensure the collection view is ready to be scrolled. guard let model = model as? CarouselModel, - (model.paging == true || loop == true) else { return } + (model.paging == true || loop == true) else { return } DispatchQueue.main.async { self.collectionView.scrollToItem(at: IndexPath(row: self.currentIndex, section: 0), at: self.itemAlignment, animated: false) self.collectionView.layoutIfNeeded() @@ -152,12 +152,12 @@ open class Carousel: View { collectionView.layer.borderWidth = (carouselModel.border ?? false) ? 1 : 0 (collectionView.collectionViewLayout as? CarouselCollectionLayout)?.useLines = carouselModel.border ?? false (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.minimumLineSpacing = carouselModel.spacing ?? 0 - + itemWidthPercent = carouselModel.itemWidthPercent / 100.0 if let alignment = carouselModel.itemAlignment { itemAlignment = alignment } - + if let height = carouselModel.height { collectionViewHeight?.constant = height collectionViewHeight?.isActive = true @@ -168,7 +168,7 @@ open class Carousel: View { registerCells(with: carouselModel, delegateObject: delegateObject) prepareMolecules(with: carouselModel) FormValidator.setupValidation(for: carouselModel, delegate: delegateObject?.formHolderDelegate) - + setupPagingMolecule(carouselModel.pagingMolecule, delegateObject: delegateObject) pageIndex = carouselModel.index @@ -197,7 +197,7 @@ open class Carousel: View { if carouselModel?.loop ?? false && newMolecules.count > 1 && !UIAccessibility.isVoiceOverRunning { // Sets up the row data with buffer cells on each side (for illusion of endless scroll... also has one more buffer cell on each side in case we can peek that cell). loop = true - + molecules?.insert(contentsOf: newMolecules.suffix(2), at: 0) molecules?.append(contentsOf: newMolecules.prefix(2)) } else { @@ -207,12 +207,25 @@ open class Carousel: View { pageIndex = 0 } + var pagingMoleculeName: String? + /// Sets up the paging molecule open func setupPagingMolecule(_ molecule: (CarouselPagingModelProtocol & MoleculeModelProtocol)?, delegateObject: MVMCoreUIDelegateObject?) { - var pagingView: (UIView & CarouselPageControlProtocol)? = nil + if let molecule = molecule, - (!molecule.hidesForSinglePage || numberOfPages > 1) { - pagingView = ModelRegistry.createMolecule(molecule, delegateObject: delegateObject) as? (UIView & CarouselPageControlProtocol) + molecule.moleculeName == pagingMoleculeName { + pagingView?.set(with: molecule, delegateObject, nil) + pagingView?.numberOfPages = numberOfPages + return + } + + var pagingView: (MoleculeViewProtocol & CarouselPageControlProtocol)? = nil + if let molecule = molecule, + (!molecule.hidesForSinglePage || numberOfPages > 1) { + pagingView = ModelRegistry.createMolecule(molecule, delegateObject: delegateObject) as? (MoleculeViewProtocol & CarouselPageControlProtocol) + pagingMoleculeName = molecule.moleculeName + } else { + pagingMoleculeName = nil } addPaging(view: pagingView, position: molecule?.position ?? 20) @@ -239,7 +252,7 @@ open class Carousel: View { } /// Adds a paging view. Centers it horizontally with the collection view. The position is the vertical distance from the center of the page view to the bottom of the collection view. - open func addPaging(view: (UIView & CarouselPageControlProtocol)?, position: CGFloat) { + open func addPaging(view: (MoleculeViewProtocol & CarouselPageControlProtocol)?, position: CGFloat) { pagingView?.removeFromSuperview() bottomPin?.isActive = false @@ -296,7 +309,7 @@ open class Carousel: View { func trackSwipeActionAnalyticsforIndex(_ index : Int){ guard let itemModel = molecules?[index], - let viewControllerObject = delegateObject?.moleculeDelegate as? MVMCoreViewControllerProtocol else { return } + let viewControllerObject = delegateObject?.moleculeDelegate as? MVMCoreViewControllerProtocol else { return } MVMCoreUILoggingHandler.shared()?.defaultLogAction(forController: viewControllerObject, actionInformation: itemModel.toJSON(), additionalData: nil) } @@ -352,7 +365,7 @@ open class Carousel: View { carouselAccessibilityElement.accessibilityFrameInContainerSpace = collectionView.frame self.carouselAccessibilityElement = carouselAccessibilityElement } - + if let currentCell = collectionView.cellForItem(at: IndexPath(row: currentIndex, section: 0)) { _accessibilityElements = [currentCell, carouselAccessibilityElement] } else { @@ -378,11 +391,11 @@ extension Carousel: UICollectionViewDataSource { open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return molecules?.count ?? 0 } - + open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { guard let molecule = molecules?[indexPath.row], - let moleculeInfo = getMoleculeInfo(with: molecule, delegateObject: nil) - else { return UICollectionViewCell() } + let moleculeInfo = getMoleculeInfo(with: molecule, delegateObject: nil) + else { return UICollectionViewCell() } let cell = collectionView.dequeueReusableCell(withReuseIdentifier: moleculeInfo.identifier, for: indexPath) if let protocolCell = cell as? MoleculeViewProtocol { @@ -445,22 +458,22 @@ extension Carousel: UIScrollViewDelegate { if translatedPoint > 0 { // Moving left, see if we are moving passed the first left buffer card and adjust if let threshold = collectionView.layoutAttributesForItem(at: IndexPath(item: 1, section: 0))?.frame.minX, - scrollView.contentOffset.x < threshold, - let newOffset = collectionView.layoutAttributesForItem(at: IndexPath(item: numberOfPages + 1, section: 0))?.frame.minX { + scrollView.contentOffset.x < threshold, + let newOffset = collectionView.layoutAttributesForItem(at: IndexPath(item: numberOfPages + 1, section: 0))?.frame.minX { scrollView.contentOffset.x = newOffset } } else if translatedPoint < 0 { // Moving right, see if we are moving passed the first right buffer card and adjust if let threshold = collectionView.layoutAttributesForItem(at: IndexPath(item: numberOfPages + 2, section: 0))?.frame.maxX, - scrollView.contentOffset.x + scrollView.bounds.width > threshold, - let newEndOffset = collectionView.layoutAttributesForItem(at: IndexPath(item: 2, section: 0))?.frame.maxX { + scrollView.contentOffset.x + scrollView.bounds.width > threshold, + let newEndOffset = collectionView.layoutAttributesForItem(at: IndexPath(item: 2, section: 0))?.frame.maxX { scrollView.contentOffset.x = newEndOffset - scrollView.bounds.width } } } - + open func scrollViewDidScroll(_ scrollView: UIScrollView) { - + // Adjust for looping if loop == true { adjustOffsetForLooping(scrollView) @@ -474,7 +487,7 @@ extension Carousel: UIScrollViewDelegate { // Disable peaking when dragging. dragging = true - + showPeaking(false) } @@ -484,7 +497,7 @@ extension Carousel: UIScrollViewDelegate { // This is for setting up smooth custom paging. (Since UICollectionView only handles paging based on collection view size and not cell size). Math requires that we are using UICollectionViewFlowLayout. guard (model as? CarouselModel)?.paging == true, - let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout else { return } + let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout else { return } let separatorWidth = layout.minimumLineSpacing let itemWidth = collectionView.bounds.width * itemWidthPercent @@ -529,7 +542,7 @@ extension Carousel: UIScrollViewDelegate { } else { targetContentOffset.pointee = scrollView.contentOffset } - + // Cap the index. let lastCellIndex = collectionView(collectionView, numberOfItemsInSection: 0) - 1 goTo(min(max(cellToSwipeTo, 0), lastCellIndex), animated: true) @@ -548,35 +561,35 @@ extension Carousel: UIScrollViewDelegate { // Adapted from: https://developer.apple.com/documentation/uikit/accessibility_for_ios_and_tvos/delivering_an_exceptional_accessibility_experience /// Ensures a good accessibility experience. Adds adjustable swiping for cards. class CarouselAccessibilityElement: UIAccessibilityElement { - + /// This indicates to the user what exactly this element is supposed to be. override var accessibilityLabel: String? { get { guard let containerView = accessibilityContainer as? Carousel, - let accessibilityLabel = containerView.accessibilityLabel else { return super.accessibilityLabel } + let accessibilityLabel = containerView.accessibilityLabel else { return super.accessibilityLabel } return accessibilityLabel } set { super.accessibilityLabel = newValue } } - + override var accessibilityValue: String? { get { // Read which card we are on. guard let containerView = accessibilityContainer as? Carousel, - let format = MVMCoreUIUtility.hardcodedString(withKey: "index_string_of_total"), - let indexString = MVMCoreUIUtility.getOrdinalString(forIndex: NSNumber(value: containerView.currentIndex + 1)) else { + let format = MVMCoreUIUtility.hardcodedString(withKey: "index_string_of_total"), + let indexString = MVMCoreUIUtility.getOrdinalString(forIndex: NSNumber(value: containerView.currentIndex + 1)) else { return super.accessibilityValue } return String(format: format, indexString, containerView.numberOfPages) } - + set { super.accessibilityValue = newValue } } - + // This tells VoiceOver that our element will support the increment and decrement callbacks. /// - Tag: accessibility_traits override var accessibilityTraits: UIAccessibilityTraits { @@ -587,41 +600,41 @@ class CarouselAccessibilityElement: UIAccessibilityElement { super.accessibilityTraits = newValue } } - + /** - A convenience for forward scrolling in both `accessibilityIncrement` and `accessibilityScroll`. - It returns a `Bool` because `accessibilityScroll` needs to know if the scroll was successful. - */ + A convenience for forward scrolling in both `accessibilityIncrement` and `accessibilityScroll`. + It returns a `Bool` because `accessibilityScroll` needs to know if the scroll was successful. + */ func accessibilityScrollForward() -> Bool { guard let containerView = accessibilityContainer as? Carousel else { return false } - + let newIndex = containerView.currentIndex + 1 guard newIndex < containerView.numberOfPages else { return false } - + containerView.goTo(newIndex, animated: false) return true } - + /** - A convenience for backward scrolling in both `accessibilityIncrement` and `accessibilityScroll`. - It returns a `Bool` because `accessibilityScroll` needs to know if the scroll was successful. - */ + A convenience for backward scrolling in both `accessibilityIncrement` and `accessibilityScroll`. + It returns a `Bool` because `accessibilityScroll` needs to know if the scroll was successful. + */ func accessibilityScrollBackward() -> Bool { guard let containerView = accessibilityContainer as? Carousel else { return false } - + let newIndex = containerView.currentIndex - 1 guard newIndex >= 0 else { return false } - + containerView.goTo(newIndex, animated: false) - + return true } - + /* - Overriding the following two methods allows the user to perform increment and decrement actions - (done by swiping up or down). - */ + Overriding the following two methods allows the user to perform increment and decrement actions + (done by swiping up or down). + */ /// - Tag: accessibility_increment_decrement override func accessibilityIncrement() { // This causes the picker to move forward one if the user swipes up. @@ -632,12 +645,12 @@ class CarouselAccessibilityElement: UIAccessibilityElement { // This causes the picker to move back one if the user swipes down. _ = accessibilityScrollBackward() } - + /* - This will cause the picker to move forward or backwards on when the user does a 3-finger swipe, - depending on the direction of the swipe. The return value indicates whether or not the scroll was successful, - so that VoiceOver can alert the user if it was not. - */ + This will cause the picker to move forward or backwards on when the user does a 3-finger swipe, + depending on the direction of the swipe. The return value indicates whether or not the scroll was successful, + so that VoiceOver can alert the user if it was not. + */ override func accessibilityScroll(_ direction: UIAccessibilityScrollDirection) -> Bool { if direction == .left { return accessibilityScrollForward() diff --git a/MVMCoreUI/Atomic/Organisms/StackModel.swift b/MVMCoreUI/Atomic/Organisms/StackModel.swift index a350da63..6310fcea 100644 --- a/MVMCoreUI/Atomic/Organisms/StackModel.swift +++ b/MVMCoreUI/Atomic/Organisms/StackModel.swift @@ -13,14 +13,12 @@ // MARK: - Properties //-------------------------------------------------- - static let defaultSpacing: CGFloat = 16.0 - public class var identifier: String { "stack" } public var backgroundColor: Color? public var molecules: [StackItemModelProtocol & MoleculeModelProtocol] public var axis: NSLayoutConstraint.Axis = .vertical - public var spacing: CGFloat = StackModel.defaultSpacing + public var spacing: CGFloat = Padding.Four public var useStackSpacingBeforeFirstItem = false public var children: [MoleculeModelProtocol] { @@ -38,6 +36,8 @@ } if let spacing = spacing { self.spacing = spacing + } else if axis == .horizontal { + self.spacing = Padding.Component.gutterForApplicationWidth } super.init() } @@ -66,6 +66,8 @@ } if let spacing = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .spacing) { self.spacing = spacing + } else if axis == .horizontal { + self.spacing = Padding.Component.gutterForApplicationWidth } backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) try super.init(from: decoder) diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index 1802e25d..a94cafe8 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -79,7 +79,7 @@ public typealias ButtonAction = (Button) -> () addActionBlock(event: .touchUpInside) { [weak self] sender in guard let self = self, let actionModel = actionModel else { return } - Self.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData) + Self.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: self.model) } } diff --git a/MVMCoreUI/BaseControllers/MFLoadingViewController.m b/MVMCoreUI/BaseControllers/MFLoadingViewController.m index aad2383e..56ad6d3b 100644 --- a/MVMCoreUI/BaseControllers/MFLoadingViewController.m +++ b/MVMCoreUI/BaseControllers/MFLoadingViewController.m @@ -34,8 +34,7 @@ [view addSubview:activityIndicatorView]; self.activityIndicator = activityIndicatorView; self.activityIndicator.accessibilityIdentifier = @"Loader"; - - [NSLayoutConstraint constraintPinView:activityIndicatorView heightConstraint:YES heightConstant:PaddingSix widthConstraint:YES widthConstant:PaddingSix]; + [activityIndicatorView pinWidthAndHeight]; // Sets the constraints for the activityIndicatorView [NSLayoutConstraint constraintPinSubview:activityIndicatorView pinCenterX:YES pinCenterY:YES]; diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 28fb37c5..9745b3f4 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -449,8 +449,8 @@ import UIKit } /// Override this method to avoid adding form params. - open func addFormParams(_ requestParameters: MVMCoreRequestParameters) { - formValidator?.addFormParams(requestParameters: requestParameters) + open func addFormParams(requestParameters: MVMCoreRequestParameters, actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) { + formValidator?.addFormParams(requestParameters: requestParameters, model: additionalData?[KeySourceModel] as? MoleculeModelProtocol & FormItemProtocol) } public func handleFieldErrors(_ fieldErrors: [Any]?, loadObject: MVMCoreLoadObject) { @@ -472,7 +472,7 @@ import UIKit //-------------------------------------------------- open func handleOpenPage(for requestParameters: MVMCoreRequestParameters, actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) { - addFormParams(requestParameters) + addFormParams(requestParameters: requestParameters, actionInformation: actionInformation, additionalData: additionalData) requestParameters.parentPageType = loadObject?.pageJSON?.optionalStringForKey("parentPageType") var pageForwardedData = additionalData ?? [:] @@ -657,7 +657,7 @@ import UIKit // MARK: - Behavior Execution //-------------------------------------------------- - func executeBehaviors(_ behaviorBlock: (_ behavior: T) -> Void) { + public func executeBehaviors(_ behaviorBlock: (_ behavior: T) -> Void) { behaviors?.compactMap { $0 as? T }.forEach { behaviorBlock($0) } } } diff --git a/MVMCoreUI/Behaviors/GetContactBehavior.swift b/MVMCoreUI/Behaviors/GetContactBehavior.swift index d62e1ad0..bfb80230 100644 --- a/MVMCoreUI/Behaviors/GetContactBehavior.swift +++ b/MVMCoreUI/Behaviors/GetContactBehavior.swift @@ -23,6 +23,7 @@ public class PageGetContactBehaviorModel: PageBehaviorModelProtocol { } public class PageGetContactBehavior: PageVisibilityBehavior { + var delegate: MVMCoreUIDelegateObject? public required init(model: PageBehaviorModelProtocol, delegateObject: MVMCoreUIDelegateObject?) { @@ -36,21 +37,38 @@ public class PageGetContactBehavior: PageVisibilityBehavior { error == nil, let rootMolecules = self?.delegate?.moleculeDelegate?.getRootMolecules() else { return } // Iterate models and provide contact - let store = CNContactStore() - let consumers: [PageGetContactBehaviorConsumerProtocol] = rootMolecules.allMoleculesOfType() - for consumer in consumers { - guard let parameters = consumer.getMatchParameters(), - let contacts = try? store.unifiedContacts(matching: parameters.0, keysToFetch: parameters.1) else { return } - consumer.consume(contacts: contacts) - } + self?.getContacts(for: rootMolecules) // Tell template to update MVMCoreDispatchUtility.performBlock(onMainThread: { // TODO: move to protocol function instead - (self?.delegate?.moleculeDelegate as? ViewController)?.handleNewData() + guard let controller = self?.delegate?.moleculeDelegate as? ViewController else { return } + controller.handleNewDataAndUpdateUI() + + if MVMCoreUIUtility.getCurrentVisibleController() == controller { + // Update navigation bar if showing. + controller.setNavigationBar() + controller.manager?.refreshNavigationUI() + } + + // Update splitview properties + if controller == MVMCoreUISplitViewController.main()?.getCurrentDetailViewController() { + MVMCoreUISplitViewController.main()?.setBottomProgressBarProgress(controller.bottomProgress() ?? 0) + controller.updateTabBar() + } }) } } - public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) { } + public func getContacts(for molecules: [MoleculeModelProtocol]) { + let consumers: [PageGetContactBehaviorConsumerProtocol] = molecules.allMoleculesOfType() + let store = CNContactStore() + for consumer in consumers { + guard let parameters = consumer.getMatchParameters(), + let contacts = try? store.unifiedContacts(matching: parameters.0, keysToFetch: parameters.1) else { return } + consumer.consume(contacts: contacts) + } + } + + public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) {} } diff --git a/MVMCoreUI/Categories/NSLayoutConstraintExtension.swift b/MVMCoreUI/Categories/NSLayoutConstraintExtension.swift index 242e3fc0..43928769 100644 --- a/MVMCoreUI/Categories/NSLayoutConstraintExtension.swift +++ b/MVMCoreUI/Categories/NSLayoutConstraintExtension.swift @@ -55,6 +55,6 @@ public extension NSLayoutConstraint { } leftView.leadingAnchor.constraint(equalTo: superView.layoutMarginsGuide.leadingAnchor).isActive = true superView.layoutMarginsGuide.trailingAnchor.constraint(equalTo: rightView.trailingAnchor).isActive = true - rightView.leftAnchor.constraint(greaterThanOrEqualTo: leftView.rightAnchor, constant: PaddingHorizontalBetweenRelatedItems).isActive = true + rightView.leftAnchor.constraint(greaterThanOrEqualTo: leftView.rightAnchor, constant: Padding.Component.gutterForApplicationWidth).isActive = true } } diff --git a/MVMCoreUI/FormUIHelpers/FormValidator.swift b/MVMCoreUI/FormUIHelpers/FormValidator.swift index a0785c41..297d1f9e 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator.swift @@ -96,8 +96,13 @@ import MVMCore public func validateGroup(_ group: FormGroupRule) -> Bool { // Validate each rule. var valid = true + var previousValidity: [String: Bool] = [:] for rule in group.rules { - valid = valid && rule.validate(fields) + let tuple = rule.validate(fields, previousValidity) + let isValidRule = tuple.valid + let returnedValidity = tuple.fieldValidity + previousValidity = previousValidity.merging(returnedValidity) { (_, new) in new } + valid = valid && isValidRule } // Notify the group watchers of validity. @@ -112,20 +117,20 @@ import MVMCore // MARK: Form params // TODO: Temporary hacks, rewrite architecture to support this. -@objc public extension FormValidator { +public extension FormValidator { - @objc func addFormParams(requestParameters: MVMCoreRequestParameters) { - let groupName = getGroupName(forPageType: requestParameters.pageType) ?? FormValidator.defaultGroupName - let formParams = self.getFormParams(forGroup: groupName) + func addFormParams(requestParameters: MVMCoreRequestParameters, model: (MoleculeModelProtocol & FormItemProtocol)?) { + let groupName = model?.groupName ?? getGroupName(forPageType: requestParameters.pageType) ?? FormValidator.defaultGroupName + let formParams = getFormParams(forGroup: groupName) requestParameters.add(formParams) } - @objc func getFormParams( forGroup groupName: String) -> [String: Any] { + @objc func getFormParams(forGroup groupName: String) -> [String: Any] { var extraParam: [String: Any] = [:] for (fieldKey, field) in fields { if let formFieldValue = field.formFieldValue(), - groupName == field.groupName { + groupName == field.groupName { extraParam[fieldKey] = formFieldValue } } @@ -136,16 +141,17 @@ import MVMCore // TODO: Temporary hacks, rewrite architecture to support this. public extension FormValidator { - + func getGroupName(forPageType pageType: String?) -> String? { - + for actionItem in groupWatchers { if let buttonModel = actionItem as? ButtonModel, - pageType == (buttonModel.action as? ActionOpenPageModel)?.pageType { + pageType == (buttonModel.action as? ActionOpenPageProtocol)?.pageType { return buttonModel.groupName } } - + return nil } } + diff --git a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyRequiredModel.swift b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyRequiredModel.swift index 7f153e83..3a9b3871 100644 --- a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyRequiredModel.swift +++ b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyRequiredModel.swift @@ -36,15 +36,23 @@ public class RuleAnyRequiredModel: RulesProtocol { return false } - public func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool { - + public func validate(_ fieldMolecules: [String: FormFieldProtocol],_ previousFieldValidity: [String: Bool]) -> (valid: Bool, fieldValidity: [String: Bool]) { + + var previousValidity: [String: Bool] = [:] for formKey in fields { guard let formField = fieldMolecules[formKey] else { continue } - - if isValid(formField) { - return true + + var fieldValidity = isValid(formField) + // If past rule is invalid for a field, the current rule should not flip the validity of a field + if let validity = previousFieldValidity[formKey], !validity, fieldValidity { + fieldValidity = false } + + if fieldValidity { + return (fieldValidity, previousValidity) + } + previousValidity[formKey] = false } - return false + return (valid: false, fieldValidity: previousValidity) } } diff --git a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift index 07cf451f..2a982e45 100644 --- a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift +++ b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift @@ -27,13 +27,21 @@ public class RuleAnyValueChangedModel: RulesProtocol { return formField.baseValue != formField.formFieldValue() } - public func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool { + public func validate(_ fieldMolecules: [String: FormFieldProtocol],_ previousFieldValidity: [String: Bool]) -> (valid: Bool, fieldValidity: [String: Bool]) { + var previousValidity: [String: Bool] = [:] for formKey in fields { guard let formField = fieldMolecules[formKey] else { continue } - if isValid(formField) { - return true + var fieldValidity = isValid(formField) + // If past rule is invalid forr a field, the current rule should not flip the validity of a field + if let validity = previousFieldValidity[formKey], !validity, fieldValidity { + fieldValidity = false } - } - return false + + if fieldValidity { + return (true, previousValidity) + } + previousValidity[formKey] = false + } + return (valid: false, fieldValidity: previousValidity) } } diff --git a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsIgnoreCaseModel.swift b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsIgnoreCaseModel.swift index 5e014cff..8326cf4f 100644 --- a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsIgnoreCaseModel.swift +++ b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsIgnoreCaseModel.swift @@ -27,10 +27,11 @@ public class RuleEqualsIgnoreCaseModel: RulesProtocol { return false } - public func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool { - var valid = false - var compareText: String? + public func validate(_ fieldMolecules: [String: FormFieldProtocol],_ previousFieldValidity: [String: Bool]) -> (valid: Bool, fieldValidity: [String: Bool]) { + var valid = false + var compareText: String? + var previousValidity: [String: Bool] = [:] for formKey in fields { guard let formField = fieldMolecules[formKey] else { continue } @@ -42,16 +43,23 @@ public class RuleEqualsIgnoreCaseModel: RulesProtocol { if let fieldValue = formField.formFieldValue() as? String, compareString.caseInsensitiveCompare(fieldValue) == .orderedSame { valid = true + + var fieldValidity = valid + // If past rule is invalid for a field, the current rule should not flip the validity of a field + if let validity = previousFieldValidity[formKey], !validity, fieldValidity { + fieldValidity = false + } + for formKey in fields { guard let formField = fieldMolecules[formKey] else { continue } (formField as? FormRuleWatcherFieldProtocol)?.setValidity(true, rule: self) } break } - + + previousValidity[formKey] = valid (formField as? FormRuleWatcherFieldProtocol)?.setValidity(valid, rule: self) } - - return valid + return (valid: valid, fieldValidity: previousValidity) } } diff --git a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsModel.swift b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsModel.swift index fa73ed51..a405e2e7 100644 --- a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsModel.swift +++ b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsModel.swift @@ -27,9 +27,10 @@ public class RuleEqualsModel: RulesProtocol { return false } - public func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool { - var valid = true - var compareValue: AnyHashable? + public func validate(_ fieldMolecules: [String: FormFieldProtocol],_ previousFieldValidity: [String: Bool]) -> (valid: Bool, fieldValidity: [String: Bool]) { + var valid = true + var compareValue: AnyHashable? + var previousValidity: [String: Bool] = [:] for formKey in fields { guard let formField = fieldMolecules[formKey] else { continue } @@ -41,13 +42,18 @@ public class RuleEqualsModel: RulesProtocol { if compareValue != formField.formFieldValue() { valid = false + previousValidity[formKey] = valid (formField as? FormRuleWatcherFieldProtocol)?.setValidity(valid, rule: self) break } else { - (formField as? FormRuleWatcherFieldProtocol)?.setValidity(valid, rule: self) + var fieldValidity = valid + // If past rule is invalid for a field, the current rule should not flip the validity of a field + if let validity = previousFieldValidity[formKey], !validity, fieldValidity { + fieldValidity = false + } + (formField as? FormRuleWatcherFieldProtocol)?.setValidity(fieldValidity, rule: self) } } - - return valid + return (valid: valid, fieldValidity: previousValidity) } } diff --git a/MVMCoreUI/FormUIHelpers/Rules/Rules/RulesProtocol.swift b/MVMCoreUI/FormUIHelpers/Rules/Rules/RulesProtocol.swift index 5a8b47a8..db8614ac 100644 --- a/MVMCoreUI/FormUIHelpers/Rules/Rules/RulesProtocol.swift +++ b/MVMCoreUI/FormUIHelpers/Rules/Rules/RulesProtocol.swift @@ -26,7 +26,7 @@ public protocol RulesProtocol: ModelProtocol { func isValid(_ formField: FormFieldProtocol) -> Bool // Validates the rule and returns the result. - func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool + func validate(_ fieldMolecules: [String: FormFieldProtocol],_ previousFieldValidity: [String: Bool]) -> (valid: Bool, fieldValidity: [String: Bool]) } public extension RulesProtocol { @@ -38,14 +38,21 @@ public extension RulesProtocol { static var categoryName: String { "\(RulesProtocol.self)" } // Individual rule can override the function to validate based on the rule type. - func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool { - var valid = true - for formKey in fields { - guard let formField = fieldMolecules[formKey] else { continue } - let fieldValidity = isValid(formField) - (formField as? FormRuleWatcherFieldProtocol)?.setValidity(fieldValidity, rule: self) - valid = valid && fieldValidity - } - return valid + func validate(_ fieldMolecules: [String: FormFieldProtocol],_ previousFieldValidity: [String: Bool]) -> (valid: Bool, fieldValidity: [String: Bool]) { + var valid = true + var previousValidity: [String: Bool] = [:] + for formKey in fields { + guard let formField = fieldMolecules[formKey] else { continue } + + var fieldValidity = isValid(formField) + // If past rule is invalid for a field, the current rule should not flip the validity of a field + if let validity = previousFieldValidity[formKey], !validity, fieldValidity { + fieldValidity = false + } + (formField as? FormRuleWatcherFieldProtocol)?.setValidity(fieldValidity, rule: self) + valid = valid && fieldValidity + previousValidity[formKey] = fieldValidity + } + return (valid: valid, fieldValidity: previousValidity) } } diff --git a/MVMCoreUI/Styles/MFStyler+PaddingExtension.swift b/MVMCoreUI/Styles/MFStyler+PaddingExtension.swift new file mode 100644 index 00000000..6da298e2 --- /dev/null +++ b/MVMCoreUI/Styles/MFStyler+PaddingExtension.swift @@ -0,0 +1,44 @@ +// +// MFStyler+PaddingExtension.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 3/25/21. +// Copyright © 2021 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objc public extension MFStyler { + + @objc static func bridgeGetGutterSizeForApplicationWidth() -> CGFloat { + Padding.Component.gutterForApplicationWidth + } + + @objc static func bridgeGetGutterSize(for size: CGFloat) -> CGFloat { + Padding.Component.gutterFor(size: size) + } + + @objc static func bridgeGetColumnSizeForApplicationWidth() -> CGFloat { + Padding.Component.columnFor(size: MVMCoreUISplitViewController.getApplicationViewWidth()) + } + + @objc static func bridgeGetColumnSize(for size: CGFloat) -> CGFloat { + Padding.Component.columnFor(size: size) + } + + @objc static func bridgeHorizontalPadding(for size: CGFloat) -> CGFloat { + Padding.Component.horizontalPaddingForSize(size) + } + + @objc static func bridgeVerticalPadding(for size: CGFloat) -> CGFloat { + Padding.Component.verticalPaddingForSize(size) + } + + @objc static func bridgeSetDefaultMargins(for view: UIView, size: CGFloat, horizontal: Bool = true, vertical: Bool = false) { + Styler.setDefaultMarginsFor(view, size: size, horizontal: horizontal, vertical: vertical) + } + + @objc static func bridgeSetMargins(for view: UIView, size: CGFloat, horizontal: Bool, top: CGFloat, bottom: CGFloat) { + Styler.setMarginsFor(view, size: size, horizontal: horizontal ? nil : 0, top: top, bottom: bottom) + } +} diff --git a/MVMCoreUI/Styles/MFStyler.h b/MVMCoreUI/Styles/MFStyler.h index a3827044..d8676016 100644 --- a/MVMCoreUI/Styles/MFStyler.h +++ b/MVMCoreUI/Styles/MFStyler.h @@ -57,6 +57,8 @@ extern CGFloat const HeightTableSeperatorHeight; extern CGFloat const MFHeightForSwitch; extern CGFloat const MFMFWidthForSwitch; +extern CGFloat const HeaderMaxWidth; + // Color constants extern CGFloat const DisableOppacity; extern CGFloat const PaymentMethodViewHeightWidthMultiplier; diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index e8d58a26..48ca21a8 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -14,6 +14,7 @@ #import "MVMCoreUISplitViewController.h" @import MVMCore.MVMCoreDispatchUtility; #import +#import CGFloat const PaddingDefault = 24; CGFloat const PaddingDefaultHorizontalSpacing = 32; @@ -26,7 +27,7 @@ CGFloat const PaddingVerticalWhiteGrayView = 72; CGFloat const PaddingVerticalHeadlineAlternate = 48; CGFloat const PaddingPrimaryButtonTop = 36; -CGFloat const PaddingHorizontalBetweenRelatedItems = 16; +CGFloat const PaddingHorizontalBetweenRelatedItems = 12; CGFloat const PaddingOne = 6; CGFloat const PaddingTwo = 12; CGFloat const PaddingThree = 18; @@ -45,6 +46,9 @@ CGFloat const HeightTableSeperatorHeight = 1; CGFloat const MFHeightForSwitch = 22; CGFloat const MFWidthForSwitch = 42; + +CGFloat const HeaderMaxWidth = 596; + CGFloat const DisableOppacity = 0.5; CGFloat const PaymentMethodViewHeightWidthMultiplier = 0.55; CGFloat const MinCellHeight = 96; @@ -77,19 +81,19 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; #pragma mark - Spacing Defaults + (CGFloat)defaultHorizontalPaddingForApplicationWidth { - return [[MFSizeObject sizeObjectWithScalingStandardSize:PaddingDefaultHorizontalSpacing] getValueBasedOnApplicationWidth]; + return [self bridgeHorizontalPaddingFor:[MVMCoreUISplitViewController getApplicationViewWidth]]; } + (CGFloat)defaultVerticalPaddingForApplicationWidth { - return [[MFSizeObject sizeObjectWithScalingStandardSize:PaddingDefaultVerticalSpacing] getValueBasedOnApplicationWidth]; + return [self bridgeVerticalPaddingFor:[MVMCoreUISplitViewController getApplicationViewWidth]]; } + (CGFloat)defaultHorizontalPaddingForSize:(CGFloat)size { - return [[MFSizeObject sizeObjectWithScalingStandardSize:PaddingDefaultHorizontalSpacing] getValueBasedOnSize:size]; + return [self bridgeHorizontalPaddingFor:size]; } + (CGFloat)defaultVerticalPaddingForSize:(CGFloat)size { - return [[MFSizeObject sizeObjectWithScalingStandardSize:PaddingDefaultVerticalSpacing] getValueBasedOnSize:size]; + return [self bridgeVerticalPaddingFor:size]; } + (void)setDefaultMarginsForView:(nullable UIView *)view size:(CGFloat)size { @@ -97,18 +101,13 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (void)setDefaultMarginsForView:(nullable UIView *)view size:(CGFloat)size horizontal:(BOOL)horizontal vertical:(BOOL)vertical { - CGFloat horizontalPadding = horizontal ? [MFStyler defaultHorizontalPaddingForSize:size] : 0; - CGFloat verticalPadding = vertical ? PaddingDefaultVerticalSpacing3 : 0; - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - [MVMCoreUIUtility setMarginsForView:view leading:horizontalPadding top:verticalPadding trailing:horizontalPadding bottom:verticalPadding]; - }]; + if (!view) { return; } + [self bridgeSetDefaultMarginsFor:view size:size horizontal:horizontal vertical:vertical]; } + (void)setMarginsForView:(nullable UIView *)view size:(CGFloat)size defaultHorizontal:(BOOL)horizontal top:(CGFloat)top bottom:(CGFloat)bottom { - CGFloat horizontalPadding = horizontal ? [MFStyler defaultHorizontalPaddingForSize:size] : 0; - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - [MVMCoreUIUtility setMarginsForView:view leading:horizontalPadding top:top trailing:horizontalPadding bottom:bottom]; - }]; + if (!view) { return; } + [self bridgeSetMarginsFor:view size:size horizontal:horizontal top:top bottom:bottom]; } #pragma mark - 3.0 fonts diff --git a/MVMCoreUI/Styles/Padding.swift b/MVMCoreUI/Styles/Padding.swift index 480896a0..f7e5b407 100644 --- a/MVMCoreUI/Styles/Padding.swift +++ b/MVMCoreUI/Styles/Padding.swift @@ -23,24 +23,41 @@ public struct Padding { public struct Component { public static let Standard: CGFloat = 24 - public static let HorizontalMarginSpacing: CGFloat = 32 - public static let LargeVerticalMarginSpacing: CGFloat = 32 + public static let HorizontalMarginSpacing: CGFloat = 16 + public static let LargeHorizontalMarginSpacing: CGFloat = 32 public static let VerticalMarginSpacing: CGFloat = 24 - + public static let LargeVerticalMarginSpacing: CGFloat = 32 + public static let HorizontalGutterSpacing: CGFloat = 12 + public static let LargeHorizontalGutterSpacing: CGFloat = 24 + public static var horizontalPaddingForApplicationWidth: CGFloat { - MFSizeObject(scalingStandardSize: HorizontalMarginSpacing)?.getValueBasedOnApplicationWidth() ?? HorizontalMarginSpacing + horizontalPaddingForSize(MVMCoreUISplitViewController.getApplicationViewWidth()) } public static var verticalPaddingForApplicationWidth: CGFloat { - MFSizeObject(scalingStandardSize: VerticalMarginSpacing)?.getValueBasedOnApplicationWidth() ?? VerticalMarginSpacing + verticalPaddingForSize(MVMCoreUISplitViewController.getApplicationViewWidth()) + } + + public static var gutterForApplicationWidth: CGFloat { + gutterFor(size: MVMCoreUISplitViewController.getApplicationViewWidth()) } public static func horizontalPaddingForSize(_ size: CGFloat) -> CGFloat { - MFSizeObject(scalingStandardSize: HorizontalMarginSpacing)?.getValueBased(onSize: size) ?? HorizontalMarginSpacing + let sizeObject = MFSizeObject(standardSize: HorizontalMarginSpacing)! + return sizeObject.getValueBased(onSize: size) } public static func verticalPaddingForSize(_ size: CGFloat) -> CGFloat { MFSizeObject(scalingStandardSize: VerticalMarginSpacing)?.getValueBased(onSize: size) ?? VerticalMarginSpacing } + + public static func gutterFor(size: CGFloat) -> CGFloat { + let sizeObject = MFSizeObject(standardSize: HorizontalGutterSpacing)! + return sizeObject.getValueBased(onSize: size) + } + + public static func columnFor(size: CGFloat) -> CGFloat { + return (size - (3.0 * gutterFor(size: size)) - (2.0 * horizontalPaddingForSize(size))) / 4.0 + } } } diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m index 46ecd793..405dd781 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m @@ -423,7 +423,7 @@ } - (void)accessibilityFocusChanged:(NSNotification *)notification { - if (![MVMCoreUIUtility viewContainsAccessiblityFocus:self]) { + if (notification.userInfo[UIAccessibilityFocusedElementKey] && ![MVMCoreUIUtility viewContainsAccessiblityFocus:self]) { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIAccessibilityElementFocusedNotification object:nil]; [self collapse]; } diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m index 44f248f3..fa96630f 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m @@ -164,18 +164,19 @@ [self.iconView removeFromSuperview]; } + CGFloat horizontalPadding = [MFStyler defaultHorizontalPaddingForApplicationWidth]; if (imageURL) { LoadImageView *imageView = [[LoadImageView alloc] init]; imageView.translatesAutoresizingMaskIntoConstraints = NO; [imageView setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal]; [self addSubview:imageView]; [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|->=space-[imageView]->=space-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:@{@"space":@(PaddingFive)} views:NSDictionaryOfVariableBindings(imageView)]]; - [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-space-[imageView]-space-[centerView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:@{@"space":@(PaddingThree)} views:NSDictionaryOfVariableBindings(imageView,centerView)]]; + [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-space-[imageView]-space-[centerView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:@{@"space":@(horizontalPadding)} views:NSDictionaryOfVariableBindings(imageView,centerView)]]; [NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0].active = YES; self.iconView = imageView; [imageView loadImageWithName:imageURL width:@(32)]; } else { - [NSLayoutConstraint constraintWithItem:centerView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:PaddingThree].active = YES; + [NSLayoutConstraint constraintWithItem:centerView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:horizontalPadding].active = YES; } } @@ -193,6 +194,7 @@ - (void)setupWithButton:(BOOL)showButton { // Setup the button. + CGFloat horizontalPadding = [MFStyler defaultHorizontalPaddingForApplicationWidth]; if (showButton) { if (!self.button) { @@ -210,7 +212,7 @@ [self addSubview:button]; [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0].active = YES; [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.centerView attribute:NSLayoutAttributeRight multiplier:1 constant:PaddingThree].active = YES; - [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:button attribute:NSLayoutAttributeRight multiplier:1 constant:(self.closeButton ? PaddingTen : PaddingFive)].active = YES; + [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:button attribute:NSLayoutAttributeRight multiplier:1 constant:(self.closeButton ? PaddingTen : horizontalPadding)].active = YES; self.button = button; } } else { @@ -222,7 +224,7 @@ } if (!self.labelRightConstraint) { - self.labelRightConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.centerView attribute:NSLayoutAttributeRight multiplier:1 constant:(self.closeButton ? PaddingTen : PaddingFive)]; + self.labelRightConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.centerView attribute:NSLayoutAttributeRight multiplier:1 constant:(self.closeButton ? PaddingTen : horizontalPadding)]; } self.labelRightConstraint.active = YES; } diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m index ad0a833f..eba4cfcc 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m @@ -335,7 +335,7 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed."; /// If the voice over user leaves top alert focus, hide. - (void)accessibilityFocusChanged:(NSNotification *)notification { - if (![MVMCoreUIUtility viewContainsAccessiblityFocus:self]) { + if (notification.userInfo[UIAccessibilityFocusedElementKey] && ![MVMCoreUIUtility viewContainsAccessiblityFocus:self]) { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIAccessibilityElementFocusedNotification object:nil]; [self hideAlertView:YES completionHandler:self.hideCompletionHandler]; self.hideCompletionHandler = nil; diff --git a/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift b/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift index d1173250..60e57d75 100644 --- a/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift +++ b/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift @@ -23,11 +23,11 @@ public extension MVMCoreUICommonViewsUtility { view.addSubview(button) var constraints: [NSLayoutConstraint] = [] if centeredVertically { - constraints.append(view.rightAnchor.constraint(equalTo: button.rightAnchor, constant: PaddingTwo)) + constraints.append(view.rightAnchor.constraint(equalTo: button.rightAnchor, constant: Padding.Component.horizontalPaddingForApplicationWidth)) constraints.append(view.centerYAnchor.constraint(equalTo: button.centerYAnchor)) } else { constraints.append(button.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: PaddingOne)) - constraints.append(view.safeAreaLayoutGuide.rightAnchor.constraint(equalTo: button.rightAnchor, constant: PaddingTwo)) + constraints.append(view.safeAreaLayoutGuide.rightAnchor.constraint(equalTo: button.rightAnchor, constant: Padding.Component.horizontalPaddingForApplicationWidth)) } NSLayoutConstraint.activate(constraints) return button diff --git a/MVMCoreUI/Utility/Sizing/MFSizeObject.h b/MVMCoreUI/Utility/Sizing/MFSizeObject.h index 781feb4c..5c40dafe 100644 --- a/MVMCoreUI/Utility/Sizing/MFSizeObject.h +++ b/MVMCoreUI/Utility/Sizing/MFSizeObject.h @@ -17,6 +17,7 @@ extern CGFloat const MFSizeLargeiPhoneThreshold; extern CGFloat const MFSizeStandardiPadPortraitThreshold; extern CGFloat const MFSizeStandardiPadLandscapeThreshold; extern CGFloat const MFSizeiPadProLandscapeThreshold; +extern CGFloat const MFSizeMostlySweetSpotThreshold; @interface MFSizeObject : NSObject diff --git a/MVMCoreUI/Utility/Sizing/MFSizeObject.m b/MVMCoreUI/Utility/Sizing/MFSizeObject.m index 792e2d81..3379a1ce 100644 --- a/MVMCoreUI/Utility/Sizing/MFSizeObject.m +++ b/MVMCoreUI/Utility/Sizing/MFSizeObject.m @@ -18,6 +18,8 @@ CGFloat const MFSizeLargeiPhoneThreshold = 400; CGFloat const MFSizeStandardiPadPortraitThreshold = 600; CGFloat const MFSizeStandardiPadLandscapeThreshold = 1000; CGFloat const MFSizeiPadProLandscapeThreshold = 1300; +CGFloat const MFSizeMostlySweetSpotThreshold = 750; + @interface MFSizeObject ()