diff --git a/CHANGELOG.md b/CHANGELOG.md index 30ef79877..16a5844b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,9 @@ * 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 + * Fixed button alignment and size bug in SwiftUI with `intrinsicContentSize` + * The height cannot be set smaller than 38px or width shorter than 300px * CardPayments * Add `status` property to `CardVaultResult` * Add `didAttemptThreeDSecureAuthentication` property to `CardVaultResult` diff --git a/Demo/Demo/SwiftUIComponents/SwiftUIPaymentButtonDemo.swift b/Demo/Demo/SwiftUIComponents/SwiftUIPaymentButtonDemo.swift index bae7b026c..145da5d35 100644 --- a/Demo/Demo/SwiftUIComponents/SwiftUIPaymentButtonDemo.swift +++ b/Demo/Demo/SwiftUIComponents/SwiftUIPaymentButtonDemo.swift @@ -102,7 +102,6 @@ struct SwiftUIPaymentButtonDemo: View { label: selectedLabel ) .id(buttonID) - .frame(maxWidth: .infinity) case .payLater: PayPalPayLaterButton.Representable( diff --git a/Sources/PaymentButtons/PayPalButton.swift b/Sources/PaymentButtons/PayPalButton.swift index 7f8de192b..0f02f1745 100644 --- a/Sources/PaymentButtons/PayPalButton.swift +++ b/Sources/PaymentButtons/PayPalButton.swift @@ -105,16 +105,12 @@ public extension PayPalButton { Coordinator(action: action) } - public func makeUIView(context: Context) -> UIView { - let view = UIView() - - view.addSubview(button) + public func makeUIView(context: Context) -> PaymentButton { 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 } } diff --git a/Sources/PaymentButtons/PayPalCreditButton.swift b/Sources/PaymentButtons/PayPalCreditButton.swift index e66045035..ec4967691 100644 --- a/Sources/PaymentButtons/PayPalCreditButton.swift +++ b/Sources/PaymentButtons/PayPalCreditButton.swift @@ -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, @@ -81,16 +81,12 @@ public extension PayPalCreditButton { Coordinator(action: action) } - public func makeUIView(context: Context) -> UIView { - let view = UIView() - - view.addSubview(button) + public func makeUIView(context: Context) -> PaymentButton { 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 } } diff --git a/Sources/PaymentButtons/PayPalPayLaterButton.swift b/Sources/PaymentButtons/PayPalPayLaterButton.swift index 9485eabef..e4ed6f8aa 100644 --- a/Sources/PaymentButtons/PayPalPayLaterButton.swift +++ b/Sources/PaymentButtons/PayPalPayLaterButton.swift @@ -80,16 +80,12 @@ public extension PayPalPayLaterButton { Coordinator(action: action) } - public func makeUIView(context: Context) -> UIView { - let view = UIView() - view.addSubview(button) - + public func makeUIView(context: Context) -> PaymentButton { 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 } } diff --git a/Sources/PaymentButtons/PaymentButton.swift b/Sources/PaymentButtons/PaymentButton.swift index 97628a2a7..f1ce334d5 100644 --- a/Sources/PaymentButtons/PaymentButton.swift +++ b/Sources/PaymentButtons/PaymentButton.swift @@ -37,7 +37,6 @@ public class PaymentButton: UIButton { self.insets = insets self.label = label super.init(frame: .zero) - configure() } // MARK: - Views @@ -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 @@ -256,6 +257,16 @@ public class PaymentButton: UIButton { } } + public override var intrinsicContentSize: CGSize { + 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) {