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

Allow a destination's contents to be refreshed #138

Merged
merged 2 commits into from
Jan 30, 2021
Merged

Conversation

jayohms
Copy link
Collaborator

@jayohms jayohms commented Jan 30, 2021

To refresh a destination's contents, simply call refresh():

class WebFragment : TurboWebFragment() {

    // ...

    private fun respondToNativeFeature() {
        // Refresh the WebView contents
        refresh()

        // Or, refresh the contents without displaying progress
        refresh(displayProgress = false)
    }
}

To refresh the current destination from your Activity, use the delegate:

class MainActivity : AppCompatActivity(), TurboActivity {

    // ...

    private fun refreshAfterResumingApp() {
        delegate.currentNavDestination?.refresh()
    }
}

Addresses #137

@jayohms jayohms merged commit 828090e into main Jan 30, 2021
@jayohms jayohms deleted the destination-refresh branch January 30, 2021 12:30
ghiculescu added a commit to ghiculescu/turbo-android that referenced this pull request Feb 2, 2021
Small updates to hotwired#138

- Adds a `refresh` method on the `TurboActivityDelegate` so that you can call `delegate.refresh()` just like all other navigation methods.
- Adds `refresh` to the docs - https://github.com/hotwired/turbo-android/blob/main/docs/NAVIGATION.md
ghiculescu added a commit to ghiculescu/turbo-android that referenced this pull request Mar 6, 2021
The functionality added in hotwired#138 (as well as my workaround in hotwired#137) had a bug: if the webView has no URL loaded, calling `refresh` will result in a spinner appearing forever, and no requests being made to the server.

To replicate this:

- Add a call to `delegate.refresh()` in `onResume`
- Force close the app
- Open the app

Our real life example was that we had a call to `refresh()` in `onResume` that ran if the app had not been open for a while, to ensure fresh content. (Is there a better approach to this? How does Basecamp/Hey ensure fresh content on app load - either because the app was in memory in the background for a while or because Turbo/the Webview has cached the last screen?)

The fix is to not call `webView.reload()` if `webView.url` is null. Instead just load the URL as normal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant