diff --git a/core/src/main/assets/js/strada.js b/core/src/main/assets/js/bridge_components.js similarity index 87% rename from core/src/main/assets/js/strada.js rename to core/src/main/assets/js/bridge_components.js index ec7ae12..c260b7e 100644 --- a/core/src/main/assets/js/strada.js +++ b/core/src/main/assets/js/bridge_components.js @@ -32,7 +32,7 @@ registerAdapter() { this.adapterIsRegistered = true - if (this.isStradaAvailable) { + if (this.isBridgeAvailable) { this.webBridge.setAdapter(this) } else { document.addEventListener("web-bridge:ready", () => this.webBridge.setAdapter(this)) @@ -42,7 +42,7 @@ notifyBridgeOfSupportedComponentsUpdate() { this.supportedComponentsUpdated() - if (this.isStradaAvailable) { + if (this.isBridgeAvailable) { this.webBridge.adapterDidUpdateSupportedComponents() } } @@ -53,7 +53,7 @@ // Reply to web with message replyWith(message) { - if (this.isStradaAvailable) { + if (this.isBridgeAvailable) { this.webBridge.receive(JSON.parse(message)) } } @@ -70,20 +70,20 @@ // Native handler ready() { - StradaNative.bridgeDidInitialize() + BridgeComponentsNative.bridgeDidInitialize() } supportedComponentsUpdated() { - StradaNative.bridgeDidUpdateSupportedComponents() + BridgeComponentsNative.bridgeDidUpdateSupportedComponents() } postMessage(message) { - StradaNative.bridgeDidReceiveMessage(message) + BridgeComponentsNative.bridgeDidReceiveMessage(message) } // Web global - get isStradaAvailable() { + get isBridgeAvailable() { return window.Strada } diff --git a/core/src/main/assets/js/turbo_bridge.js b/core/src/main/assets/js/turbo.js similarity index 100% rename from core/src/main/assets/js/turbo_bridge.js rename to core/src/main/assets/js/turbo.js diff --git a/core/src/main/kotlin/dev/hotwire/core/bridge/Bridge.kt b/core/src/main/kotlin/dev/hotwire/core/bridge/Bridge.kt index cd1ee92..0132a5a 100644 --- a/core/src/main/kotlin/dev/hotwire/core/bridge/Bridge.kt +++ b/core/src/main/kotlin/dev/hotwire/core/bridge/Bridge.kt @@ -7,9 +7,9 @@ import dev.hotwire.core.logging.logEvent import kotlinx.serialization.json.JsonElement import java.lang.ref.WeakReference -// These need to match whatever is set in strada.js +// These need to match whatever is set in bridge_components.js private const val bridgeGlobal = "window.nativeBridge" -private const val bridgeJavascriptInterface = "StradaNative" +private const val bridgeJavascriptInterface = "BridgeComponentsNative" @Suppress("unused") class Bridge internal constructor(webView: WebView) { diff --git a/core/src/main/kotlin/dev/hotwire/core/bridge/BridgeComponent.kt b/core/src/main/kotlin/dev/hotwire/core/bridge/BridgeComponent.kt index 8eadf87..5909d86 100644 --- a/core/src/main/kotlin/dev/hotwire/core/bridge/BridgeComponent.kt +++ b/core/src/main/kotlin/dev/hotwire/core/bridge/BridgeComponent.kt @@ -116,7 +116,7 @@ abstract class BridgeComponent( * reply will be ignored. */ inline fun replyTo(event: String, data: T): Boolean { - return replyTo(event, jsonData = StradaJsonConverter.toJson(data)) + return replyTo(event, jsonData = BridgeComponentJsonConverter.toJson(data)) } private fun reply(message: Message): Boolean { diff --git a/core/src/main/kotlin/dev/hotwire/core/bridge/StradaJsonConverter.kt b/core/src/main/kotlin/dev/hotwire/core/bridge/BridgeComponentJsonConverter.kt similarity index 74% rename from core/src/main/kotlin/dev/hotwire/core/bridge/StradaJsonConverter.kt rename to core/src/main/kotlin/dev/hotwire/core/bridge/BridgeComponentJsonConverter.kt index 77cbec9..55da3da 100644 --- a/core/src/main/kotlin/dev/hotwire/core/bridge/StradaJsonConverter.kt +++ b/core/src/main/kotlin/dev/hotwire/core/bridge/BridgeComponentJsonConverter.kt @@ -5,13 +5,13 @@ import dev.hotwire.core.logging.logError import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json -abstract class StradaJsonConverter { +abstract class BridgeComponentJsonConverter { companion object { const val NO_CONVERTER = - "A Strada.config.jsonConverter must be set to encode or decode json" + "A Hotwire.config.jsonConverter must be set to encode or decode json" const val INVALID_CONVERTER = - "The configured json converter must implement a StradaJsonTypeConverter " + + "The configured json converter must implement a BridgeComponentJsonTypeConverter " + "or use the provided KotlinXJsonConverter." inline fun toObject(jsonData: String): T? { @@ -19,7 +19,7 @@ abstract class StradaJsonConverter { return when (converter) { is KotlinXJsonConverter -> converter.toObject(jsonData) - is StradaJsonTypeConverter -> converter.toObject(jsonData, T::class.java) + is BridgeComponentJsonTypeConverter -> converter.toObject(jsonData, T::class.java) else -> throw IllegalStateException(INVALID_CONVERTER) } } @@ -29,19 +29,19 @@ abstract class StradaJsonConverter { return when (converter) { is KotlinXJsonConverter -> converter.toJson(data) - is StradaJsonTypeConverter -> converter.toJson(data, T::class.java) + is BridgeComponentJsonTypeConverter -> converter.toJson(data, T::class.java) else -> throw IllegalStateException(INVALID_CONVERTER) } } } } -abstract class StradaJsonTypeConverter : StradaJsonConverter() { +abstract class BridgeComponentJsonTypeConverter : BridgeComponentJsonConverter() { abstract fun toObject(jsonData: String, type: Class): T? abstract fun toJson(data: T, type: Class): String } -class KotlinXJsonConverter : StradaJsonConverter() { +class KotlinXJsonConverter : BridgeComponentJsonConverter() { val json = Json { ignoreUnknownKeys = true } inline fun toObject(jsonData: String): T? { diff --git a/core/src/main/kotlin/dev/hotwire/core/bridge/Message.kt b/core/src/main/kotlin/dev/hotwire/core/bridge/Message.kt index dba1fda..4e8e00d 100644 --- a/core/src/main/kotlin/dev/hotwire/core/bridge/Message.kt +++ b/core/src/main/kotlin/dev/hotwire/core/bridge/Message.kt @@ -48,11 +48,11 @@ data class Message constructor( event: String = this.event, data: T ): Message { - return replacing(event, StradaJsonConverter.toJson(data)) + return replacing(event, BridgeComponentJsonConverter.toJson(data)) } inline fun data(): T? { - return StradaJsonConverter.toObject(jsonData) + return BridgeComponentJsonConverter.toObject(jsonData) } } diff --git a/core/src/main/kotlin/dev/hotwire/core/bridge/Repository.kt b/core/src/main/kotlin/dev/hotwire/core/bridge/Repository.kt index 768a1a4..34cc9ed 100644 --- a/core/src/main/kotlin/dev/hotwire/core/bridge/Repository.kt +++ b/core/src/main/kotlin/dev/hotwire/core/bridge/Repository.kt @@ -4,7 +4,7 @@ import android.content.Context internal class Repository { fun getUserScript(context: Context): String { - return context.assets.open("js/strada.js").use { + return context.assets.open("js/bridge_components.js").use { String(it.readBytes()) } } diff --git a/core/src/main/kotlin/dev/hotwire/core/config/HotwireConfig.kt b/core/src/main/kotlin/dev/hotwire/core/config/HotwireConfig.kt index a5b3f4b..1e44fd1 100644 --- a/core/src/main/kotlin/dev/hotwire/core/config/HotwireConfig.kt +++ b/core/src/main/kotlin/dev/hotwire/core/config/HotwireConfig.kt @@ -4,7 +4,7 @@ import android.content.Context import android.webkit.WebView import dev.hotwire.core.bridge.BridgeComponent import dev.hotwire.core.bridge.BridgeComponentFactory -import dev.hotwire.core.bridge.StradaJsonConverter +import dev.hotwire.core.bridge.BridgeComponentJsonConverter import dev.hotwire.core.turbo.config.PathConfiguration import dev.hotwire.core.turbo.http.HotwireHttpClient import dev.hotwire.core.turbo.offline.OfflineRequestHandler @@ -24,7 +24,7 @@ class HotwireConfig internal constructor() { * object in received messages and to encode a data object back to json to * reply with a custom message back to the web. */ - var jsonConverter: StradaJsonConverter? = null + var jsonConverter: BridgeComponentJsonConverter? = null /** * Experimental: API may be removed, not ready for production use. diff --git a/core/src/main/kotlin/dev/hotwire/core/turbo/webview/HotwireWebView.kt b/core/src/main/kotlin/dev/hotwire/core/turbo/webview/HotwireWebView.kt index b43fbc7..f2fc03f 100644 --- a/core/src/main/kotlin/dev/hotwire/core/turbo/webview/HotwireWebView.kt +++ b/core/src/main/kotlin/dev/hotwire/core/turbo/webview/HotwireWebView.kt @@ -74,7 +74,7 @@ open class HotwireWebView @JvmOverloads constructor( internal fun installBridge(onBridgeInstalled: () -> Unit) { val script = "window.turboNative == null" - val bridge = context.contentFromAsset("js/turbo_bridge.js") + val bridge = context.contentFromAsset("js/turbo.js") runJavascript(script) { s -> if (s?.toBoolean() == true) { diff --git a/core/src/test/kotlin/dev/hotwire/core/bridge/BridgeComponentTest.kt b/core/src/test/kotlin/dev/hotwire/core/bridge/BridgeComponentTest.kt index a9d80f4..d9029ff 100644 --- a/core/src/test/kotlin/dev/hotwire/core/bridge/BridgeComponentTest.kt +++ b/core/src/test/kotlin/dev/hotwire/core/bridge/BridgeComponentTest.kt @@ -110,7 +110,7 @@ class BridgeComponentTest { assertThatThrownBy { component.replyTo("connect", MessageData(title = "Page-title")) } .isInstanceOf(IllegalArgumentException::class.java) - .hasMessage(StradaJsonConverter.NO_CONVERTER) + .hasMessage(BridgeComponentJsonConverter.NO_CONVERTER) } @Test diff --git a/core/src/test/kotlin/dev/hotwire/core/bridge/MessageTest.kt b/core/src/test/kotlin/dev/hotwire/core/bridge/MessageTest.kt index 9c9feb5..dc9d6a1 100644 --- a/core/src/test/kotlin/dev/hotwire/core/bridge/MessageTest.kt +++ b/core/src/test/kotlin/dev/hotwire/core/bridge/MessageTest.kt @@ -112,7 +112,7 @@ class MessageTest { assertThatThrownBy { message.replacing(data = data) } .isInstanceOf(IllegalArgumentException::class.java) - .hasMessage(StradaJsonConverter.NO_CONVERTER) + .hasMessage(BridgeComponentJsonConverter.NO_CONVERTER) } @Test @@ -131,7 +131,7 @@ class MessageTest { assertThatThrownBy { message.replacing(data = data) } .isInstanceOf(IllegalStateException::class.java) - .hasMessage(StradaJsonConverter.INVALID_CONVERTER) + .hasMessage(BridgeComponentJsonConverter.INVALID_CONVERTER) } @Serializable @@ -139,5 +139,5 @@ class MessageTest { private class InvalidMessageData() - private class InvalidJsonConverter : StradaJsonConverter() + private class InvalidJsonConverter : BridgeComponentJsonConverter() } diff --git a/demo/src/main/assets/json/configuration.json b/demo/src/main/assets/json/configuration.json index b1bb752..336600c 100644 --- a/demo/src/main/assets/json/configuration.json +++ b/demo/src/main/assets/json/configuration.json @@ -25,7 +25,7 @@ { "patterns": [ "/signin$", - "/strada-form$" + "/bridge-form$" ], "properties": { "context": "modal",