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

Fixed PaymentButton sizing issue #255

Merged
merged 9 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
* Add `status` property to `CardResult`
* Add `didAttemptThreeDSecureAuthentication` property to `CardResult`
* PaymentButtons
* Add `custom` case for `PaymentButtonEdges`
* Support VoiceOver by adding button accessibility labels
* Add `custom` case for `PaymentButtonEdges`
* Support VoiceOver by adding button accessibility labels
* Font typeface changed to "PayPalOpen" to meet brand guidelines
* Fixed frame alignment and width issue occuring in SwiftUI
* PayPalWebPayments
* Add `vault(url:)` method to `PayPalWebCheckoutClient`
* Add `PayPalVaultResult` type to return vault result
Expand Down
2 changes: 2 additions & 0 deletions Demo/Demo/SwiftUIComponents/SwiftUIPaymentButtonDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct SwiftUIPaymentButtonDemo: View {
size: selectedSize
)
.id(buttonID)
.frame(maxWidth: .infinity)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these needed? I removed them and tested in canvas and sim and seem to be okay without these changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're not needed but I have them there so that people, internally and externally, who aren't familiar with SwiftUI know that you can set the button widths. Pre-PR, this part was broken and you couldn't customize the width in SwiftUI. If it feels redundant and unnecessary, I can remove it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to remove them if they're not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, I'll update but will leave one of the in


case .credit:
PayPalCreditButton.Representable(
Expand All @@ -119,6 +120,7 @@ struct SwiftUIPaymentButtonDemo: View {
size: selectedSize
)
.id(buttonID)
.frame(maxWidth: .infinity)
}
}
.padding()
Expand Down
21 changes: 13 additions & 8 deletions Sources/PaymentButtons/PayPalButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,13 @@ public extension PayPalButton {
Coordinator(action: action)
}

public func makeUIView(context: Context) -> UIView {
let view = UIView()

view.addSubview(button)
public func makeUIView(context: Context) -> PaymentButton {
let button = button
stechiu marked this conversation as resolved.
Show resolved Hide resolved
button.addTarget(context.coordinator, action: #selector(Coordinator.onAction(_:)), for: .touchUpInside)

return view
return button
}

public func updateUIView(_ uiView: UIView, context: Context) {
public func updateUIView(_ uiView: PaymentButton, context: Context) {
context.coordinator.action = action
}
}
Expand All @@ -125,13 +122,21 @@ public extension PayPalButton {
struct PayPalButtonView: View {

var body: some View {

stechiu marked this conversation as resolved.
Show resolved Hide resolved
PayPalButton.Representable()
}
}

struct PayPalButtonView_Preview: PreviewProvider {

static var previews: some View {
PayPalButtonView()
PayPalButtonWrapper()
stechiu marked this conversation as resolved.
Show resolved Hide resolved
}

struct PayPalButtonWrapper: View {
stechiu marked this conversation as resolved.
Show resolved Hide resolved

var body: some View {
PayPalButton.Representable()
}
}
}
23 changes: 14 additions & 9 deletions Sources/PaymentButtons/PayPalCreditButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public extension PayPalCreditButton {
_ action: @escaping () -> Void = { }
) {
self.button = PayPalCreditButton(
fundingSource: PaymentButtonFundingSource.credit,
fundingSource: .credit,
color: color.color,
edges: edges,
size: size,
Expand All @@ -81,16 +81,13 @@ public extension PayPalCreditButton {
Coordinator(action: action)
}

public func makeUIView(context: Context) -> UIView {
let view = UIView()

view.addSubview(button)
public func makeUIView(context: Context) -> PaymentButton {
let button = button
jaxdesmarais marked this conversation as resolved.
Show resolved Hide resolved
button.addTarget(context.coordinator, action: #selector(Coordinator.onAction(_:)), for: .touchUpInside)

return view
return button
}

public func updateUIView(_ uiView: UIView, context: Context) {
public func updateUIView(_ uiView: PaymentButton, context: Context) {
context.coordinator.action = action
}
}
Expand All @@ -101,13 +98,21 @@ public extension PayPalCreditButton {
struct PayPalCreditButtonView: View {

var body: some View {

PayPalCreditButton.Representable()
}
}

struct PayPalCreditButtonView_Preview: PreviewProvider {

static var previews: some View {
PayPalCreditButtonView()
PayPalCreditButtonWrapper()
stechiu marked this conversation as resolved.
Show resolved Hide resolved
}

struct PayPalCreditButtonWrapper: View {
stechiu marked this conversation as resolved.
Show resolved Hide resolved

var body: some View {
PayPalCreditButton.Representable()
}
}
}
21 changes: 13 additions & 8 deletions Sources/PaymentButtons/PayPalPayLaterButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,13 @@ public extension PayPalPayLaterButton {
Coordinator(action: action)
}

public func makeUIView(context: Context) -> UIView {
let view = UIView()
view.addSubview(button)

public func makeUIView(context: Context) -> PaymentButton {
let button = button
stechiu marked this conversation as resolved.
Show resolved Hide resolved
button.addTarget(context.coordinator, action: #selector(Coordinator.onAction(_:)), for: .touchUpInside)

return view
return button
}

public func updateUIView(_ uiView: UIView, context: Context) {
public func updateUIView(_ uiView: PaymentButton, context: Context) {
context.coordinator.action = action
}
}
Expand All @@ -101,13 +98,21 @@ public extension PayPalPayLaterButton {
struct PayPalPayLaterButtonView: View {

var body: some View {

PayPalPayLaterButton.Representable()
}
}

struct PayPalPayLaterButtonView_Preview: PreviewProvider {

static var previews: some View {
PayPalPayLaterButtonView()
PayPalPayLaterButtonWrapper()
stechiu marked this conversation as resolved.
Show resolved Hide resolved
}

struct PayPalPayLaterButtonWrapper: View {
stechiu marked this conversation as resolved.
Show resolved Hide resolved

var body: some View {
PayPalPayLaterButton.Representable()
}
}
}
13 changes: 12 additions & 1 deletion Sources/PaymentButtons/PaymentButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class PaymentButton: UIButton {
self.insets = insets
self.label = label
super.init(frame: .zero)
configure()
}

// MARK: - Views
Expand Down Expand Up @@ -248,6 +247,8 @@ public class PaymentButton: UIButton {
// MARK: - Override Function
override public func layoutSubviews() {
super.layoutSubviews()
configure()

if size == .mini {
let minValue = min(containerView.bounds.width, containerView.bounds.height)
containerView.layer.cornerRadius = minValue / 2
Expand All @@ -256,6 +257,16 @@ public class PaymentButton: UIButton {
}
}

public override var intrinsicContentSize: CGSize {
stechiu marked this conversation as resolved.
Show resolved Hide resolved
switch size {
case .mini:
return CGSize(width: 36, height: 24)

case .collapsed, .expanded, .full:
return CGSize(width: frame.size.width, height: imageHeight + size.elementPadding.top * 2)
}
}

// MARK: - Utility

private func sizeToImage(on imageView: UIImageView, with size: PaymentButtonSize) {
Expand Down
Loading