Skip to content

Commit daa0a1c

Browse files
authored
Fix: Ensure the scrollbars are always restored (#6004)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1207418217763355/task/1210108991225075?focus=true ### Description This fixes a bug when the WebView scrollbars would stay hidden if the preview generation threw an exception. This may happen fairly often with tab swiping when you swipe between tabs fast so that the webview doesn't get a chance to get laid out. ### Steps to test this PR - [ ] Swipe tabs until you notice `Failed to generate WebView preview` in the logcat - [ ] Swipe back to the last tab - [ ] Notice the WebView has scrollbars when you scroll it
1 parent 9a4d594 commit daa0a1c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

app/src/main/java/com/duckduckgo/app/browser/tabpreview/WebViewPreviewGenerator.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ interface WebViewPreviewGenerator {
3333
class FileBasedWebViewPreviewGenerator(private val dispatchers: DispatcherProvider) : WebViewPreviewGenerator {
3434

3535
override suspend fun generatePreview(webView: WebView): Bitmap {
36-
disableScrollbars(webView)
37-
val fullSizeBitmap = createBitmap(webView)
36+
try {
37+
disableScrollbars(webView)
38+
val fullSizeBitmap = createBitmap(webView)
3839

39-
val scaledHeight = webView.context.resources.getDimension(R.dimen.gridItemPreviewHeight).toPx()
40-
val scaledWidth = scaledHeight / fullSizeBitmap.height * fullSizeBitmap.width
41-
val scaledBitmap = scaleBitmap(fullSizeBitmap, scaledHeight.roundToInt(), scaledWidth.roundToInt())
42-
enableScrollbars(webView)
43-
return scaledBitmap
40+
val scaledHeight = webView.context.resources.getDimension(R.dimen.gridItemPreviewHeight).toPx()
41+
val scaledWidth = scaledHeight / fullSizeBitmap.height * fullSizeBitmap.width
42+
return scaleBitmap(fullSizeBitmap, scaledHeight.roundToInt(), scaledWidth.roundToInt())
43+
} finally {
44+
enableScrollbars(webView)
45+
}
4446
}
4547

4648
@SuppressLint("AvoidComputationUsage")

0 commit comments

Comments
 (0)