Skip to content

Fix: Ensure the scrollbars are always restored #6004

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

Merged
merged 2 commits into from
May 5, 2025

Conversation

0nko
Copy link
Member

@0nko 0nko commented May 2, 2025

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

@@ -33,13 +33,17 @@ interface WebViewPreviewGenerator {
class FileBasedWebViewPreviewGenerator(private val dispatchers: DispatcherProvider) : WebViewPreviewGenerator {

override suspend fun generatePreview(webView: WebView): Bitmap {
disableScrollbars(webView)
val fullSizeBitmap = createBitmap(webView)
val scaledBitmap: Bitmap
Copy link
Member

@CDRussell CDRussell May 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't think you need to have val scaledBitmap: Bitmap and return scaledBitmap separately; could just make it part of the return statement at the end of the try block. marginally easier to read IMO.

try {
    disableScrollbars(webView)
    val fullSizeBitmap = createBitmap(webView)

    val scaledHeight = webView.context.resources.getDimension(R.dimen.gridItemPreviewHeight).toPx()
    val scaledWidth = scaledHeight / fullSizeBitmap.height * fullSizeBitmap.width
    return scaleBitmap(fullSizeBitmap, scaledHeight.roundToInt(), scaledWidth.roundToInt())
} finally {
    enableScrollbars(webView)
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, thanks!

@0nko 0nko merged commit daa0a1c into develop May 5, 2025
6 checks passed
@0nko 0nko deleted the fix/ondrej/webview-scrollbars branch May 5, 2025 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants