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

Update Button Sizes #241

Merged
merged 15 commits into from
Jan 29, 2024
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

## unreleased
* PaymentButtons
* Add new `PaymentButtonSize` case `.miniWithWordmark`
* Add new `PaymentButtonSize` case `.regular`
* Add new `PayPalButton.Labels` cases: `.addMoneyWith`, `.bookWith`, `.buyWith`, `.buyNowWith`,
`.checkoutWith`, `.continueWith`, `.contributeWith`, `.orderWith`, `.payLaterWith`, `.payWith`,
`.reloadWith`, `.rentWith`, `.reserveWith`, `.subscribeWith`, `.supportWith`, `.tipWith`,
`.topUpWith`
* `PayPalButtonSize` `.mini` changed to rectangular button to meet brand guidelines
* Breaking Changes
* Remove `PayPalButton.Labels` cases: `.checkout`, `.buyNow`, `.payLater`
* Remove `PaymentButtonSize` cases: `.miniWithWordmark`, `.collapsed`, `.expanded`, `.full`

## 1.1.0 (2023-11-16)
* PayPalNativePayments
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/Extensions/PaymentButtonEnums+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension PaymentButtonEdges: CaseIterable {
extension PaymentButtonSize: CaseIterable {

public static var allCases: [PaymentButtonSize] {
[.mini, .miniWithWordmark, .collapsed, .expanded, .full]
[.mini, .regular]
}

static func allCasesAsString() -> [String] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ struct PayPalWebButtonsView: View {
payPalWebViewModel.paymentButtonTapped(funding: .paypal)
}
.frame(maxWidth: .infinity, maxHeight: 40)
PayPalButton.Representable(color: .gold, size: .miniWithWordmark) {
PayPalButton.Representable(color: .gold, size: .mini) {
payPalWebViewModel.paymentButtonTapped(funding: .paypal)
}
.frame(maxWidth: .infinity, maxHeight: 40)
PayPalCreditButton.Representable(color: .black, edges: .softEdges, size: .expanded) {
PayPalCreditButton.Representable(color: .black, edges: .rounded, size: .regular) {
payPalWebViewModel.paymentButtonTapped(funding: .paypalCredit)
}
.frame(maxWidth: .infinity, maxHeight: 40)
PayPalPayLaterButton.Representable(color: .silver, edges: .rounded, size: .full) {
PayPalPayLaterButton.Representable(color: .silver, edges: .rounded, size: .regular) {
payPalWebViewModel.paymentButtonTapped(funding: .paylater)
}
.frame(maxWidth: .infinity, maxHeight: 40)
Expand Down
24 changes: 12 additions & 12 deletions Demo/Demo/SwiftUIComponents/SwiftUIPaymentButtonDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ struct SwiftUIPaymentButtonDemo: View {
}
.id(pickerId)

Picker("Edges", selection: $edgesIndex) {
ForEach(edges.indices, id: \.self) { index in
Text(edges[index])
}
}
.pickerStyle(SegmentedPickerStyle())
.onChange(of: edgesIndex) { _ in
selectedEdge = PaymentButtonEdges.allCases[edgesIndex]
buttonId += 1
}

Picker("sizes", selection: $sizesIndex) {
ForEach(sizes.indices, id: \.self) { index in
Text(sizes[index])
Expand All @@ -80,7 +69,18 @@ struct SwiftUIPaymentButtonDemo: View {

switch selectedFunding {
case .payPal:
if selectedSize == .expanded || selectedSize == .full {
if selectedSize == .regular {
Picker("Edges", selection: $edgesIndex) {
ForEach(edges.indices, id: \.self) { index in
Text(edges[index])
}
}
.pickerStyle(SegmentedPickerStyle())
.onChange(of: edgesIndex) { _ in
selectedEdge = PaymentButtonEdges.allCases[edgesIndex]
buttonId += 1
stechiu marked this conversation as resolved.
Show resolved Hide resolved
}

Picker("label", selection: $labelIndex) {
ForEach(labels.indices, id: \.self) { index in
Text(labels[index])
Expand Down
21 changes: 6 additions & 15 deletions Sources/PaymentButtons/ImageAsset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,18 @@ enum ImageAsset {
switch button.fundingSource {
case .payPal:
imageAssetString = "paypal"

stechiu marked this conversation as resolved.
Show resolved Hide resolved
case .payLater:
imageAssetString = "paypal"

if button.size == .collapsed {
imageAssetString = "paypal_monogram"
}


case .credit:
if button.size == .collapsed {
imageAssetString = "credit_monogram"
} else if button.size != .miniWithWordmark && button.size != .mini {
if button.size != .mini {
imageAssetString = "credit"
}
}

if button.size == .mini {
imageAssetString = "paypal_monogram"
} else if button.size == .miniWithWordmark {
imageAssetString = "paypal_vertical"
}
if button.size == .mini {
imageAssetString = "paypal_vertical"
}
stechiu marked this conversation as resolved.
Show resolved Hide resolved

return UIImage(named: imageAssetString, in: PaymentButton.bundle, compatibleWith: nil)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/PaymentButtons/PayPalButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public final class PayPalButton: PaymentButton {
insets: NSDirectionalEdgeInsets? = nil,
color: Color = .gold,
edges: PaymentButtonEdges = .softEdges,
size: PaymentButtonSize = .collapsed,
size: PaymentButtonSize = .regular,
stechiu marked this conversation as resolved.
Show resolved Hide resolved
label: Label? = nil
) {
self.init(
Expand Down Expand Up @@ -136,7 +136,7 @@ public extension PayPalButton {
insets: NSDirectionalEdgeInsets? = nil,
color: PayPalButton.Color = .gold,
edges: PaymentButtonEdges = .softEdges,
size: PaymentButtonSize = .collapsed,
size: PaymentButtonSize = .regular,
stechiu marked this conversation as resolved.
Show resolved Hide resolved
label: PayPalButton.Label? = nil,
_ action: @escaping () -> Void = { }
) {
Expand Down
6 changes: 3 additions & 3 deletions Sources/PaymentButtons/PayPalCreditButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class PayPalCreditButton: PaymentButton {
insets: NSDirectionalEdgeInsets? = nil,
color: Color = .darkBlue,
edges: PaymentButtonEdges = .softEdges,
size: PaymentButtonSize = .collapsed
size: PaymentButtonSize = .regular
stechiu marked this conversation as resolved.
Show resolved Hide resolved
) {
self.init(
fundingSource: PaymentButtonFundingSource.credit,
Expand Down Expand Up @@ -59,8 +59,8 @@ public extension PayPalCreditButton {
public init(
insets: NSDirectionalEdgeInsets? = nil,
color: PayPalCreditButton.Color = .darkBlue,
edges: PaymentButtonEdges = .softEdges,
size: PaymentButtonSize = .collapsed,
edges: PaymentButtonEdges = .rounded,
size: PaymentButtonSize = .regular,
_ action: @escaping () -> Void = { }
) {
self.button = PayPalCreditButton(
Expand Down
6 changes: 3 additions & 3 deletions Sources/PaymentButtons/PayPalPayLaterButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class PayPalPayLaterButton: PaymentButton {
insets: NSDirectionalEdgeInsets? = nil,
color: Color = .gold,
edges: PaymentButtonEdges = .softEdges,
stechiu marked this conversation as resolved.
Show resolved Hide resolved
size: PaymentButtonSize = .collapsed,
size: PaymentButtonSize = .regular,
stechiu marked this conversation as resolved.
Show resolved Hide resolved
_ action: @escaping () -> Void = { }
) {
self.init(
Expand Down Expand Up @@ -58,8 +58,8 @@ public extension PayPalPayLaterButton {
public init(
insets: NSDirectionalEdgeInsets? = nil,
color: PayPalPayLaterButton.Color = .gold,
edges: PaymentButtonEdges = .softEdges,
size: PaymentButtonSize = .collapsed,
edges: PaymentButtonEdges = .rounded,
size: PaymentButtonSize = .regular,
stechiu marked this conversation as resolved.
Show resolved Hide resolved
_ action: @escaping () -> Void = { }
) {
self.button = PayPalPayLaterButton(
Expand Down
31 changes: 9 additions & 22 deletions Sources/PaymentButtons/PaymentButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,21 @@ public class PaymentButton: UIButton {
private var imageHeight: CGFloat {
// For pay later or paypal credit return different image height
stechiu marked this conversation as resolved.
Show resolved Hide resolved
switch size {
case .mini:
return 20.0

case .miniWithWordmark:
case .mini:
return 24.0

case .collapsed:
return 15.0

case .expanded:
case .regular:
return 20.0

case .full:
return 26.0
}
}

private var supportsPrefixLabel: Bool {
switch size {
case .mini, .miniWithWordmark, .collapsed:
case .mini:
return false

case .expanded, .full:
case .regular:
if let label = label {
return label.position == .prefix
}
Expand All @@ -145,15 +137,11 @@ public class PaymentButton: UIButton {
}

private var supportsSuffixLabel: Bool {

switch size {
case .mini, .miniWithWordmark:
case .mini:
return false

case .collapsed:
return fundingSource == .payLater

case .expanded, .full:
case .regular:
if let label = label {
return label.position == .suffix
}
Expand Down Expand Up @@ -239,9 +227,8 @@ public class PaymentButton: UIButton {
// MARK: - Override Function
override public func layoutSubviews() {
super.layoutSubviews()
if size == .mini || size == .miniWithWordmark {
let minValue = min(containerView.bounds.width, containerView.bounds.height)
containerView.layer.cornerRadius = minValue / 2
if size == .mini {
containerView.layer.cornerRadius = 4.0
} else {
containerView.layer.cornerRadius = edges.cornerRadius(for: containerView)
}
Expand All @@ -255,7 +242,7 @@ public class PaymentButton: UIButton {

// Size to fit
switch size {
case .mini, .miniWithWordmark:
case .mini:
let maxValue = max(image.size.width, image.size.height)
imageView.bounds = CGRect(
x: 0,
Expand Down
2 changes: 1 addition & 1 deletion Sources/PaymentButtons/PaymentButtonColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum PaymentButtonColor: String {
var color: UIColor {
switch self {
case .gold:
return UIColor(hexString: "#FFC439")
stechiu marked this conversation as resolved.
Show resolved Hide resolved
return UIColor(hexString: "#FFD140")

case .white:
return UIColor(hexString: "#FFFFFF")
Expand Down
82 changes: 18 additions & 64 deletions Sources/PaymentButtons/PaymentButtonSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,107 +3,61 @@ import UIKit
/// The size category which determines how the button is shown.
public enum PaymentButtonSize: Int, CustomStringConvertible {

/// Smallest button size that will show the PayPal monogram only. Use this for screens where space is limited. The recommended size when displaying on screens with limited space `.miniWithWordmark`
/// Smallest button size uses the primary mark, vertically stacked. This is the recommended size when displaying on screens with limited space.
case mini

/// Smallest button size that will show the primary mark (PayPal monogram and wordmark). This is the recommended size when displaying on screens with limited space.
case miniWithWordmark

/// Collapsed shows the primary mark (PayPal monogram and wordmark) along with the prefix or suffix.
case collapsed

/// Expanded shows the primary mark (PayPal monogram and wordmark along with the prefix or suffix
case expanded

/// Full will show the primary mark (PayPal monogram and wordmark along with the prefix or suffix.
case full
/// Regular size shows the primary mark along with the prefix or suffix
case regular

var font: UIFont {
switch self {
case .mini, .miniWithWordmark, .collapsed:
case .mini:
return PaymentButtonFont.secondaryFont

case .expanded:
case .regular:
return PaymentButtonFont.primaryFont

case .full:
return PaymentButtonFont.systemFont18
}
}

var elementSpacing: CGFloat {
switch self {
case .mini, .miniWithWordmark, .collapsed:
case .mini:
return 4.0

case .expanded:
case .regular:
return 4.5

case .full:
return 6.0
}
}

var elementPadding: NSDirectionalEdgeInsets {
switch self {
case .mini:
return NSDirectionalEdgeInsets(
top: 14.0,
leading: 14.0,
bottom: 14.0,
trailing: 14.0
)

stechiu marked this conversation as resolved.
Show resolved Hide resolved
case .miniWithWordmark:
return NSDirectionalEdgeInsets(
top: 14.0,
leading: 14.0,
bottom: 14.0,
trailing: 14.0
)

case .collapsed:
case .mini:
return NSDirectionalEdgeInsets(
top: 15.0,
top: 9.0,
leading: 20.0,
bottom: 15.0,
bottom: 9.0,
trailing: 20.0
)

case .expanded:
return NSDirectionalEdgeInsets(
top: 13.0,
leading: 24.0,
bottom: 13.0,
trailing: 24.0
)

case .full:
case .regular:
return NSDirectionalEdgeInsets(
top: 15.0,
leading: 44.0,
bottom: 15.0,
trailing: 44.0
top: 10.0,
leading: 80.0,
bottom: 10.0,
trailing: 80.0
)
}
}

public var description: String {
switch self {

stechiu marked this conversation as resolved.
Show resolved Hide resolved
case .mini:
return "mini"

case .miniWithWordmark:
return "mini with wordmark"

case .collapsed:
return "collapsed"

case .expanded:
return "expanded"

case .full:
return "full"
case .regular:
return "regular"
}
}
}
2 changes: 1 addition & 1 deletion UnitTests/PaymentButtonsTests/PayPalButton_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PayPalButton_Tests: XCTestCase {
func testInit_whenPayPalButtonCreated_hasDefaultUIValuess() {
let sut = PayPalButton()
XCTAssertEqual(sut.edges, PaymentButtonEdges.softEdges)
XCTAssertEqual(sut.size, PaymentButtonSize.collapsed)
XCTAssertEqual(sut.size, PaymentButtonSize.regular)
XCTAssertEqual(sut.color, PaymentButtonColor.gold)
XCTAssertNil(sut.label)
XCTAssertNil(sut.insets)
Expand Down
Loading
Loading