Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -565,16 +565,20 @@ export interface ScrollViewPropsAndroid {
nestedScrollEnabled?: boolean | undefined;

/**
* Fades out the edges of the scroll content.
* Controls the fading effect at the edges of the scroll content.
*
* If the value is greater than 0, the fading edges will be set accordingly
* to the current scroll direction and position,
* indicating if there is more content to show.
* A value greater than 0 will apply the fading effect, indicating more content is available
* to scroll.
*
* You can specify a single number to apply the same fading length to both edges.
* Alternatively, use an object with `start` and `end` properties to set different
* fading lengths for the start and end of the scroll content.
*
* The default value is 0.
*
* @platform android
*/
fadingEdgeLength?: number | undefined;
fadingEdgeLength?: number | {start: number; end: number} | undefined;

/**
* Causes the scrollbars not to turn transparent when they are not in use. The default value is false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,20 @@ export type ScrollViewPropsAndroid = $ReadOnly<{
*/
persistentScrollbar?: ?boolean,
/**
* Fades out the edges of the scroll content.
* Controls the fading effect at the edges of the scroll content.
*
* If the value is greater than 0, the fading edges will be set accordingly
* to the current scroll direction and position,
* indicating if there is more content to show.
* A value greater than 0 will apply the fading effect, indicating more content is available
* to scroll.
*
* You can specify a single number to apply the same fading length to both edges.
* Alternatively, use an object with `start` and `end` properties to set different
* fading lengths for the start and end of the scroll content.
*
* The default value is 0.
*
* @platform android
*/
fadingEdgeLength?: ?number,
fadingEdgeLength?: ?number | {start: number, end: number},
}>;

