-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support removeClippedSubviews for horizontal ScrollViews
Summary: Currently, horizontal `ScrollViews` don't properly support `removeClippedSubviews`. This is because the container view, `ReactHorizontalScrollContainerView` extends from regular `ViewGroup` instead of `ReactViewGroup` so doesn't have all the logic around clipping children. Moreover, the `ReactHorizontalScrollContainerViewManager` doesn't actually support the `removeClippedSubviews` prop This change: - Makes `ReactHorizontalScrollContainerView` extend from `ReactViewGroup` while maintaining the special logic around RTL scrolling - Factors out a common `ReactClippingViewManager` which will be used to bridge all components which extend `ReactViewGroup` and support clipping. It has the logic for adding/removing children and getting child counts while considering clipped subviews - `ReactViewManager` now extends this new `ReactClippingViewManager` - `ReactHorizontalScrollContainerViewManager` also extends `ReactClippingViewManager` Reviewed By: JoshuaGross Differential Revision: D17708630 fbshipit-source-id: d257566ee54ad46f6d62f176a657c596bba96aa4
- Loading branch information
1 parent
21f1cce
commit 42152a3
Showing
4 changed files
with
83 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
ReactAndroid/src/main/java/com/facebook/react/views/view/ReactClippingViewManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. | ||
|
||
// This source code is licensed under the MIT license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
|
||
package com.facebook.react.views.view; | ||
|
||
import android.view.View; | ||
import com.facebook.react.uimanager.ViewGroupManager; | ||
import com.facebook.react.uimanager.annotations.ReactProp; | ||
|
||
/** | ||
* View manager which handles clipped subviews. Useful for custom views which extends from {@link | ||
* com.facebook.react.views.view.ReactViewGroup} | ||
*/ | ||
public abstract class ReactClippingViewManager<T extends ReactViewGroup> | ||
extends ViewGroupManager<T> { | ||
|
||
@ReactProp( | ||
name = com.facebook.react.uimanager.ReactClippingViewGroupHelper.PROP_REMOVE_CLIPPED_SUBVIEWS) | ||
public void setRemoveClippedSubviews(T view, boolean removeClippedSubviews) { | ||
view.setRemoveClippedSubviews(removeClippedSubviews); | ||
} | ||
|
||
@Override | ||
public void addView(T parent, View child, int index) { | ||
boolean removeClippedSubviews = parent.getRemoveClippedSubviews(); | ||
if (removeClippedSubviews) { | ||
parent.addViewWithSubviewClippingEnabled(child, index); | ||
} else { | ||
parent.addView(child, index); | ||
} | ||
} | ||
|
||
@Override | ||
public int getChildCount(T parent) { | ||
boolean removeClippedSubviews = parent.getRemoveClippedSubviews(); | ||
if (removeClippedSubviews) { | ||
return parent.getAllChildrenCount(); | ||
} else { | ||
return parent.getChildCount(); | ||
} | ||
} | ||
|
||
@Override | ||
public View getChildAt(T parent, int index) { | ||
boolean removeClippedSubviews = parent.getRemoveClippedSubviews(); | ||
if (removeClippedSubviews) { | ||
return parent.getChildAtWithSubviewClippingEnabled(index); | ||
} else { | ||
return parent.getChildAt(index); | ||
} | ||
} | ||
|
||
@Override | ||
public void removeViewAt(T parent, int index) { | ||
boolean removeClippedSubviews = parent.getRemoveClippedSubviews(); | ||
if (removeClippedSubviews) { | ||
View child = getChildAt(parent, index); | ||
if (child.getParent() != null) { | ||
parent.removeView(child); | ||
} | ||
parent.removeViewWithSubviewClippingEnabled(child); | ||
} else { | ||
parent.removeViewAt(index); | ||
} | ||
} | ||
|
||
@Override | ||
public void removeAllViews(T parent) { | ||
boolean removeClippedSubviews = parent.getRemoveClippedSubviews(); | ||
if (removeClippedSubviews) { | ||
parent.removeAllViewsWithSubviewClippingEnabled(); | ||
} else { | ||
parent.removeAllViews(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters