Skip to content

Commit

Permalink
fix: gesture conflict on android
Browse files Browse the repository at this point in the history
  • Loading branch information
hellohublot committed Aug 4, 2024
1 parent d09c490 commit ec25f89
Showing 1 changed file with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) : 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);
}

}

0 comments on commit ec25f89

Please sign in to comment.