@@ -58,6 +58,7 @@ public class ReactScrollView extends ScrollView
58
58
private static boolean sTriedToGetScrollerField = false ;
59
59
private static final String CONTENT_OFFSET_LEFT = "contentOffsetLeft" ;
60
60
private static final String CONTENT_OFFSET_TOP = "contentOffsetTop" ;
61
+ private static final String SCROLL_AWAY_PADDING_TOP = "scrollAwayPaddingTop" ;
61
62
62
63
private static final int UNSET_CONTENT_OFFSET = -1 ;
63
64
@@ -95,6 +96,8 @@ public class ReactScrollView extends ScrollView
95
96
private int mFinalAnimatedPositionScrollX ;
96
97
private int mFinalAnimatedPositionScrollY ;
97
98
99
+ private int mScrollAwayPaddingTop = 0 ;
100
+
98
101
private int mLastStateUpdateScrollX = -1 ;
99
102
private int mLastStateUpdateScrollY = -1 ;
100
103
@@ -959,6 +962,41 @@ public void setBorderStyle(@Nullable String style) {
959
962
mReactBackgroundManager .setBorderStyle (style );
960
963
}
961
964
965
+ /**
966
+ * ScrollAway: This enables a natively-controlled navbar that optionally obscures the top content
967
+ * of the ScrollView. Whether or not the navbar is obscuring the React Native surface is
968
+ * determined outside of React Native.
969
+ *
970
+ * <p>Note: all ScrollViews and HorizontalScrollViews in React have exactly one child: the
971
+ * "content" View (see ScrollView.js). That View is non-collapsable so it will never be
972
+ * View-flattened away. However, it is possible to pass custom styles into that View.
973
+ *
974
+ * <p>If you are using this feature it is assumed that you have full control over this ScrollView
975
+ * and that you are **not** overriding the ScrollView content view to pass in a `translateY`
976
+ * style. `translateY` must never be set from ReactJS while using this feature!
977
+ */
978
+ public void setScrollAwayTopPaddingEnabledUnstable (int topPadding ) {
979
+ int count = getChildCount ();
980
+
981
+ Assertions .assertCondition (
982
+ count == 1 , "React Native ScrollView always has exactly 1 child; a content View" );
983
+
984
+ if (count > 0 ) {
985
+ for (int i = 0 ; i < count ; i ++) {
986
+ View childView = getChildAt (i );
987
+ childView .setTranslationY (topPadding );
988
+ }
989
+
990
+ // Add the topPadding value as the bottom padding for the ScrollView.
991
+ // Otherwise, we'll push down the contents of the scroll view down too
992
+ // far off screen.
993
+ setPadding (0 , 0 , 0 , topPadding );
994
+ }
995
+
996
+ updateScrollAwayState (topPadding );
997
+ setRemoveClippedSubviews (mRemoveClippedSubviews );
998
+ }
999
+
962
1000
/**
963
1001
* Called on any stabilized onScroll change to propagate content offset value to a Shadow Node.
964
1002
*/
@@ -971,23 +1009,41 @@ private void updateStateOnScroll(final int scrollX, final int scrollY) {
971
1009
mLastStateUpdateScrollX = scrollX ;
972
1010
mLastStateUpdateScrollY = scrollY ;
973
1011
1012
+ forceUpdateState ();
1013
+ }
1014
+
1015
+ private void updateStateOnScroll () {
1016
+ updateStateOnScroll (getScrollX (), getScrollY ());
1017
+ }
1018
+
1019
+ private void updateScrollAwayState (int scrollAwayPaddingTop ) {
1020
+ if (mScrollAwayPaddingTop == scrollAwayPaddingTop ) {
1021
+ return ;
1022
+ }
1023
+
1024
+ mScrollAwayPaddingTop = scrollAwayPaddingTop ;
1025
+
1026
+ forceUpdateState ();
1027
+ }
1028
+
1029
+ private void forceUpdateState () {
1030
+ final int scrollX = mLastStateUpdateScrollX ;
1031
+ final int scrollY = mLastStateUpdateScrollY ;
1032
+ final int scrollAwayPaddingTop = mScrollAwayPaddingTop ;
1033
+
974
1034
mFabricViewStateManager .setState (
975
1035
new FabricViewStateManager .StateUpdateCallback () {
976
1036
@ Override
977
1037
public WritableMap getStateUpdate () {
978
-
979
1038
WritableMap map = new WritableNativeMap ();
980
1039
map .putDouble (CONTENT_OFFSET_LEFT , PixelUtil .toDIPFromPixel (scrollX ));
981
1040
map .putDouble (CONTENT_OFFSET_TOP , PixelUtil .toDIPFromPixel (scrollY ));
1041
+ map .putDouble (SCROLL_AWAY_PADDING_TOP , PixelUtil .toDIPFromPixel (scrollAwayPaddingTop ));
982
1042
return map ;
983
1043
}
984
1044
});
985
1045
}
986
1046
987
- private void updateStateOnScroll () {
988
- updateStateOnScroll (getScrollX (), getScrollY ());
989
- }
990
-
991
1047
@ Override
992
1048
public FabricViewStateManager getFabricViewStateManager () {
993
1049
return mFabricViewStateManager ;
0 commit comments