Skip to content

Commit

Permalink
fix: post merge
Browse files Browse the repository at this point in the history
  • Loading branch information
pklatka committed Apr 24, 2024
1 parent 66b3df4 commit f43e591
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.reactnativeturbowebview

import android.webkit.JavascriptInterface
import android.webkit.WebSettings
import android.webkit.WebView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Lifecycle
Expand All @@ -20,10 +21,10 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.json.JSONObject


class RNSession(
private val reactContext: ReactApplicationContext,
private val sessionHandle: String,
private val applicationNameForUserAgent: String?,
) : SessionCallbackAdapter {

var visitableView: SessionSubscriber? = null
Expand All @@ -36,6 +37,7 @@ class RNSession(
WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG)
webView.settings.setJavaScriptEnabled(true)
webView.addJavascriptInterface(JavaScriptInterface(), "AndroidInterface")
setUserAgentString(webView, applicationNameForUserAgent)
webView.webChromeClient = RNWebChromeClient(reactContext, this@RNSession)
session.isRunningInAndroidNavigation = false
session
Expand All @@ -47,6 +49,14 @@ class RNSession(
visitableView = newView
}

private fun setUserAgentString(webView: TurboWebView, applicationNameForUserAgent: String?) {
var userAgentString = WebSettings.getDefaultUserAgent(webView.context)
if (applicationNameForUserAgent != null) {
userAgentString = "$userAgentString $applicationNameForUserAgent"
}
webView.settings.userAgentString = userAgentString
}

fun visit(url: String, restoreWithCachedSnapshot: Boolean, reload: Boolean, viewTreeLifecycleOwner: LifecycleOwner?, visitOptions: TurboVisitOptions?){
val restore = restoreWithCachedSnapshot && !reload

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class RNSessionManager(reactContext: ReactApplicationContext) :
fun findOrCreateSession(
reactContext: ReactApplicationContext,
sessionHandle: String,
applicationNameForUserAgent: String? = null
): RNSession = sessions.getOrPut(sessionHandle) {
RNSession(reactContext, sessionHandle)
RNSession(reactContext, sessionHandle, applicationNameForUserAgent)
}

fun clearSnapshotCaches() {
Expand Down

0 comments on commit f43e591

Please sign in to comment.