Skip to content

Commit 0e5fd41

Browse files
authored
[1.0.4] Dismiss only the checkout sheet on cancel (#73)
* Dismiss only the checkout sheet on cancel * Update version + add changelog entry * Update test
1 parent f498da0 commit 0e5fd41

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
> - [ ] I have read and agree with the [Contribution Guidelines](https://github.com/shopify/checkout-sheet-kit-react-native/blob/main/.github/CONTRIBUTING.md).
1717
> - [ ] I have read and agree with the [Code of Conduct](https://github.com/shopify/checkout-sheet-kit-react-native/blob/main/.github/CODE_OF_CONDUCT.md).
1818
> - [ ] I've updated the [README](https://github.com/shopify/checkout-sheet-kit-react-native).
19-
> - [ ] I've updated any documentation related to these changes.
2019
2120
---
2221

@@ -27,5 +26,5 @@
2726
- [ ] I have added a [Changelog](./CHANGELOG.md) entry.
2827
</details>
2928

30-
> [!TIP]
29+
> [!TIP]
3130
> See the [Contributing documentation](https://github.com/shopify/checkout-sheet-kit-react-native/blob/main/.github/CONTRIBUTING.md#releasing-a-new-version) for instructions on how to publish a new version of the library.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.0.4 - March 4, 2024
4+
5+
- Fixes an issue where the parent view controller is dismissed after the
6+
checkout sheet is dismissed.
7+
38
## 1.0.3 - February 21, 2024
49

510
- Fixes an issue where the checkout can remain in a frozen empty state after

modules/@shopify/checkout-sheet-kit/ios/ShopifyCheckoutSheetKit.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import React
3030
class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
3131
private var hasListeners = false
3232

33+
internal var checkoutSheet: UIViewController?
34+
3335
override var methodQueue: DispatchQueue! {
3436
return DispatchQueue.main
3537
}
@@ -84,9 +86,7 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
8486
self.sendEvent(withName: "close", body: nil)
8587
}
8688

87-
if let viewController = UIApplication.shared.delegate?.window??.rootViewController {
88-
viewController.dismiss(animated: true)
89-
}
89+
self.checkoutSheet?.dismiss(animated: true)
9090
}
9191
}
9292

@@ -123,7 +123,9 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
123123
@objc func present(_ checkoutURL: String) {
124124
DispatchQueue.main.async {
125125
if let url = URL(string: checkoutURL), let viewController = self.getCurrentViewController() {
126-
ShopifyCheckoutSheetKit.present(checkout: url, from: viewController, delegate: self)
126+
let view = CheckoutViewController(checkout: url, delegate: self)
127+
viewController.present(view, animated: true)
128+
self.checkoutSheet = view
127129
}
128130
}
129131
}

modules/@shopify/checkout-sheet-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@shopify/checkout-sheet-kit",
33
"license": "MIT",
4-
"version": "1.0.3",
4+
"version": "1.0.4",
55
"main": "lib/commonjs/index.js",
66
"types": "src/index.ts",
77
"source": "src/index.ts",

sample/ios/ReactNativeTests/ShopifyCheckoutSheetKitTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,17 @@ class ShopifyCheckoutSheetKitTests: XCTestCase {
129129
}
130130
}
131131

132+
mock.checkoutSheet = MockCheckoutSheet()
132133
mock.startObserving()
133134
mock.checkoutDidCancel()
134135

135136
// Wait for the expectation to be fulfilled
136137
waitForExpectations(timeout: 1, handler: nil)
137138

138139
XCTAssertTrue(mock.didSendEvent)
140+
141+
// swiftlint:disable:next force_cast
142+
XCTAssertTrue((mock.checkoutSheet as! MockCheckoutSheet).dismissWasCalled)
139143
}
140144

141145
/// checkoutDidFail
@@ -269,3 +273,12 @@ class AsyncRCTShopifyCheckoutSheetKitMock: RCTShopifyCheckoutSheetKit {
269273
sendEventImplementation?(name, body)
270274
}
271275
}
276+
277+
class MockCheckoutSheet: UIViewController {
278+
var dismissWasCalled = false
279+
280+
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
281+
dismissWasCalled = true
282+
super.dismiss(animated: flag, completion: completion)
283+
}
284+
}

0 commit comments

Comments
 (0)