Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically initialize the Bridge for each WebView instance #8

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/kotlin/dev/hotwire/core/bridge/Bridge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Bridge internal constructor(webView: WebView) {
companion object {
private val instances = mutableListOf<Bridge>()

fun initialize(webView: WebView) {
internal fun initialize(webView: WebView) {
if (getBridgeFor(webView) == null) {
initialize(Bridge(webView))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import dev.hotwire.core.bridge.Bridge
import dev.hotwire.core.config.Hotwire
import dev.hotwire.core.turbo.nav.TurboNavDestination
import dev.hotwire.core.turbo.nav.TurboNavGraphBuilder
Expand Down Expand Up @@ -55,6 +56,11 @@ abstract class TurboSessionNavHostFragment : NavHostFragment() {
*/
open fun onSessionCreated() {
session.pathConfiguration.load(Hotwire.config.pathConfigurationLocation)

// Initialize bridge with new WebView instance
if (Hotwire.registeredBridgeComponentFactories.isNotEmpty()) {
Bridge.initialize(session.webView)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.hotwire.demo.main

import dev.hotwire.core.bridge.Bridge
import dev.hotwire.core.turbo.session.TurboSessionNavHostFragment
import dev.hotwire.demo.util.HOME_URL
import dev.hotwire.demo.util.initDayNightTheme
Expand All @@ -16,8 +15,5 @@ class MainSessionNavHostFragment : TurboSessionNavHostFragment() {

// Configure WebView
session.webView.initDayNightTheme()

// Initialize Strada bridge with new WebView instance
Bridge.initialize(session.webView)
}
}