From ceb4ba456315edca3a2bd5d97c242757ffdc09f7 Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Tue, 12 Jan 2021 15:16:33 -0500 Subject: [PATCH 1/2] Fix crash while using an S-Pen to navigate within the WebView. This prevents the ViewGroup's dispatched hover events from trying to determine a custom order of its children when the WebView is being removed (there's no custom order anyway). --- .../turbo/views/TurboSwipeRefreshLayout.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/views/TurboSwipeRefreshLayout.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/views/TurboSwipeRefreshLayout.kt index febb3bfc..87620261 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/views/TurboSwipeRefreshLayout.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/views/TurboSwipeRefreshLayout.kt @@ -2,15 +2,31 @@ package dev.hotwire.turbo.views import android.content.Context import android.util.AttributeSet +import android.view.MotionEvent import android.webkit.WebView import androidx.core.view.children import androidx.swiperefreshlayout.widget.SwipeRefreshLayout +import dev.hotwire.turbo.util.TurboLog internal class TurboSwipeRefreshLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : SwipeRefreshLayout(context, attrs) { + init { + disableCustomDrawingOrder() + } + override fun canChildScrollUp(): Boolean { val webView = children.firstOrNull() as? WebView return webView?.scrollY ?: 0 > 0 } + + /** + * Disable custom child drawing order. This fixes a crash while using a + * stylus that dispatches hover events when the WebView is being removed. + * This doesn't have any unintended consequences, since the WebView is the + * only possible child of this view. + */ + private fun disableCustomDrawingOrder() { + isChildrenDrawingOrderEnabled = false + } } From 009dd6c81ffd875eb10863ef10b82a843223fe03 Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Tue, 12 Jan 2021 15:28:18 -0500 Subject: [PATCH 2/2] Remove unused imports --- .../kotlin/dev/hotwire/turbo/views/TurboSwipeRefreshLayout.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/views/TurboSwipeRefreshLayout.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/views/TurboSwipeRefreshLayout.kt index 87620261..38ff5bad 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/views/TurboSwipeRefreshLayout.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/views/TurboSwipeRefreshLayout.kt @@ -2,11 +2,9 @@ package dev.hotwire.turbo.views import android.content.Context import android.util.AttributeSet -import android.view.MotionEvent import android.webkit.WebView import androidx.core.view.children import androidx.swiperefreshlayout.widget.SwipeRefreshLayout -import dev.hotwire.turbo.util.TurboLog internal class TurboSwipeRefreshLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : SwipeRefreshLayout(context, attrs) {