Skip to content

Commit

Permalink
invalidate checkout view on swipe down (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiftio authored Oct 19, 2023
1 parent f43dc47 commit e3d8e5b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion Sources/ShopifyCheckout/CheckoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO
import UIKit
import WebKit

class CheckoutViewController: UIViewController {
class CheckoutViewController: UIViewController, UIAdaptivePresentationControllerDelegate {

// MARK: Properties

Expand Down Expand Up @@ -106,6 +106,14 @@ class CheckoutViewController: UIViewController {
}

@IBAction internal func close() {
didCancel()
}

internal func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
didCancel()
}

private func didCancel() {
CheckoutView.invalidate()
delegate?.checkoutDidCancel()
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/ShopifyCheckout/ShopifyCheckout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public func preload(checkout url: URL) {

/// Presents the checkout from a given `UIViewController`.
public func present(checkout url: URL, from: UIViewController, delegate: CheckoutDelegate? = nil) {
let viewController = UINavigationController(
rootViewController: CheckoutViewController(checkoutURL: url, delegate: delegate)
)
let rootViewController = CheckoutViewController(checkoutURL: url, delegate: delegate)
let viewController = UINavigationController(rootViewController: rootViewController)
viewController.presentationController?.delegate = rootViewController
from.present(viewController, animated: true)
}
12 changes: 12 additions & 0 deletions Tests/ShopifyCheckoutTests/CheckoutViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ class CheckoutViewDelegateTests: XCTestCase {
XCTAssertNotEqual(two, three)
}

func testPresentationControllerDidDismissInvalidatesViewCache() {
let one = CheckoutView.for(checkout: checkoutURL)
let two = CheckoutView.for(checkout: checkoutURL)
XCTAssertEqual(one, two)

let presentationController = UIViewController().presentationController!
viewController.presentationControllerDidDismiss(presentationController)

let three = CheckoutView.for(checkout: checkoutURL)
XCTAssertNotEqual(two, three)
}

func testCheckoutViewDidClickLinkDoesNotInvalidateViewCache() {
let one = CheckoutView.for(checkout: checkoutURL)
let two = CheckoutView.for(checkout: checkoutURL)
Expand Down

0 comments on commit e3d8e5b

Please sign in to comment.