Skip to content

Commit

Permalink
parse visible property from event and use that to hide/show nav bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kiftio committed Oct 20, 2023
1 parent 30b0082 commit 261a85e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Sources/ShopifyCheckout/CheckoutBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extension CheckoutBridge {
case checkoutCanceled
case checkoutExpired
case checkoutUnavailable
case checkoutModalToggled
case checkoutModalToggled(modalVisible: Bool)
case unsupported(String)

enum CodingKeys: String, CodingKey {
Expand All @@ -80,7 +80,8 @@ extension CheckoutBridge {
// needs to support .checkoutUnavailable by parsing error payload on body
self = .checkoutExpired
case "checkoutBlockingEvent":
self = .checkoutModalToggled
let modalVisible = try container.decode(String.self, forKey: .body)
self = .checkoutModalToggled(modalVisible: Bool(modalVisible)!)
default:
self = .unsupported(name)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/ShopifyCheckout/CheckoutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protocol CheckoutViewDelegate: AnyObject {
func checkoutViewDidFinishNavigation()
func checkoutViewDidClickLink(url: URL)
func checkoutViewDidFailWithError(error: CheckoutError)
func checkoutViewDidToggleModal()
func checkoutViewDidToggleModal(modalVisible: Bool)
}

class CheckoutView: WKWebView {
Expand Down Expand Up @@ -105,8 +105,8 @@ extension CheckoutView: WKScriptMessageHandler {
case .checkoutUnavailable:
CheckoutView.cache = nil
viewDelegate?.checkoutViewDidFailWithError(error: .checkoutUnavailable(message: "Checkout unavailable."))
case .checkoutModalToggled:
viewDelegate?.checkoutViewDidToggleModal()
case let .checkoutModalToggled(modalVisible):
viewDelegate?.checkoutViewDidToggleModal(modalVisible: modalVisible)
default:
()
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/ShopifyCheckout/CheckoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ extension CheckoutViewController: CheckoutViewDelegate {
delegate?.checkoutDidClickLink(url: url)
}

func checkoutViewDidToggleModal() {
let hide = !self.navigationController!.isNavigationBarHidden
self.navigationController?.setNavigationBarHidden(hide, animated: true)
func checkoutViewDidToggleModal(modalVisible: Bool) {
guard let navigationController = self.navigationController else { return }
navigationController.setNavigationBarHidden(modalVisible, animated: true)
}
}
4 changes: 2 additions & 2 deletions Tests/ShopifyCheckoutTests/CheckoutViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ class CheckoutViewDelegateTests: XCTestCase {
func testCheckoutViewDidToggleModalAddsAndRemovesNavigationBar() {
XCTAssertFalse(viewController.navigationController!.isNavigationBarHidden)

viewController.checkoutViewDidToggleModal()
viewController.checkoutViewDidToggleModal(modalVisible: true)
XCTAssertTrue(viewController.navigationController!.isNavigationBarHidden)

viewController.checkoutViewDidToggleModal()
viewController.checkoutViewDidToggleModal(modalVisible: false)
XCTAssertFalse(viewController.navigationController!.isNavigationBarHidden)
}
}

0 comments on commit 261a85e

Please sign in to comment.