Skip to content

Commit

Permalink
Change logic of refresh method (#172)
Browse files Browse the repository at this point in the history
Co-authored-by: Mattias Pfeiffer <[email protected]>
  • Loading branch information
pklatka and pfeiffer authored Mar 27, 2024
1 parent 5495d1e commit 2cda1ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions packages/turbo/ios/RNVisitableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 2cda1ed

Please sign in to comment.