From ec25f89c8f35731c16caabbb08c25a294cf29849 Mon Sep 17 00:00:00 2001 From: hublot Date: Mon, 5 Aug 2024 07:04:25 +0800 Subject: [PATCH] fix: gesture conflict on android --- .../widget/NestedScrollableFrameLayout.kt | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/so/onekey/app/wallet/widget/NestedScrollableFrameLayout.kt b/android/src/main/java/so/onekey/app/wallet/widget/NestedScrollableFrameLayout.kt index a908edb..49e373f 100644 --- a/android/src/main/java/so/onekey/app/wallet/widget/NestedScrollableFrameLayout.kt +++ b/android/src/main/java/so/onekey/app/wallet/widget/NestedScrollableFrameLayout.kt @@ -2,7 +2,40 @@ package so.onekey.app.wallet.widget import android.content.Context import android.util.AttributeSet +import android.view.MotionEvent import android.widget.FrameLayout +import com.facebook.react.uimanager.events.NativeGestureUtil + class NestedScrollableFrameLayout @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 -) : FrameLayout(context, attrs, defStyleAttr) \ No newline at end of file +) : FrameLayout(context, attrs, defStyleAttr) { + private var initialX = 0f + private var initialY = 0f + + override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { + when (ev.action) { + MotionEvent.ACTION_DOWN -> { + initialX = ev.x + initialY = ev.y + } + MotionEvent.ACTION_MOVE -> { + val diffX = ev.x - initialX + val diffY = ev.y - initialY + if (Math.abs(diffX) > Math.abs(diffY)) { + NativeGestureUtil.notifyNativeGestureStarted(this, ev); + } + } + } + return super.onInterceptTouchEvent(ev) + } + + override fun onTouchEvent(ev: MotionEvent): Boolean { + when (ev.action) { + MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { + NativeGestureUtil.notifyNativeGestureEnded(this, ev); + } + } + return super.onTouchEvent(ev); + } + +} \ No newline at end of file