mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Breaking: Move ReactClippingViewGroup + Helper to uimanager package
Summary: This is to be able to depend on ReactClippingViewGroup from BaseViewManager. Devs using ReactClippingViewGroup may need to update their imports when updating past this commit. Reviewed By: lexs Differential Revision: D3835328 fbshipit-source-id: 290c08b130d837e553b68a90377bd9a30b7ec6dc
This commit is contained in:
1 parent
a4916b8c98
commit
e2cf37a5a6
8 files changed
+18
-25
No files matched your search
+61
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.react.uimanager;
|
||||
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.view.View;
|
||||
import android.view.ViewParent;
|
||||
|
||||
/**
|
||||
* Provides implementation of common tasks for view and it's view manager supporting property
|
||||
* {@code removeClippedSubviews}.
|
||||
*/
|
||||
@NotThreadSafe
|
||||
public class ReactClippingViewGroupHelper {
|
||||
|
||||
public static final String PROP_REMOVE_CLIPPED_SUBVIEWS = "removeClippedSubviews";
|
||||
|
||||
private static final Rect sHelperRect = new Rect();
|
||||
|
||||
/**
|
||||
* Can be used by view that support {@code removeClippedSubviews} property to calculate area that
|
||||
* given {@param view} should be clipped to based on the clipping rectangle of it's parent in
|
||||
* case when parent is also set to clip it's children.
|
||||
*
|
||||
* @param view view that we want to calculate clipping rect for
|
||||
* @param outputRect where the calculated rectangle will be written
|
||||
*/
|
||||
public static void calculateClippingRect(View view, Rect outputRect) {
|
||||
ViewParent parent = view.getParent();
|
||||
if (parent == null) {
|
||||
outputRect.setEmpty();
|
||||
return;
|
||||
} else if (parent instanceof ReactClippingViewGroup) {
|
||||
ReactClippingViewGroup clippingViewGroup = (ReactClippingViewGroup) parent;
|
||||
if (clippingViewGroup.getRemoveClippedSubviews()) {
|
||||
clippingViewGroup.getClippingRect(sHelperRect);
|
||||
// Intersect the view with the parent's rectangle
|
||||
// This will result in the overlap with coordinates in the parent space
|
||||
if (!sHelperRect.intersect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())) {
|
||||
outputRect.setEmpty();
|
||||
return;
|
||||
}
|
||||
// Now we move the coordinates to the View's coordinate space
|
||||
sHelperRect.offset(-view.getLeft(), -view.getTop());
|
||||
sHelperRect.offset(view.getScrollX(), view.getScrollY());
|
||||
outputRect.set(sHelperRect);
|
||||
return;
|
||||
}
|
||||
}
|
||||
view.getDrawingRect(outputRect);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user