diff --git a/packages/turbo/android/src/main/java/com/reactnativeturbowebview/RNVisitableView.kt b/packages/turbo/android/src/main/java/com/reactnativeturbowebview/RNVisitableView.kt index 183fcf14..8c2bed42 100644 --- a/packages/turbo/android/src/main/java/com/reactnativeturbowebview/RNVisitableView.kt +++ b/packages/turbo/android/src/main/java/com/reactnativeturbowebview/RNVisitableView.kt @@ -23,6 +23,10 @@ import dev.hotwire.turbo.errors.WebError import dev.hotwire.turbo.errors.WebSslError import dev.hotwire.turbo.visit.TurboVisitAction +const val REFRESH_SCRIPT = "typeof Turbo.session.refresh === 'function'" + + "? Turbo.session.refresh(document.baseURI)" + // Turbo 8+ + ": Turbo.visit(document.baseURI, { action: 'replace', shouldCacheSnapshot: 'false' })" // Older Turbo versions + class RNVisitableView(context: Context) : LinearLayout(context), SessionSubscriber { private val reactContext = context as ReactApplicationContext @@ -117,13 +121,7 @@ class RNVisitableView(context: Context) : LinearLayout(context), SessionSubscrib } override fun refresh() { - session.visit( - url = url, - restoreWithCachedSnapshot = false, - reload = false, - viewTreeLifecycleOwner = viewTreeLifecycleOwner, - visitOptions = TurboVisitOptions(action = TurboVisitAction.REPLACE) - ) + webView.evaluateJavascript(REFRESH_SCRIPT, null) } override fun reload(displayProgress: Boolean) { diff --git a/packages/turbo/ios/RNVisitableView.swift b/packages/turbo/ios/RNVisitableView.swift index 0e9697de..b985c8fe 100644 --- a/packages/turbo/ios/RNVisitableView.swift +++ b/packages/turbo/ios/RNVisitableView.swift @@ -7,6 +7,10 @@ import UIKit +let REFRESH_SCRIPT = "typeof Turbo.session.refresh === 'function'" + + "? Turbo.session.refresh(document.baseURI)" + // Turbo 8+ + ": Turbo.visit(document.baseURI, { action: 'replace', shouldCacheSnapshot: 'false' })" // Older Turbo versions + class RNVisitableView: UIView, RNSessionSubscriber { var id: UUID = UUID() @objc var sessionHandle: NSString? = nil @@ -120,10 +124,7 @@ class RNVisitableView: UIView, RNSessionSubscriber { } public func refresh() { - if (controller == nil) { - return - } - session.visit(controller!, action: .replace) + webView.evaluateJavaScript(REFRESH_SCRIPT) } private func visit() {