type StickyHeaderComponentType = component(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type ScrollViewNativeProps = $ReadOnly<{
directionalLockEnabled?: ?boolean,
disableIntervalMomentum?: ?boolean,
endFillColor?: ?ColorValue,
fadingEdgeLength?: ?number,
fadingEdgeLength?: ?number | {start: number, end: number},
indicatorStyle?: ?('default' | 'black' | 'white'),
isInvertedVirtualizedList?: ?boolean,
keyboardDismissMode?: ?('none' | 'on-drag' | 'interactive'),
Expand Down
14 changes: 9 additions & 5 deletions packages/react-native/Libraries/Lists/FlatList.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,20 @@ export interface FlatListProps<ItemT> extends VirtualizedListProps<ItemT> {
removeClippedSubviews?: boolean | undefined;

/**
* Fades out the edges of the scroll content.
* Controls the fading effect at the edges of the scroll content.
*
* If the value is greater than 0, the fading edges will be set accordingly
* to the current scroll direction and position,
* indicating if there is more content to show.
* A value greater than 0 will apply the fading effect, indicating more content is available
* to scroll.
*
* You can specify a single number to apply the same fading length to both edges.
* Alternatively, use an object with `start` and `end` properties to set different
* fading lengths for the start and end of the scroll content.
*
* The default value is 0.
*
* @platform android
*/
fadingEdgeLength?: number | undefined;
fadingEdgeLength?: number | {start: number; end: number} | undefined;
}

export abstract class FlatListComponent<
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ type OptionalProps<ItemT> = {
/**
* See `ScrollView` for flow type and further documentation.
*/
fadingEdgeLength?: ?number,
fadingEdgeLength?: ?number | {start: number, end: number},
/**
* Enable an optimization to memoize the item renderer to prevent unnecessary rerenders.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ export type ScrollViewPropsAndroid = $ReadOnly<{
scrollPerfTag?: ?string,
overScrollMode?: ?(\\"auto\\" | \\"always\\" | \\"never\\"),
persistentScrollbar?: ?boolean,
fadingEdgeLength?: ?number,
fadingEdgeLength?: ?number | { start: number, end: number },
}>;
type StickyHeaderComponentType = component(
ref?: React.RefSetter<
Expand Down Expand Up @@ -2157,7 +2157,7 @@ exports[`public API should not change unintentionally Libraries/Components/Scrol
directionalLockEnabled?: ?boolean,
disableIntervalMomentum?: ?boolean,
endFillColor?: ?ColorValue,
fadingEdgeLength?: ?number,
fadingEdgeLength?: ?number | { start: number, end: number },
indicatorStyle?: ?(\\"default\\" | \\"black\\" | \\"white\\"),
isInvertedVirtualizedList?: ?boolean,
keyboardDismissMode?: ?(\\"none\\" | \\"on-drag\\" | \\"interactive\\"),
Expand Down Expand Up @@ -4934,7 +4934,7 @@ type OptionalProps<ItemT> = {
keyExtractor?: ?(item: ItemT, index: number) => string,
numColumns?: number,
removeClippedSubviews?: boolean,
fadingEdgeLength?: ?number,
fadingEdgeLength?: ?number | { start: number, end: number },
strictMode?: boolean,
};
type FlatListBaseProps<ItemT> = {
Expand Down
16 changes: 14 additions & 2 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -5764,14 +5764,18 @@ public class com/facebook/react/views/scroll/ReactHorizontalScrollView : android
public fun focusSearch (Landroid/view/View;I)Landroid/view/View;
public fun getChildVisibleRect (Landroid/view/View;Landroid/graphics/Rect;Landroid/graphics/Point;)Z
public fun getClippingRect (Landroid/graphics/Rect;)V
public fun getFadingEdgeLengthEnd ()I
public fun getFadingEdgeLengthStart ()I
public fun getFlingAnimator ()Landroid/animation/ValueAnimator;
public fun getFlingExtrapolatedDistance (I)I
public fun getLastScrollDispatchTime ()J
protected fun getLeftFadingEdgeStrength ()F
public fun getOverflow ()Ljava/lang/String;
public fun getOverflowInset ()Landroid/graphics/Rect;
public fun getPointerEvents ()Lcom/facebook/react/uimanager/PointerEvents;
public fun getReactScrollViewScrollState ()Lcom/facebook/react/views/scroll/ReactScrollViewHelper$ReactScrollViewScrollState;
public fun getRemoveClippedSubviews ()Z
protected fun getRightFadingEdgeStrength ()F
public fun getScrollEnabled ()Z
public fun getScrollEventThrottle ()I
public fun getStateWrapper ()Lcom/facebook/react/uimanager/StateWrapper;
Expand Down Expand Up @@ -5805,6 +5809,8 @@ public class com/facebook/react/views/scroll/ReactHorizontalScrollView : android
public fun setDecelerationRate (F)V
public fun setDisableIntervalMomentum (Z)V
public fun setEndFillColor (I)V
public fun setFadingEdgeLengthEnd (I)V
public fun setFadingEdgeLengthStart (I)V
public fun setLastScrollDispatchTime (J)V
public fun setMaintainVisibleContentPosition (Lcom/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper$Config;)V
public fun setOverflow (Ljava/lang/String;)V
Expand Down Expand Up @@ -5854,7 +5860,7 @@ public class com/facebook/react/views/scroll/ReactHorizontalScrollViewManager :
public final fun setContentOffset (Lcom/facebook/react/views/scroll/ReactHorizontalScrollView;Lcom/facebook/react/bridge/ReadableMap;)V
public final fun setDecelerationRate (Lcom/facebook/react/views/scroll/ReactHorizontalScrollView;F)V
public final fun setDisableIntervalMomentum (Lcom/facebook/react/views/scroll/ReactHorizontalScrollView;Z)V
public final fun setFadingEdgeLength (Lcom/facebook/react/views/scroll/ReactHorizontalScrollView;I)V
public final fun setFadingEdgeLength (Lcom/facebook/react/views/scroll/ReactHorizontalScrollView;Lcom/facebook/react/bridge/Dynamic;)V
public final fun setHorizontal (Lcom/facebook/react/views/scroll/ReactHorizontalScrollView;Z)V
public final fun setMaintainVisibleContentPosition (Lcom/facebook/react/views/scroll/ReactHorizontalScrollView;Lcom/facebook/react/bridge/ReadableMap;)V
public final fun setNestedScrollEnabled (Lcom/facebook/react/views/scroll/ReactHorizontalScrollView;Z)V
Expand Down Expand Up @@ -5891,8 +5897,11 @@ public class com/facebook/react/views/scroll/ReactScrollView : android/widget/Sc
public fun flashScrollIndicators ()V
public fun fling (I)V
public fun focusSearch (Landroid/view/View;I)Landroid/view/View;
protected fun getBottomFadingEdgeStrength ()F
public fun getChildVisibleRect (Landroid/view/View;Landroid/graphics/Rect;Landroid/graphics/Point;)Z
public fun getClippingRect (Landroid/graphics/Rect;)V
public fun getFadingEdgeLengthEnd ()I
public fun getFadingEdgeLengthStart ()I
public fun getFlingAnimator ()Landroid/animation/ValueAnimator;
public fun getFlingExtrapolatedDistance (I)I
public fun getLastScrollDispatchTime ()J
Expand All @@ -5904,6 +5913,7 @@ public class com/facebook/react/views/scroll/ReactScrollView : android/widget/Sc
public fun getScrollEnabled ()Z
public fun getScrollEventThrottle ()I
public fun getStateWrapper ()Lcom/facebook/react/uimanager/StateWrapper;
protected fun getTopFadingEdgeStrength ()F
protected fun handleInterceptedTouchEvent (Landroid/view/MotionEvent;)V
public fun isPartiallyScrolledInView (Landroid/view/View;)Z
protected fun onAttachedToWindow ()V
Expand Down Expand Up @@ -5934,6 +5944,8 @@ public class com/facebook/react/views/scroll/ReactScrollView : android/widget/Sc
public fun setDecelerationRate (F)V
public fun setDisableIntervalMomentum (Z)V
public fun setEndFillColor (I)V
public fun setFadingEdgeLengthEnd (I)V
public fun setFadingEdgeLengthStart (I)V
public fun setLastScrollDispatchTime (J)V
public fun setMaintainVisibleContentPosition (Lcom/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper$Config;)V
public fun setOverflow (Ljava/lang/String;)V
Expand Down Expand Up @@ -6109,7 +6121,7 @@ public class com/facebook/react/views/scroll/ReactScrollViewManager : com/facebo
public final fun setContentOffset (Lcom/facebook/react/views/scroll/ReactScrollView;Lcom/facebook/react/bridge/ReadableMap;)V
public final fun setDecelerationRate (Lcom/facebook/react/views/scroll/ReactScrollView;F)V
public final fun setDisableIntervalMomentum (Lcom/facebook/react/views/scroll/ReactScrollView;Z)V
public final fun setFadingEdgeLength (Lcom/facebook/react/views/scroll/ReactScrollView;I)V
public final fun setFadingEdgeLength (Lcom/facebook/react/views/scroll/ReactScrollView;Lcom/facebook/react/bridge/Dynamic;)V
public final fun setHorizontal (Lcom/facebook/react/views/scroll/ReactScrollView;Z)V
public final fun setIsInvertedVirtualizedList (Lcom/facebook/react/views/scroll/ReactScrollView;Z)V
public final fun setMaintainVisibleContentPosition (Lcom/facebook/react/views/scroll/ReactScrollView;Lcom/facebook/react/bridge/ReadableMap;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
private int mScrollEventThrottle = 0;
private @Nullable View mContentView;
private @Nullable MaintainVisibleScrollPositionHelper mMaintainVisibleContentPositionHelper;
private int mFadingEdgeLengthStart = 0;
private int mFadingEdgeLengthEnd = 0;

private final Rect mTempRect = new Rect();

Expand Down Expand Up @@ -284,6 +286,44 @@ public void flashScrollIndicators() {
awakenScrollBars();
}

public int getFadingEdgeLengthStart() {
return mFadingEdgeLengthStart;
}

public int getFadingEdgeLengthEnd() {
return mFadingEdgeLengthEnd;
}

public void setFadingEdgeLengthStart(int start) {
mFadingEdgeLengthStart = start;
invalidate();
}

public void setFadingEdgeLengthEnd(int end) {
mFadingEdgeLengthEnd = end;
invalidate();
}

@Override
protected float getLeftFadingEdgeStrength() {
float max = Math.max(mFadingEdgeLengthStart, mFadingEdgeLengthEnd);
int value =
getLayoutDirection() == LAYOUT_DIRECTION_RTL
? mFadingEdgeLengthEnd
: mFadingEdgeLengthStart;
return (value / max);
}

@Override
protected float getRightFadingEdgeStrength() {
float max = Math.max(mFadingEdgeLengthStart, mFadingEdgeLengthEnd);
int value =
getLayoutDirection() == LAYOUT_DIRECTION_RTL
? mFadingEdgeLengthStart
: mFadingEdgeLengthEnd;
return (value / max);
}

public void setOverflow(@Nullable String overflow) {
if (overflow == null) {
mOverflow = Overflow.SCROLL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ package com.facebook.react.views.scroll

import android.graphics.Color
import androidx.core.view.ViewCompat
import com.facebook.react.bridge.Dynamic
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.ReadableType
import com.facebook.react.bridge.RetryableMountingLayerException
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.BackgroundStyleApplicator.setBorderColor
Expand All @@ -19,6 +21,7 @@ import com.facebook.react.uimanager.BackgroundStyleApplicator.setBorderStyle
import com.facebook.react.uimanager.BackgroundStyleApplicator.setBorderWidth
import com.facebook.react.uimanager.LengthPercentage
import com.facebook.react.uimanager.LengthPercentageType
import com.facebook.react.uimanager.PixelUtil.dpToPx
import com.facebook.react.uimanager.PixelUtil.getDisplayMetricDensity
import com.facebook.react.uimanager.PixelUtil.toPixelFromDIP
import com.facebook.react.uimanager.PointerEvents.Companion.parsePointerEvents
Expand Down Expand Up @@ -308,12 +311,37 @@ constructor(private val fpsListener: FpsListener? = null) :
}

@ReactProp(name = "fadingEdgeLength")
public fun setFadingEdgeLength(view: ReactHorizontalScrollView, value: Int) {
if (value > 0) {
view.isHorizontalFadingEdgeEnabled = true
view.setFadingEdgeLength(value)
public fun setFadingEdgeLength(view: ReactHorizontalScrollView, value: Dynamic) {
when (value.type) {
ReadableType.Number -> {
view.setFadingEdgeLengthStart(value.asInt())
view.setFadingEdgeLengthEnd(value.asInt())
}
ReadableType.Map -> {
value.asMap()?.let { map ->
var start = 0
var end = 0
if (map.hasKey("start") && map.getInt("start") > 0) {
start = map.getInt("start")
}
if (map.hasKey("end") && map.getInt("end") > 0) {
end = map.getInt("end")
}
view.setFadingEdgeLengthStart(start)
view.setFadingEdgeLengthEnd(end)
}
}
else -> {
// no-op
}
}
if (view.getFadingEdgeLengthStart() > 0 || view.getFadingEdgeLengthEnd() > 0) {
view.setHorizontalFadingEdgeEnabled(true)
view.setFadingEdgeLength(
Math.round(
Math.max(view.getFadingEdgeLengthStart(), view.getFadingEdgeLengthEnd()).dpToPx()))
} else {
view.isHorizontalFadingEdgeEnabled = false
view.setHorizontalFadingEdgeEnabled(false)
view.setFadingEdgeLength(0)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public class ReactScrollView extends ScrollView
private int mScrollEventThrottle = 0;
private @Nullable MaintainVisibleScrollPositionHelper mMaintainVisibleContentPositionHelper =
null;
private int mFadingEdgeLengthStart = 0;
private int mFadingEdgeLengthEnd = 0;

public ReactScrollView(Context context) {
this(context, null);
Expand Down Expand Up @@ -263,6 +265,36 @@ public void flashScrollIndicators() {
awakenScrollBars();
}

public int getFadingEdgeLengthStart() {
return mFadingEdgeLengthStart;
}

public int getFadingEdgeLengthEnd() {
return mFadingEdgeLengthEnd;
}

public void setFadingEdgeLengthStart(int start) {
mFadingEdgeLengthStart = start;
invalidate();
}

public void setFadingEdgeLengthEnd(int end) {
mFadingEdgeLengthEnd = end;
invalidate();
}

@Override
protected float getTopFadingEdgeStrength() {
float max = Math.max(mFadingEdgeLengthStart, mFadingEdgeLengthEnd);
return (mFadingEdgeLengthStart / max);
}

@Override
protected float getBottomFadingEdgeStrength() {
float max = Math.max(mFadingEdgeLengthStart, mFadingEdgeLengthEnd);
return (mFadingEdgeLengthEnd / max);
}

public void setOverflow(@Nullable String overflow) {
if (overflow == null) {
mOverflow = Overflow.SCROLL;
Expand Down
Loading
Loading