From 60e856945e025d6a0276084e878f7b7672da67ed Mon Sep 17 00:00:00 2001 From: Dylan Ginsburg Date: Fri, 21 Jan 2022 11:16:06 -0500 Subject: [PATCH] Update iOS JavaScript shim to match changes made in the strada-web incorporate-stimulus branch --- Source/strada.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Source/strada.js b/Source/strada.js index d4b721f..7db0dc4 100644 --- a/Source/strada.js +++ b/Source/strada.js @@ -5,7 +5,7 @@ class NativeBridge { constructor() { this.supportedComponents = [] - document.addEventListener("web-bridge:ready", () => window.webBridge.setAdapter(this)) + document.addEventListener("web-bridge:ready", () => this.webBridge.setAdapter(this)) } register(component) { @@ -27,8 +27,8 @@ } notifyBridgeOfSupportedComponentsUpdate() { - if (window.webBridge) { - window.webBridge.adapterDidUpdateSupportedComponents() + if (this.isStradaAvailable) { + this.webBridge.adapterDidUpdateSupportedComponents() } } @@ -38,8 +38,8 @@ // Send message to web send(message) { - if (window.webBridge) { - window.webBridge.receive(message) + if (this.isStradaAvailable) { + this.webBridge.receive(message) } } @@ -57,6 +57,14 @@ postMessage(message) { webkit.messageHandlers.strada.postMessage(message) } + + get isStradaAvailable() { + return window.Strada + } + + get webBridge() { + return window.Strada.web + } } window.nativeBridge = new NativeBridge()