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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
* Add `PayPalVaultDelegate` to handle results from vault flow
* Add `PayPalWebCheckoutClientError.paypalVaultResponseError` for missing or invalid response from vaulting
* PaymentButtons
* Add new `PaymentButtonSize` case `.regular`
* Add `custom` case for `PaymentButtonEdges`
* Support VoiceOver by adding button accessibility labels
* Add new `PaymentButtonSize` case `.miniWithWordmark`
* 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
* PaymentButtons
* Remove `PayPalButton.Labels` cases: `.checkout`, `.buyNow`, `.payLater`
* Remove `PaymentButtonColor` `.black`, `.silver`, `.blue`, and `.darkBlue`
* Add `PaymentButtonColor.gold` for `PayPalCreditButton`
* Remove `PayPalButton.Labels` cases: `.checkout`, `.buyNow`, `.payLater`
stechiu marked this conversation as resolved.
Show resolved Hide resolved
* 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 @@ -27,15 +27,15 @@ struct PayPalWebButtonsView: View {

switch selectedFundingSource {
case .paypalCredit:
PayPalCreditButton.Representable(color: .gold, size: .full) {
PayPalCreditButton.Representable(color: .gold, size: .regular) {
payPalWebViewModel.paymentButtonTapped(funding: .paypalCredit)
}
case .paylater:
PayPalPayLaterButton.Representable(color: .silver, edges: .softEdges, size: .full) {
PayPalPayLaterButton.Representable(color: .silver, edges: .softEdges, size: .regular) {
richherrera marked this conversation as resolved.
Show resolved Hide resolved
payPalWebViewModel.paymentButtonTapped(funding: .paylater)
}
case .paypal:
PayPalButton.Representable(color: .blue, size: .full) {
PayPalButton.Representable(color: .blue, size: .regular) {
richherrera marked this conversation as resolved.
Show resolved Hide resolved
payPalWebViewModel.paymentButtonTapped(funding: .paypal)
}
}
Expand Down
13 changes: 12 additions & 1 deletion Demo/Demo/SwiftUIComponents/SwiftUIPaymentButtonDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,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
}

Picker("label", selection: $labelIndex) {
ForEach(labels.indices, id: \.self) { index in
Text(labels[index])
Expand Down
19 changes: 5 additions & 14 deletions Sources/PaymentButtons/ImageAsset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,15 @@ enum ImageAsset {

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
8 changes: 4 additions & 4 deletions Sources/PaymentButtons/PayPalButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ public final class PayPalButton: PaymentButton {
/// - insets: Edge insets of the button, defining the spacing of the button's edges relative to its content.
/// - color: Color of the button. Default to gold if not provided.
/// - edges: Edges of the button. Default to softEdges if not provided.
/// - size: Size of the button. Default to collapsed if not provided.
/// - size: Size of the button. Default to regular if not provided.
/// - label: Label displayed next to the button's logo. Default to no label.
public convenience init(
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 @@ -127,13 +127,13 @@ public extension PayPalButton {
/// - insets: Edge insets of the button, defining the spacing of the button's edges relative to its content.
/// - color: Color of the button. Default to gold if not provided.
/// - edges: Edges of the button. Default to softEdges if not provided.
/// - size: Size of the button. Default to collapsed if not provided.
/// - size: Size of the button. Default to regular if not provided.
/// - label: Label displayed next to the button's logo. Default to no label.
public init(
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
8 changes: 4 additions & 4 deletions Sources/PaymentButtons/PayPalCreditButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public final class PayPalCreditButton: PaymentButton {
/// - insets: Edge insets of the button, defining the spacing of the button's edges relative to its content.
/// - color: Color of the button. Default to gold if not provided.
/// - edges: Edges of the button. Default to softEdges if not provided.
/// - size: Size of the button. Default to collapsed if not provided.
/// - size: Size of the button. Default to regular if not provided.
public convenience init(
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
) {
self.init(
fundingSource: PaymentButtonFundingSource.credit,
Expand Down Expand Up @@ -54,12 +54,12 @@ public extension PayPalCreditButton {
/// - insets: Edge insets of the button, defining the spacing of the button's edges relative to its content.
/// - color: Color of the button. Default to gold if not provided.
/// - edges: Edges of the button. Default to softEdges if not provided.
/// - size: Size of the button. Default to collapsed if not provided.
/// - size: Size of the button. Default to regular if not provided.
public init(
insets: NSDirectionalEdgeInsets? = nil,
color: PayPalCreditButton.Color = .gold,
edges: PaymentButtonEdges = .softEdges,
size: PaymentButtonSize = .collapsed,
size: PaymentButtonSize = .regular,
_ action: @escaping () -> Void = { }
) {
self.button = PayPalCreditButton(
Expand Down
8 changes: 4 additions & 4 deletions Sources/PaymentButtons/PayPalPayLaterButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public final class PayPalPayLaterButton: PaymentButton {
/// - insets: Edge insets of the button, defining the spacing of the button's edges relative to its content.
/// - color: Color of the button. Default to gold if not provided.
/// - edges: Edges of the button. Default to softEdges if not provided.
/// - size: Size of the button. Default to collapsed if not provided.
/// - size: Size of the button. Default to regular if not provided.
public convenience init(
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 All @@ -51,12 +51,12 @@ public extension PayPalPayLaterButton {
/// - insets: Edge insets of the button, defining the spacing of the button's edges relative to its content.
/// - color: Color of the button. Default to gold if not provided.
/// - edges: Edges of the button. Default to softEdges if not provided.
/// - size: Size of the button. Default to collapsed if not provided.
/// - size: Size of the button. Default to regular if not provided.
public init(
insets: NSDirectionalEdgeInsets? = nil,
color: PayPalPayLaterButton.Color = .gold,
edges: PaymentButtonEdges = .softEdges,
size: PaymentButtonSize = .collapsed,
size: PaymentButtonSize = .regular,
_ action: @escaping () -> Void = { }
) {
self.button = PayPalPayLaterButton(
Expand Down
32 changes: 9 additions & 23 deletions Sources/PaymentButtons/PaymentButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,22 @@ public class PaymentButton: UIButton {
public private(set) var label: PaymentButtonLabel?

private var imageHeight: CGFloat {
// For pay later or paypal credit return different image height
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 +136,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 @@ -250,9 +237,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 @@ -266,7 +252,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
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"
}
}
}
Loading
Loading