From 42caa8a566c9416fc9f956e346b6001b5d7b549a Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 1 Jul 2019 11:57:38 -0700 Subject: Support setting own child scroll callback --- .../main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt index 0ab11fc6..451f3948 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt @@ -24,11 +24,13 @@ class SwipeRefreshLayout @JvmOverloads constructor(context: Context, attrs: Attr private var downY: Float = -1f private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop + private var nestedCanChildScrollUp: OnChildScrollUpCallback? = null + /** * Copy of [canChildScrollUp], with additional support if necessary */ private val canChildScrollUp = OnChildScrollUpCallback { parent, child -> - when (child) { + nestedCanChildScrollUp?.canChildScrollUp(parent, child) ?: when (child) { is WebView -> child.canScrollVertically(-1).apply { L.d { "Webview can scroll up $this" } } @@ -42,6 +44,10 @@ class SwipeRefreshLayout @JvmOverloads constructor(context: Context, attrs: Attr setOnChildScrollUpCallback(canChildScrollUp) } + override fun setOnChildScrollUpCallback(callback: OnChildScrollUpCallback?) { + this.nestedCanChildScrollUp = callback + } + override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { if (ev.action != MotionEvent.ACTION_DOWN && preventRefresh) { return false -- cgit v1.2.3