Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 2.2.0 chore: Update style options struct and add equatable conformance #98

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SeamlessPay.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SeamlessPay'
s.version = '2.1.0'
s.version = '2.2.0'
s.summary = 'There are three demo apps included with the framework.'

s.description = <<~DESC
Expand Down
56 changes: 45 additions & 11 deletions SeamlessPay/UI/Models/StyleOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,31 @@
import UIKit
import Foundation

public struct StyleOptions {
public var colors: Colors = .default
public var shapes: Shapes = .default
public var typography: Typography = .default
public struct StyleOptions: Equatable {
public var colors: Colors
public var shapes: Shapes
public var typography: Typography

public init(colors: Colors, shapes: Shapes, typography: Typography) {
self.colors = colors
self.shapes = shapes
self.typography = typography
}

public static var `default`: StyleOptions {
StyleOptions(colors: .default, shapes: .default, typography: .default)
}
}

public struct Colors {
public struct Colors: Equatable {
public var light: ColorPalette
public var dark: ColorPalette

public init(light: ColorPalette, dark: ColorPalette) {
self.light = light
self.dark = dark
}

public static var `default`: Colors {
Colors(light: .init(theme: .light), dark: .init(theme: .dark))
}
Expand All @@ -31,19 +42,29 @@ public struct Colors {
}
}

public struct ColorPalette {
public struct ColorPalette: Equatable {
public var theme: ThemeColors

public init(theme: ThemeColors) {
self.theme = theme
}

public static var `default`: ColorPalette {
ColorPalette(theme: .default)
}
}

public struct ThemeColors {
public struct ThemeColors: Equatable {
public var neutral: UIColor
public var primary: UIColor
public var danger: UIColor

public init(neutral: UIColor, primary: UIColor, danger: UIColor) {
self.neutral = neutral
self.primary = primary
self.danger = danger
}

public static var `default`: ThemeColors {
.light
}
Expand All @@ -65,23 +86,31 @@ public struct ThemeColors {
}
}

public struct Shapes {
public struct Shapes: Equatable {
public var cornerRadius: CGFloat

public init(cornerRadius: CGFloat) {
self.cornerRadius = cornerRadius
}

public static var `default`: Shapes {
Shapes(cornerRadius: 8.0)
}
}

public struct Shadow {
public struct Shadow: Equatable {
public var elevation: ElevationLevel

public init(elevation: ElevationLevel) {
self.elevation = elevation
}

public static var `default`: Shadow {
Shadow(elevation: .none)
}
}

public enum ElevationLevel {
public enum ElevationLevel: Equatable {
case none
case level1
case level2
Expand All @@ -90,7 +119,7 @@ public enum ElevationLevel {
case level5
}

public struct Typography {
public struct Typography: Equatable {
public var font: UIFont
public var scale: CGFloat {
willSet {
Expand All @@ -100,6 +129,11 @@ public struct Typography {
}
}

public init(font: UIFont, scale: CGFloat) {
self.font = font
self.scale = scale
}

public static var `default`: Typography {
Typography(font: UIFont.systemFont(ofSize: 18), scale: 1.0)
}
Expand Down
20 changes: 9 additions & 11 deletions SeamlessPay/UI/PaymentInputs/Direct/MultiLineCardForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class MultiLineCardForm: UIControl, CardForm {
[numberField, expirationField, cvcField, postalCodeField]
}

private let styleOptions: StyleOptions
let styleOptions: StyleOptions

// MARK: - Subviews
private lazy var numberField: LineTextField = {
Expand Down Expand Up @@ -191,35 +191,36 @@ public class MultiLineCardForm: UIControl, CardForm {
}()

// MARK: - Internal
let viewModel: CardFormViewModel
let viewModel: CardFormViewModel = .init()

// MARK: - Constants
private let textFieldHeight: CGFloat = 84

// MARK: - Initializers
override public init(frame: CGRect) {
viewModel = .init()
styleOptions = .default
self.styleOptions = .default
super.init(frame: frame)
setUpSubViews()
}

required init?(coder: NSCoder) {
viewModel = .init()
styleOptions = .default
self.styleOptions = .default
super.init(coder: coder)
setUpSubViews()
}

public convenience init(

public init(
config: ClientConfiguration,
fieldOptions: FieldOptions = .default,
styleOptions: StyleOptions = .default
) {
self.init()
self.styleOptions = styleOptions
viewModel.apiClient = .init(config: config)
viewModel.cvcDisplayConfig = fieldOptions.cvv.display
viewModel.postalCodeDisplayConfig = fieldOptions.postalCode.display
super.init(frame: .zero)
setUpSubViews()

layoutIfNeeded()
}
Expand Down Expand Up @@ -283,9 +284,6 @@ private extension MultiLineCardForm {
textField.defaultColor = .darkText
textField.errorColor = .systemRed

let currentPalette = styleOptions.colors.palette(for: traitCollection)
let theme = currentPalette.theme

textField.appearance = buildTextFieldAppearanceConfig()

return textField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class MultiLineCardFormTests: XCTestCase {

override func setUp() {
super.setUp()
multiLineCardForm = MultiLineCardForm(frame: .zero)
multiLineCardForm = MultiLineCardForm(
config: .init(environment: .production, secretKey: "secret_ket"),
fieldOptions: .init(cvv: .init(display: .required), postalCode: .init(display: .required)),
styleOptions: .default
)
}

override func tearDown() {
Expand Down Expand Up @@ -123,4 +127,42 @@ class MultiLineCardFormTests: XCTestCase {
multiLineCardForm.isEnabled = true
XCTAssertTrue(multiLineCardForm.isEnabled)
}

func testInitializerWithDefaultStyleOptions() {
let config = ClientConfiguration(
environment: .production,
secretKey: "test_secret_key",
proxyAccountId: .none
)

let multiLineCardForm = MultiLineCardForm(config: config)

XCTAssertNotNil(multiLineCardForm)
XCTAssertEqual(multiLineCardForm.styleOptions, .default)
}

func testInitializerWithCustomStyleOptions() {
let config = ClientConfiguration(
environment: .production,
secretKey: "test_secret_key",
proxyAccountId: .none
)

let styleOptions = StyleOptions(
colors: .init(
light: .init(theme: .init(neutral: .blue, primary: .green, danger: .red)),
dark: .init(theme: .init(neutral: .purple, primary: .yellow, danger: .cyan))
),
shapes: .init(cornerRadius: 8),
typography: .init(font: .boldSystemFont(ofSize: 18), scale: 1.2)
)

let multiLineCardForm = MultiLineCardForm(
config: config,
styleOptions: styleOptions
)

XCTAssertNotNil(multiLineCardForm)
XCTAssertNotEqual(multiLineCardForm.styleOptions, .default)
}
}