From b86efed0acf84491903cb84febbdc5c55526774b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kr=C3=BCger?= Date: Fri, 23 Aug 2019 12:31:50 +0200 Subject: [PATCH] Implement fading edges for Scrollview and it's dependent FlatList This should add props for enabling horizontal and vertical fading edges for Scrollview and FlatList. These fading edges are used to communicate to the user that there is more content to see. --- Libraries/Components/ScrollView/ScrollView.js | 12 +++++++++ Libraries/Lists/FlatList.js | 4 +++ .../js/examples/FlatList/FlatListExample.js | 26 ++++++++++++++++++- .../ReactHorizontalScrollViewManager.java | 11 ++++++++ .../views/scroll/ReactScrollViewManager.java | 11 ++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index b4298158b3354f..46f91c6a8acdf6 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -335,6 +335,18 @@ type AndroidProps = $ReadOnly<{| * @platform android */ persistentScrollbar?: ?boolean, + /** + * Fades out the edges of the 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. + * + * The default value is 0. + * + * @platform android + */ + fadingEdgeLength?: ?number, |}>; type VRProps = $ReadOnly<{| diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index 3afed1ba5a75b7..cd7b1d6c6c2be4 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -233,6 +233,10 @@ type OptionalProps = { * will be called when its corresponding ViewabilityConfig's conditions are met. */ viewabilityConfigCallbackPairs?: Array, + /** + * See `ScrollView` for flow type and further documentation. + */ + fadingEdgeLength?: ?number, }; export type Props = RequiredProps & OptionalProps & diff --git a/RNTester/js/examples/FlatList/FlatListExample.js b/RNTester/js/examples/FlatList/FlatListExample.js index bb7cc9afe88c02..e71b9acd6d4d4a 100644 --- a/RNTester/js/examples/FlatList/FlatListExample.js +++ b/RNTester/js/examples/FlatList/FlatListExample.js @@ -29,7 +29,14 @@ const { pressItem, renderSmallSwitchOption, } = require('../../components/ListExampleShared'); -const {Alert, Animated, StyleSheet, View} = require('react-native'); +const { + Alert, + Animated, + Platform, + StyleSheet, + TextInput, + View, +} = require('react-native'); import type {Item} from '../../components/ListExampleShared'; @@ -51,6 +58,7 @@ type State = {| virtualized: boolean, empty: boolean, useFlatListItemComponent: boolean, + fadingEdgeLength: number, |}; class FlatListExample extends React.PureComponent { @@ -65,6 +73,7 @@ class FlatListExample extends React.PureComponent { virtualized: true, empty: false, useFlatListItemComponent: false, + fadingEdgeLength: 0, }; _onChangeFilterText = filterText => { @@ -124,11 +133,26 @@ class FlatListExample extends React.PureComponent { {renderSmallSwitchOption(this, 'empty')} {renderSmallSwitchOption(this, 'debug')} {renderSmallSwitchOption(this, 'useFlatListItemComponent')} + {Platform.OS === 'android' && ( + + + this.setState({ + fadingEdgeLength: Number(event.nativeEvent.text), + }) + } + /> + + )} } ListFooterComponent={FooterComponent} diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java index a8c9898e10d5d7..221cff4ccfe32c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java @@ -276,4 +276,15 @@ public void setOverflow(ReactHorizontalScrollView view, @Nullable String overflo public void setPersistentScrollbar(ReactHorizontalScrollView view, boolean value) { view.setScrollbarFadingEnabled(!value); } + + @ReactProp(name = "fadingEdgeLength") + public void setFadingEdgeLength(ReactHorizontalScrollView view, int value) { + if (value > 0) { + view.setHorizontalFadingEdgeEnabled(true); + view.setFadingEdgeLength(value); + } else { + view.setHorizontalFadingEdgeEnabled(false); + view.setFadingEdgeLength(0); + } + } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java index cb8befaca24300..679db98450d311 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java @@ -278,6 +278,17 @@ public void setPersistentScrollbar(ReactScrollView view, boolean value) { view.setScrollbarFadingEnabled(!value); } + @ReactProp(name = "fadingEdgeLength") + public void setFadingEdgeLength(ReactScrollView view, int value) { + if (value > 0) { + view.setVerticalFadingEdgeEnabled(true); + view.setFadingEdgeLength(value); + } else { + view.setVerticalFadingEdgeEnabled(false); + view.setFadingEdgeLength(0); + } + } + @Override public @Nullable Map getExportedCustomDirectEventTypeConstants() { return createExportedCustomDirectEventTypeConstants();