Skip to content

Commit

Permalink
Set embedded view default padding to zero as originally intended
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-stripe committed Jan 15, 2025
1 parent 41f58f3 commit 4d56904
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
### ApplePay
* [Added] Added a `dismiss` method to `STPApplePayContext`.

### PaymentSheet
* [Fixed] Embedded Payment Element (private beta) layout margins default to zero.


## 24.4.0 2025-01-13
### PaymentSheet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ private class PaymentMethodsViewController: UIViewController {
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
])

embeddedPaymentElement.view.layoutMargins = .zero
let stackView = UIStackView(arrangedSubviews: [embeddedPaymentElement.view, continueButton])
stackView.axis = .vertical
stackView.translatesAutoresizingMaskIntoConstraints = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ class EmbeddedPaymentElementContainerView: UIView {
init(embeddedPaymentMethodsView: EmbeddedPaymentMethodsView) {
self.contentView = embeddedPaymentMethodsView
super.init(frame: .zero)
addInitialView(contentView)
directionalLayoutMargins = .zero
setContentView(contentView)
}

required init?(coder: NSCoder) {
fatalError()
}

private func addInitialView(_ view: UIView) {
private func setContentView(_ view: UIView) {
view.translatesAutoresizingMaskIntoConstraints = false
addSubview(view)
bottomAnchorConstraint = view.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor)
Expand All @@ -39,7 +40,7 @@ class EmbeddedPaymentElementContainerView: UIView {
// A zero frame means we haven't been laid out yet. Simply replace the old view to avoid laying out before the view is ready and breaking constraints.
contentView.removeFromSuperview()
contentView = embeddedPaymentMethodsView
addInitialView(embeddedPaymentMethodsView)
setContentView(embeddedPaymentMethodsView)
return
}
let oldContentView = contentView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,14 @@ class EmbeddedPaymentElementSnapshotTests: STPSnapshotTestCase, EmbeddedPaymentE
XCTAssertTrue(delegateDidUpdateHeightCalled)
XCTAssertFalse(delegateDidUpdatePaymentOptionCalled)
}

func testMarginsAreZero() async throws {
let sut = try await EmbeddedPaymentElement.create(intentConfiguration: paymentIntentConfig, configuration: configuration)
sut.delegate = self
sut.presentingViewController = UIViewController()
sut.view.autosizeHeight(width: 300)

XCTAssertEqual(sut.view.directionalLayoutMargins, .zero)
XCTAssertFalse(sut.view.hasAmbiguousLayout)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4d56904

Please sign in to comment.