Skip to content

Commit

Permalink
Update the adapter js to match the updated changes in strada-web
Browse files Browse the repository at this point in the history
  • Loading branch information
jayohms committed Apr 12, 2023
1 parent 310b393 commit df7efdd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
30 changes: 20 additions & 10 deletions strada/src/main/assets/js/strada.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
registerAdapter() {
this.adapterIsRegistered = true

if (window.webBridge) {
window.webBridge.setAdapter(this)
if (this.isStradaAvailable) {
this.webBridge.setAdapter(this)
} else {
document.addEventListener("web-bridge:ready", () => window.webBridge.setAdapter(this))
document.addEventListener("web-bridge:ready", () => this.webBridge.setAdapter(this))
}
}

notifyBridgeOfSupportedComponentsUpdate() {
this.supportedComponentsUpdated()

if (window.webBridge) {
window.webBridge.adapterDidUpdateSupportedComponents()
if (this.isStradaAvailable) {
this.webBridge.adapterDidUpdateSupportedComponents()
}
}

Expand All @@ -53,8 +53,8 @@

// Send message to web
send(message) {
if (window.webBridge) {
window.webBridge.receive(JSON.parse(message))
if (this.isStradaAvailable) {
this.webBridge.receive(JSON.parse(message))
}
}

Expand All @@ -70,15 +70,25 @@
// Native handler

ready() {
Strada.bridgeDidInitialize()
StradaNative.bridgeDidInitialize()
}

supportedComponentsUpdated() {
Strada.bridgeDidUpdateSupportedComponents()
StradaNative.bridgeDidUpdateSupportedComponents()
}

postMessage(message) {
Strada.bridgeDidReceiveMessage(message)
StradaNative.bridgeDidReceiveMessage(message)
}

// Web global

get isStradaAvailable() {
return window.Strada
}

get webBridge() {
return window.Strada.web
}
}

Expand Down
2 changes: 1 addition & 1 deletion strada/src/main/kotlin/dev/hotwire/strada/Bridge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.lang.ref.WeakReference

// These need to match whatever is set in strada.js
private const val bridgeGlobal = "window.nativeBridge"
private const val bridgeJavascriptInterface = "Strada"
private const val bridgeJavascriptInterface = "StradaNative"

@Suppress("unused")
class Bridge internal constructor(webView: WebView) {
Expand Down

0 comments on commit df7efdd

Please sign in to comment.