Skip to content

Commit 3ade24e

Browse files
authored
Ensure the webview content is always rendered when fragment is resumed (#5987)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1207418217763355/task/1209581454593298?focus=true ### Description This PR fixes an issue when the WebView content is not rendered in the browser. ### Steps to test this PR - [ ] Create 4 tabs and move to the 1st one - [ ] Restart the app to start fresh - [ ] Swipe to the 2nd, 3rd and 4th tab, one by one - [ ] Open the tab switcher and select the 1st tab - [ ] Notice the web content is correctly rendered - [ ] Repeat the previous 3 steps to make sure ### UI changes Before https://github.com/user-attachments/assets/c5a0fcf0-3ac9-446f-8a81-d61bf74fae4e After https://github.com/user-attachments/assets/ca0bc4e0-ec20-4304-b30c-5154c4b11e41
1 parent 41b3388 commit 3ade24e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,19 +891,31 @@ class BrowserTabFragment :
891891
Timber.d("Resuming webview: $tabId")
892892
webView?.let { webView ->
893893
if (webView.isShown) {
894+
webView.ensureVisible()
894895
webView.onResume()
895896
} else if (swipingTabsFeature.isEnabled) {
896-
// Sometimes the tab is brought back from the background but the WebView is not visible yet due to
897-
// ViewPager page change delay; this fixes an issue when a tab was blank.
897+
// Sometimes a tab is brought back from the background but the WebView is not shown yet due to
898+
// ViewPager page change delay; this makes sure the WebView is resumed when it is shown.
898899
webView.post {
899900
if (webView.isShown) {
901+
webView.ensureVisible()
900902
webView.onResume()
901903
}
902904
}
905+
} else {
906+
Timber.d("WebView is not shown, not resuming")
903907
}
904908
}
905909
}
906910

911+
// This is a hack to make sure the WebView content is always rendered when the fragment is resumed
912+
private fun DuckDuckGoWebView.ensureVisible() = postDelayed(100) {
913+
if (swipingTabsFeature.isEnabled) {
914+
scrollBy(0, 1)
915+
scrollBy(0, -1)
916+
}
917+
}
918+
907919
override fun onActivityCreated(savedInstanceState: Bundle?) {
908920
super.onActivityCreated(savedInstanceState)
909921
omnibar = Omnibar(settingsDataStore.omnibarPosition, visualDesignExperimentDataStore.getOmnibarType(), binding)

0 commit comments

Comments
 (0)