Extract getViewportOffset out RootView

Summary:
This diff moves the method getViewportOffset out of ReactRootView. This is necessary to avoid Fabric to depend from paper.

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D26716901

fbshipit-source-id: cec67c24860a776fb361d7cda08d3142e1214c8c
This commit is contained in:
David Vacca authored and Facebook GitHub Bot committed 2021-03-01 17:55:16 -08:00
1 parent 21a434ceec
commit 05f687fa88
6 files changed
+24 -20

No files matched your search

@@ -7,8 +7,11 @@
package com.facebook.react.uimanager;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewParent;
import androidx.annotation.UiThread;
import com.facebook.infer.annotation.Assertions;
public class RootViewUtil {
@@ -28,4 +31,19 @@ public class RootViewUtil {
current = (View) next;
}
}
@UiThread
public static Point getViewportOffset(View v) {
int[] locationInWindow = new int[2];
v.getLocationInWindow(locationInWindow);
// we need to subtract visibleWindowCoords - to subtract possible window insets, split
// screen or multi window
Rect visibleWindowFrame = new Rect();
v.getWindowVisibleDisplayFrame(visibleWindowFrame);
locationInWindow[0] -= visibleWindowFrame.left;
locationInWindow[1] -= visibleWindowFrame.top;
return new Point(locationInWindow[0], locationInWindow[1]);
}
}