Skip to content

Commit

Permalink
Merge branch 'prerelease_0_15_2' into accessibility/progressbar
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisBorleeAdevinta authored May 30, 2024
2 parents 34a4f73 + e978db3 commit 1d52d94
Show file tree
Hide file tree
Showing 171 changed files with 8,661 additions and 2,758 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ jobs:
uses: actions/checkout@v3
- name: Run sourcery
run: |
VERSION=$(cat .sourcery-version)
echo "Downloading Sourcery from https://github.com/krzysztofzablocki/Sourcery/releases/download/$VERSION/sourcery-$VERSION.zip"
curl -L https://github.com/krzysztofzablocki/Sourcery/releases/download/$VERSION/sourcery-$VERSION.zip -o sourcery.zip
unzip sourcery.zip -d sourcery-bin
./sourcery-bin/bin/sourcery
brew install sourcery
sourcery
- name: Run xcodegen
uses: xavierLowmiller/[email protected]
with:
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ spark-ios-snapshots

#sourcery
*Generated/
sourcery-bin
sourcery.zip

vendor/
*.lock
1 change: 0 additions & 1 deletion .sourcery-version

This file was deleted.

14 changes: 0 additions & 14 deletions PrivacyInfo.xcprivacy

This file was deleted.

15 changes: 14 additions & 1 deletion core/Sources/Common/DataType/Updateable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import Foundation

protocol Updateable {
func update<Value>(_ keyPath: WritableKeyPath<Self, Value>, value: Value) -> Self
associatedtype T
func update<Value>(_ keyPath: WritableKeyPath<T, Value>, value: Value) -> T
func updateIfNeeded<Value: Equatable>(keyPath: ReferenceWritableKeyPath<T, Value>, newValue: Value)
func updateIfNeeded(keyPath: ReferenceWritableKeyPath<T, any ColorToken>, newValue: any ColorToken)
}

extension Updateable {
Expand All @@ -19,4 +22,14 @@ extension Updateable {
copy[keyPath: keyPath] = value
return copy
}

func updateIfNeeded<Value: Equatable>(keyPath: ReferenceWritableKeyPath<Self, Value>, newValue: Value) {
guard self[keyPath: keyPath] != newValue else { return }
self[keyPath: keyPath] = newValue
}

func updateIfNeeded(keyPath: ReferenceWritableKeyPath<Self, any ColorToken>, newValue: any ColorToken) {
guard self[keyPath: keyPath].equals(newValue) == false else { return }
self[keyPath: keyPath] = newValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension EdgeInsets {
/// - Parameters:
/// - vertical: horizontal inset value use to set left and right insets.
/// - horizontal: horizontal inset value use to set left and right insets.
init(vertical: CGFloat, horizontal: CGFloat) {
init(vertical: CGFloat = 0, horizontal: CGFloat = 0) {
self = .init(top: vertical, leading: horizontal, bottom: vertical, trailing: horizontal)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import UIKit

extension UIControl {

// Add a default tap gesture recognizer without any action to detect the action/publisher/target action even if the parent view has a gesture recognizer
// Why? UIControl action/publisher/target doesn't work if the parent contains a gesture recognizer.
// Note: Native UIButton add the same default recognizer to manage this use case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

import UIKit

struct EdgeSet: OptionSet {
let rawValue: UInt

static let top = EdgeSet(rawValue: 1 << 0)
static let trailing = EdgeSet(rawValue: 2 << 0)
static let bottom = EdgeSet(rawValue: 3 << 0)
static let leading = EdgeSet(rawValue: 4 << 0)

static let all: EdgeSet = [.top, .trailing, .bottom, .leading]
}

extension NSLayoutConstraint {
/// Make the view stick to the edges of an other view
///
Expand All @@ -24,6 +35,26 @@ extension NSLayoutConstraint {
])
}

static func edgeConstraints(from: UIView, to: UIView, insets: UIEdgeInsets = .zero, edge: EdgeSet = .all) -> [NSLayoutConstraint] {

var constraints = [NSLayoutConstraint]()
if edge.contains(.top) {
constraints.append(from.topAnchor.constraint(equalTo: to.topAnchor, constant: insets.top))
}
if edge.contains(.leading) {
constraints.append(from.leadingAnchor.constraint(equalTo: to.leadingAnchor, constant: insets.left))
}
if edge.contains(.bottom) {
constraints.append(from.bottomAnchor.constraint(equalTo: to.bottomAnchor, constant: -insets.bottom))
}
if edge.contains(.trailing) {
constraints.append(from.trailingAnchor.constraint(equalTo: to.trailingAnchor, constant: -insets.right))
}


return constraints
}

static func center(from: UIView, to: UIView) {
NSLayoutConstraint.activate([
from.centerXAnchor.constraint(equalTo: to.centerXAnchor),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ extension ButtonSpacings {
// MARK: - Properties

static func mocked(
verticalSpacing: CGFloat = 10,
horizontalSpacing: CGFloat = 11,
horizontalPadding: CGFloat = 12
) -> Self {
return .init(
verticalSpacing: verticalSpacing,
horizontalSpacing: horizontalSpacing,
horizontalPadding: horizontalPadding
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ struct ButtonSpacings: Equatable {

// MARK: - Properties

let verticalSpacing: CGFloat
let horizontalSpacing: CGFloat
let horizontalPadding: CGFloat
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ struct ButtonGetSpacingsUseCase: ButtonGetSpacingsUseCaseable {

func execute(spacing: LayoutSpacing) -> ButtonSpacings {
return .init(
verticalSpacing: spacing.medium,
horizontalSpacing: spacing.large,
horizontalPadding: spacing.medium
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ final class ButtonGetSpacingsUseCaseTests: XCTestCase {
)

// THEN
XCTAssertEqual(spacings.verticalSpacing,
spacingMock.medium,
"Wrong verticalSpacing value")
XCTAssertEqual(spacings.horizontalSpacing,
spacingMock.large,
"Wrong horizontalSpacing value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ struct ButtonContainerView<ContainerView: View, ViewModel: ButtonMainViewModel &
var body: some View {
Button(action: self.action) {
self.contentView()
.padding(self.padding)
.frame(height: self.height)
.frame(minWidth: self.height)
.background(self.viewModel.currentColors?.backgroundColor.color ?? .clear)
.contentShape(Rectangle())
.border(
width: self.borderWidth,
radius: self.borderRadius,
colorToken: self.viewModel.currentColors?.borderColor ?? ColorTokenDefault.clear
)
}
.buttonStyle(PressedButtonStyle(
isPressed: self.$isPressed
))
.padding(self.padding)
.frame(height: self.height)
.frame(minWidth: self.height)
.background(self.viewModel.currentColors?.backgroundColor.color ?? .clear)
.border(
width: self.borderWidth,
radius: self.borderRadius,
colorToken: self.viewModel.currentColors?.borderColor ?? ColorTokenDefault.clear
)
.compositingGroup()
.disabled(self.viewModel.state?.isUserInteractionEnabled == false)
.opacity(self.viewModel.state?.opacity ?? .zero)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public struct ButtonView: View {

@ObservedObject private var viewModel: ButtonSUIViewModel

@ScaledMetric private var verticalSpacing: CGFloat
@ScaledMetric private var horizontalSpacing: CGFloat
@ScaledMetric private var horizontalPadding: CGFloat

Expand Down Expand Up @@ -53,7 +52,6 @@ public struct ButtonView: View {

// **
// Scaled Metric
self._verticalSpacing = .init(wrappedValue: viewModel.spacings?.verticalSpacing ?? .zero)
self._horizontalSpacing = .init(wrappedValue: viewModel.spacings?.horizontalSpacing ?? .zero)
self._horizontalPadding = .init(wrappedValue: viewModel.spacings?.horizontalPadding ?? .zero)
// **
Expand All @@ -67,7 +65,6 @@ public struct ButtonView: View {
ButtonContainerView(
viewModel: self.viewModel,
padding: .init(
vertical: self.verticalSpacing,
horizontal: self.horizontalSpacing
),
action: self.action
Expand Down Expand Up @@ -96,8 +93,8 @@ public struct ButtonView: View {
maxWidth: self.viewModel.maxWidth,
alignment: self.viewModel.frameAlignment
)
.contentShape(Rectangle())
.animation(nil, value: UUID())
.animation(nil, value: self.viewModel.maxWidth)
.animation(nil, value: self.viewModel.frameAlignment)
}

@ViewBuilder
Expand All @@ -112,9 +109,11 @@ public struct ButtonView: View {
.foregroundStyle(self.viewModel.currentColors?.titleColor?.color ?? ColorTokenDefault.clear.color)
.font(self.viewModel.titleFontToken?.font)
.accessibilityIdentifier(ButtonAccessibilityIdentifier.text)
.animation(nil, value: text)
} else if let attributedText = self.viewModel.controlStateText?.attributedText {
Text(attributedText)
.accessibilityIdentifier(ButtonAccessibilityIdentifier.text)
.animation(nil, value: attributedText)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public struct IconButtonView: View {
action: self.action
) {
ButtonImageView(viewModel: self.viewModel)
.animation(nil, value: UUID())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ public final class ButtonUIView: ButtonMainUIView {
private let viewModel: ButtonViewModel

private var contentStackViewLeadingConstraint: NSLayoutConstraint?
private var contentStackViewTopConstraint: NSLayoutConstraint?
private var contentStackViewBottomConstraint: NSLayoutConstraint?

@ScaledUIMetric private var verticalSpacing: CGFloat = 0
@ScaledUIMetric private var horizontalSpacing: CGFloat = 0
@ScaledUIMetric private var horizontalPadding: CGFloat = 0

Expand Down Expand Up @@ -199,15 +196,15 @@ public final class ButtonUIView: ButtonMainUIView {
self.contentStackView.translatesAutoresizingMaskIntoConstraints = false

self.contentStackViewLeadingConstraint = self.contentStackView.leadingAnchor.constraint(greaterThanOrEqualTo: self.leadingAnchor)
self.contentStackViewTopConstraint = self.contentStackView.topAnchor.constraint(equalTo: self.topAnchor)
let contentStackViewTopConstraint = self.contentStackView.topAnchor.constraint(equalTo: self.topAnchor)
let contentStackViewCenterXAnchor = self.contentStackView.centerXAnchor.constraint(equalTo: self.centerXAnchor)
self.contentStackViewBottomConstraint = self.contentStackView.bottomAnchor.constraint(equalTo: self.bottomAnchor)
let contentStackViewBottomConstraint = self.contentStackView.bottomAnchor.constraint(equalTo: self.bottomAnchor)

NSLayoutConstraint.activate([
self.contentStackViewLeadingConstraint,
self.contentStackViewTopConstraint,
contentStackViewTopConstraint,
contentStackViewCenterXAnchor,
self.contentStackViewBottomConstraint,
contentStackViewBottomConstraint,
].compactMap({ $0 }))
}

Expand Down Expand Up @@ -283,12 +280,10 @@ public final class ButtonUIView: ButtonMainUIView {

private func updateSpacings() {
// Reload spacing only if value changed
let verticalSpacing = self._verticalSpacing.wrappedValue
let horizontalSpacing = self._horizontalSpacing.wrappedValue
let horizontalPadding = self._horizontalPadding.wrappedValue

if verticalSpacing != self.contentStackViewTopConstraint?.constant ||
horizontalSpacing != self.contentStackViewLeadingConstraint?.constant ||
if horizontalSpacing != self.contentStackViewLeadingConstraint?.constant ||
horizontalPadding != self.contentStackView.spacing {

let isAnimated = self.isAnimated && !self.firstContentStackViewAnimation
Expand All @@ -300,8 +295,6 @@ public final class ButtonUIView: ButtonMainUIView {
self.firstContentStackViewAnimation = false

self.contentStackViewLeadingConstraint?.constant = horizontalSpacing
self.contentStackViewTopConstraint?.constant = verticalSpacing
self.contentStackViewBottomConstraint?.constant = -verticalSpacing
self.contentStackView.updateConstraintsIfNeeded()

self.contentStackView.spacing = horizontalPadding
Expand All @@ -312,7 +305,6 @@ public final class ButtonUIView: ButtonMainUIView {
// MARK: - Data Did Update

private func spacingsDidUpdate(_ spacings: ButtonSpacings) {
self.verticalSpacing = spacings.verticalSpacing
self.horizontalSpacing = spacings.horizontalSpacing
self.horizontalPadding = spacings.horizontalPadding

Expand Down Expand Up @@ -383,7 +375,6 @@ public final class ButtonUIView: ButtonMainUIView {
super.traitCollectionDidChange(previousTraitCollection)

// Update spacings
self._verticalSpacing.update(traitCollection: self.traitCollection)
self._horizontalSpacing.update(traitCollection: self.traitCollection)
self._horizontalPadding.update(traitCollection: self.traitCollection)
self.updateSpacings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,7 @@ private final class Stub: ButtonViewModelStub {

super.init(
viewModel: viewModel,
getSpacingsUseCaseMock: getSpacingsUseCaseMock,
getBorderUseCaseMock: ButtonGetBorderUseCaseableGeneratedMock(),
getColorsUseCaseMock: ButtonGetColorsUseCaseableGeneratedMock(),
getCurrentColorsUseCaseMock: ButtonGetCurrentColorsUseCaseableGeneratedMock(),
getSizesUseCaseMock: ButtonGetSizesUseCaseableGeneratedMock(),
getStateUseCaseMock: ButtonGetStateUseCaseableGeneratedMock()
getSpacingsUseCaseMock: getSpacingsUseCaseMock
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ import Foundation

/// The accessibility identifiers for the checkbox.
public enum CheckboxAccessibilityIdentifier {
/// The default accessibility identifier. Can be changed by the consumer
/// The default checkbox accessibility identifier.
public static let checkbox = "spark-check-box"
/// The default accessibility identifier. Can be changed by the consumer
/// The default checkbox group accessibility identifier.
public static let checkboxGroup = "spark-check-box-group"
/// The identifier of checkbox group ui view title
public static let checkboxGroupTitle = "spark-check-box-group-title"
/// The default checkbox group item accessibility identifier.
public static func checkboxGroupItem(_ id: String) -> String {
Self.checkbox + "-\(id)"
}
}

public enum CheckboxAccessibilityValue {
public static let checked = "1"
public static let indeterminate = "0.5"
public static let unchecked = "0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ final class CheckboxGroupViewModel: ObservableObject {
@Published var checkedImage: Image
@Published var layout: CheckboxGroupLayout
@Published var spacing: LayoutSpacing
@Published var accessibilityIdentifierPrefix: String
@Published var titleFont: TypographyFontToken
@Published var titleColor: any ColorToken
@Published var intent: CheckboxIntent
Expand All @@ -28,7 +27,6 @@ final class CheckboxGroupViewModel: ObservableObject {
init(
title: String?,
checkedImage: Image,
accessibilityIdentifierPrefix: String,
theme: Theme,
intent: CheckboxIntent = .main,
alignment: CheckboxAlignment = .left,
Expand All @@ -43,7 +41,6 @@ final class CheckboxGroupViewModel: ObservableObject {
self.spacing = theme.layout.spacing
self.titleFont = theme.typography.subhead
self.titleColor = theme.colors.base.onSurface
self.accessibilityIdentifierPrefix = accessibilityIdentifierPrefix
}

func calculateSingleCheckboxWidth(string: String?) -> CGFloat {
Expand Down
Loading

0 comments on commit 1d52d94

Please sign in to comment.