Skip to content
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

Use correct origin point for calculating the absolute position on Android #2826

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.graphics.PointF
import android.graphics.Rect
import android.os.Build
import android.view.MotionEvent
import android.view.MotionEvent.PointerCoords
import android.view.MotionEvent.PointerProperties
import android.view.View
import android.view.Window
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.UiThreadUtil
import com.facebook.react.bridge.WritableArray
import com.facebook.react.uimanager.PixelUtil
Expand Down Expand Up @@ -176,12 +175,9 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
this.view = view
this.orchestrator = orchestrator

val decorView = getWindow(view?.context)?.decorView
if (decorView != null) {
val frame = Rect()
decorView.getWindowVisibleDisplayFrame(frame)
windowOffset[0] = frame.left
windowOffset[1] = frame.top
val content = getActivity(view?.context)?.findViewById<View>(android.R.id.content)
if (content != null) {
content.getLocationOnScreen(windowOffset)
} else {
windowOffset[0] = 0
windowOffset[1] = 0
Expand All @@ -192,10 +188,11 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu

protected open fun onPrepare() {}

private fun getWindow(context: Context?): Window? {
private fun getActivity(context: Context?): Activity? {
if (context == null) return null
if (context is Activity) return context.window
if (context is ContextWrapper) return getWindow(context.baseContext)
if (context is ReactContext) return context.currentActivity
if (context is Activity) return context
if (context is ContextWrapper) return getActivity(context.baseContext)
j-piasecki marked this conversation as resolved.
Show resolved Hide resolved

return null
}
Expand Down
Loading