Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts.RequestMultiplePermissions
import androidx.activity.result.contract.ActivityResultContracts.RequestPermission
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
import androidx.core.view.ScrollingView
import androidx.lifecycle.Lifecycle.State.STARTED
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -231,6 +232,7 @@ internal class HotwireWebFragmentDelegate(

override fun visitRendered() {
callback.onVisitRendered(location)
resetWebViewScrollForScrollingContainer()
navDestination.fragmentViewModel.setTitle(title())
removeTransitionalViews()
}
Expand Down Expand Up @@ -474,6 +476,19 @@ internal class HotwireWebFragmentDelegate(
hotwireView?.webViewRefresh?.isEnabled = enabled
}

/**
* When the WebView moves into a ScrollingView container (e.g., bottom
* sheet), its native scroll state carries over from the previous page
* and gets applied to the ScrollingView. Normally Turbo's JS would
* scroll to the top, but this has no effect on a WRAP_CONTENT WebView
* inside a ScrollingView. Reset it natively instead.
*/
private fun resetWebViewScrollForScrollingContainer() {
if (webView.parent is ScrollingView) {
webView.scrollTo(0, 0)
}
}

private fun removeTransitionalViews() {
hotwireView?.webViewRefresh?.isRefreshing = false
hotwireView?.errorRefresh?.isRefreshing = false
Expand Down