|
7 | 7 | package com.facebook.react.uimanager;
|
8 | 8 |
|
9 | 9 | import android.content.res.Resources;
|
| 10 | +import android.graphics.Matrix; |
| 11 | +import android.graphics.RectF; |
10 | 12 | import android.util.SparseArray;
|
11 | 13 | import android.util.SparseBooleanArray;
|
12 | 14 | import android.util.SparseIntArray;
|
@@ -74,6 +76,7 @@ public class NativeViewHierarchyManager {
|
74 | 76 | private final LayoutAnimationController mLayoutAnimator = new LayoutAnimationController();
|
75 | 77 | private final SparseArray<SparseIntArray> mTagsToPendingIndicesToDelete = new SparseArray<>();
|
76 | 78 | private final int[] mDroppedViewArray = new int[100];
|
| 79 | + private final RectF mBoundingBox = new RectF(); |
77 | 80 |
|
78 | 81 | private boolean mLayoutAnimationEnabled;
|
79 | 82 | private PopupMenu mPopupMenu;
|
@@ -649,16 +652,47 @@ public synchronized void measure(int tag, int[] outputBuffer) {
|
649 | 652 | if (rootView == null) {
|
650 | 653 | throw new NoSuchNativeViewException("Native view " + tag + " is no longer on screen");
|
651 | 654 | }
|
652 |
| - rootView.getLocationInWindow(outputBuffer); |
| 655 | + computeBoundingBox(rootView, outputBuffer); |
653 | 656 | int rootX = outputBuffer[0];
|
654 | 657 | int rootY = outputBuffer[1];
|
| 658 | + computeBoundingBox(v, outputBuffer); |
| 659 | + outputBuffer[0] -= rootX; |
| 660 | + outputBuffer[1] -= rootY; |
| 661 | + } |
655 | 662 |
|
656 |
| - v.getLocationInWindow(outputBuffer); |
| 663 | + private void computeBoundingBox(View view, int[] outputBuffer) { |
| 664 | + mBoundingBox.set(0, 0, view.getWidth(), view.getHeight()); |
| 665 | + mapRectFromViewToWindowCoords(view, mBoundingBox); |
657 | 666 |
|
658 |
| - outputBuffer[0] = outputBuffer[0] - rootX; |
659 |
| - outputBuffer[1] = outputBuffer[1] - rootY; |
660 |
| - outputBuffer[2] = v.getWidth(); |
661 |
| - outputBuffer[3] = v.getHeight(); |
| 667 | + outputBuffer[0] = Math.round(mBoundingBox.left); |
| 668 | + outputBuffer[1] = Math.round(mBoundingBox.top); |
| 669 | + outputBuffer[2] = Math.round(mBoundingBox.right - mBoundingBox.left); |
| 670 | + outputBuffer[3] = Math.round(mBoundingBox.bottom - mBoundingBox.top); |
| 671 | + } |
| 672 | + |
| 673 | + private void mapRectFromViewToWindowCoords(View view, RectF rect) { |
| 674 | + Matrix matrix = view.getMatrix(); |
| 675 | + if (!matrix.isIdentity()) { |
| 676 | + matrix.mapRect(rect); |
| 677 | + } |
| 678 | + |
| 679 | + rect.offset(view.getLeft(), view.getTop()); |
| 680 | + |
| 681 | + ViewParent parent = view.getParent(); |
| 682 | + while (parent instanceof View) { |
| 683 | + View parentView = (View) parent; |
| 684 | + |
| 685 | + rect.offset(-parentView.getScrollX(), -parentView.getScrollY()); |
| 686 | + |
| 687 | + matrix = parentView.getMatrix(); |
| 688 | + if (!matrix.isIdentity()) { |
| 689 | + matrix.mapRect(rect); |
| 690 | + } |
| 691 | + |
| 692 | + rect.offset(parentView.getLeft(), parentView.getTop()); |
| 693 | + |
| 694 | + parent = parentView.getParent(); |
| 695 | + } |
662 | 696 | }
|
663 | 697 |
|
664 | 698 | /**
|
|
0 commit comments