mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support ScrollAway in ReactScrollView
Summary: Support ScrollAway in ReactScrollView for Fabric/non-Fabric. Changelog: [Android][Added] Support for ScrollAway native nav bars added to ReactScrollView Reviewed By: mdvacca Differential Revision: D28308855 fbshipit-source-id: 9a922159ef50fb7c8e9c484a4b97ca57ab248496
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d87542ee4c
commit
0ef5beee85
+5
-1
@@ -43,12 +43,16 @@ public class ReactClippingViewGroupHelper {
|
||||
// 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())) {
|
||||
view.getLeft(),
|
||||
view.getTop() + (int) view.getTranslationY(),
|
||||
view.getRight(),
|
||||
view.getBottom() + (int) view.getTranslationY())) {
|
||||
outputRect.setEmpty();
|
||||
return;
|
||||
}
|
||||
// Now we move the coordinates to the View's coordinate space
|
||||
sHelperRect.offset(-view.getLeft(), -view.getTop());
|
||||
sHelperRect.offset(-(int) view.getTranslationX(), -(int) view.getTranslationY());
|
||||
sHelperRect.offset(view.getScrollX(), view.getScrollY());
|
||||
outputRect.set(sHelperRect);
|
||||
return;
|
||||
|
||||
+2
@@ -60,6 +60,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
private static boolean sTriedToGetScrollerField = false;
|
||||
private static final String CONTENT_OFFSET_LEFT = "contentOffsetLeft";
|
||||
private static final String CONTENT_OFFSET_TOP = "contentOffsetTop";
|
||||
private static final String SCROLL_AWAY_PADDING_TOP = "scrollAwayPaddingTop";
|
||||
private int mLayoutDirection;
|
||||
|
||||
private int mScrollXAfterMeasure = NO_SCROLL_POSITION;
|
||||
@@ -1214,6 +1215,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
WritableMap map = new WritableNativeMap();
|
||||
map.putDouble(CONTENT_OFFSET_LEFT, PixelUtil.toDIPFromPixel(fabricScrollX));
|
||||
map.putDouble(CONTENT_OFFSET_TOP, PixelUtil.toDIPFromPixel(scrollY));
|
||||
map.putDouble(SCROLL_AWAY_PADDING_TOP, 0);
|
||||
return map;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -58,6 +58,7 @@ public class ReactScrollView extends ScrollView
|
||||
private static boolean sTriedToGetScrollerField = false;
|
||||
private static final String CONTENT_OFFSET_LEFT = "contentOffsetLeft";
|
||||
private static final String CONTENT_OFFSET_TOP = "contentOffsetTop";
|
||||
private static final String SCROLL_AWAY_PADDING_TOP = "scrollAwayPaddingTop";
|
||||
|
||||
private static final int UNSET_CONTENT_OFFSET = -1;
|
||||
|
||||
@@ -95,6 +96,8 @@ public class ReactScrollView extends ScrollView
|
||||
private int mFinalAnimatedPositionScrollX;
|
||||
private int mFinalAnimatedPositionScrollY;
|
||||
|
||||
private int mScrollAwayPaddingTop = 0;
|
||||
|
||||
private int mLastStateUpdateScrollX = -1;
|
||||
private int mLastStateUpdateScrollY = -1;
|
||||
|
||||
@@ -959,6 +962,41 @@ public class ReactScrollView extends ScrollView
|
||||
mReactBackgroundManager.setBorderStyle(style);
|
||||
}
|
||||
|
||||
/**
|
||||
* ScrollAway: This enables a natively-controlled navbar that optionally obscures the top content
|
||||
* of the ScrollView. Whether or not the navbar is obscuring the React Native surface is
|
||||
* determined outside of React Native.
|
||||
*
|
||||
* <p>Note: all ScrollViews and HorizontalScrollViews in React have exactly one child: the
|
||||
* "content" View (see ScrollView.js). That View is non-collapsable so it will never be
|
||||
* View-flattened away. However, it is possible to pass custom styles into that View.
|
||||
*
|
||||
* <p>If you are using this feature it is assumed that you have full control over this ScrollView
|
||||
* and that you are **not** overriding the ScrollView content view to pass in a `translateY`
|
||||
* style. `translateY` must never be set from ReactJS while using this feature!
|
||||
*/
|
||||
public void setScrollAwayTopPaddingEnabledUnstable(int topPadding) {
|
||||
int count = getChildCount();
|
||||
|
||||
Assertions.assertCondition(
|
||||
count == 1, "React Native ScrollView always has exactly 1 child; a content View");
|
||||
|
||||
if (count > 0) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
View childView = getChildAt(i);
|
||||
childView.setTranslationY(topPadding);
|
||||
}
|
||||
|
||||
// Add the topPadding value as the bottom padding for the ScrollView.
|
||||
// Otherwise, we'll push down the contents of the scroll view down too
|
||||
// far off screen.
|
||||
setPadding(0, 0, 0, topPadding);
|
||||
}
|
||||
|
||||
updateScrollAwayState(topPadding);
|
||||
setRemoveClippedSubviews(mRemoveClippedSubviews);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on any stabilized onScroll change to propagate content offset value to a Shadow Node.
|
||||
*/
|
||||
@@ -971,23 +1009,41 @@ public class ReactScrollView extends ScrollView
|
||||
mLastStateUpdateScrollX = scrollX;
|
||||
mLastStateUpdateScrollY = scrollY;
|
||||
|
||||
mFabricViewStateManager.setState(
|
||||
new FabricViewStateManager.StateUpdateCallback() {
|
||||
@Override
|
||||
public WritableMap getStateUpdate() {
|
||||
|
||||
WritableMap map = new WritableNativeMap();
|
||||
map.putDouble(CONTENT_OFFSET_LEFT, PixelUtil.toDIPFromPixel(scrollX));
|
||||
map.putDouble(CONTENT_OFFSET_TOP, PixelUtil.toDIPFromPixel(scrollY));
|
||||
return map;
|
||||
}
|
||||
});
|
||||
forceUpdateState();
|
||||
}
|
||||
|
||||
private void updateStateOnScroll() {
|
||||
updateStateOnScroll(getScrollX(), getScrollY());
|
||||
}
|
||||
|
||||
private void updateScrollAwayState(int scrollAwayPaddingTop) {
|
||||
if (mScrollAwayPaddingTop == scrollAwayPaddingTop) {
|
||||
return;
|
||||
}
|
||||
|
||||
mScrollAwayPaddingTop = scrollAwayPaddingTop;
|
||||
|
||||
forceUpdateState();
|
||||
}
|
||||
|
||||
private void forceUpdateState() {
|
||||
final int scrollX = mLastStateUpdateScrollX;
|
||||
final int scrollY = mLastStateUpdateScrollY;
|
||||
final int scrollAwayPaddingTop = mScrollAwayPaddingTop;
|
||||
|
||||
mFabricViewStateManager.setState(
|
||||
new FabricViewStateManager.StateUpdateCallback() {
|
||||
@Override
|
||||
public WritableMap getStateUpdate() {
|
||||
WritableMap map = new WritableNativeMap();
|
||||
map.putDouble(CONTENT_OFFSET_LEFT, PixelUtil.toDIPFromPixel(scrollX));
|
||||
map.putDouble(CONTENT_OFFSET_TOP, PixelUtil.toDIPFromPixel(scrollY));
|
||||
map.putDouble(SCROLL_AWAY_PADDING_TOP, PixelUtil.toDIPFromPixel(scrollAwayPaddingTop));
|
||||
return map;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricViewStateManager getFabricViewStateManager() {
|
||||
return mFabricViewStateManager;
|
||||
|
||||
Reference in New Issue
Block a user