Skip to content

Commit 51aacd5

Browse files
André Krügerfacebook-github-bot
André Krüger
authored andcommitted
Implement fading edges for ScrollView and it's dependent FlatList (#26163)
Summary: 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. ## Changelog [Android] [Added] - fading edges props to the FlatList and ScrollView components Pull Request resolved: #26163 Test Plan: Open the React Native test app and navigate to the FlatList section. Enable the `useFadingEdges` switch and insert a number into `Fading edge length`. ![device-2019-08-23-123745](https://user-images.githubusercontent.com/222393/63587150-7385cb00-c5a3-11e9-98dc-bffe8276d30c.png) ![device-2019-08-23-123844](https://user-images.githubusercontent.com/222393/63587156-75e82500-c5a3-11e9-9e9f-66876ac8f506.png) Differential Revision: D17080676 Pulled By: TheSavior fbshipit-source-id: 91df629c17052d43c99145672e9084e1379a4113
1 parent c9ff99f commit 51aacd5

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

Libraries/Components/ScrollView/ScrollView.js

+12
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,18 @@ type AndroidProps = $ReadOnly<{|
335335
* @platform android
336336
*/
337337
persistentScrollbar?: ?boolean,
338+
/**
339+
* Fades out the edges of the the scroll content.
340+
*
341+
* If the value is greater than 0, the fading edges will be set accordingly
342+
* to the current scroll direction and position,
343+
* indicating if there is more content to show.
344+
*
345+
* The default value is 0.
346+
*
347+
* @platform android
348+
*/
349+
fadingEdgeLength?: ?number,
338350
|}>;
339351

340352
type VRProps = $ReadOnly<{|

Libraries/Lists/FlatList.js

+4
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ type OptionalProps<ItemT> = {
233233
* will be called when its corresponding ViewabilityConfig's conditions are met.
234234
*/
235235
viewabilityConfigCallbackPairs?: Array<ViewabilityConfigCallbackPair>,
236+
/**
237+
* See `ScrollView` for flow type and further documentation.
238+
*/
239+
fadingEdgeLength?: ?number,
236240
};
237241
export type Props<ItemT> = RequiredProps<ItemT> &
238242
OptionalProps<ItemT> &

RNTester/js/examples/FlatList/FlatListExample.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ const {
2929
pressItem,
3030
renderSmallSwitchOption,
3131
} = require('../../components/ListExampleShared');
32-
const {Alert, Animated, StyleSheet, View} = require('react-native');
32+
const {
33+
Alert,
34+
Animated,
35+
Platform,
36+
StyleSheet,
37+
TextInput,
38+
View,
39+
} = require('react-native');
3340

3441
import type {Item} from '../../components/ListExampleShared';
3542

@@ -51,6 +58,7 @@ type State = {|
5158
virtualized: boolean,
5259
empty: boolean,
5360
useFlatListItemComponent: boolean,
61+
fadingEdgeLength: number,
5462
|};
5563

5664
class FlatListExample extends React.PureComponent<Props, State> {
@@ -65,6 +73,7 @@ class FlatListExample extends React.PureComponent<Props, State> {
6573
virtualized: true,
6674
empty: false,
6775
useFlatListItemComponent: false,
76+
fadingEdgeLength: 0,
6877
};
6978

7079
_onChangeFilterText = filterText => {
@@ -124,11 +133,26 @@ class FlatListExample extends React.PureComponent<Props, State> {
124133
{renderSmallSwitchOption(this, 'empty')}
125134
{renderSmallSwitchOption(this, 'debug')}
126135
{renderSmallSwitchOption(this, 'useFlatListItemComponent')}
136+
{Platform.OS === 'android' && (
137+
<View>
138+
<TextInput
139+
placeholder="Fading edge length"
140+
underlineColorAndroid="black"
141+
keyboardType={'numeric'}
142+
onChange={event =>
143+
this.setState({
144+
fadingEdgeLength: Number(event.nativeEvent.text),
145+
})
146+
}
147+
/>
148+
</View>
149+
)}
127150
<Spindicator value={this._scrollPos} />
128151
</View>
129152
</View>
130153
<SeparatorComponent />
131154
<Animated.FlatList
155+
fadingEdgeLength={this.state.fadingEdgeLength}
132156
ItemSeparatorComponent={ItemSeparatorComponent}
133157
ListHeaderComponent={<HeaderComponent />}
134158
ListFooterComponent={FooterComponent}

ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java

+11
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,15 @@ public void setOverflow(ReactHorizontalScrollView view, @Nullable String overflo
276276
public void setPersistentScrollbar(ReactHorizontalScrollView view, boolean value) {
277277
view.setScrollbarFadingEnabled(!value);
278278
}
279+
280+
@ReactProp(name = "fadingEdgeLength")
281+
public void setFadingEdgeLength(ReactHorizontalScrollView view, int value) {
282+
if (value > 0) {
283+
view.setHorizontalFadingEdgeEnabled(true);
284+
view.setFadingEdgeLength(value);
285+
} else {
286+
view.setHorizontalFadingEdgeEnabled(false);
287+
view.setFadingEdgeLength(0);
288+
}
289+
}
279290
}

ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java

+11
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,17 @@ public void setPersistentScrollbar(ReactScrollView view, boolean value) {
278278
view.setScrollbarFadingEnabled(!value);
279279
}
280280

281+
@ReactProp(name = "fadingEdgeLength")
282+
public void setFadingEdgeLength(ReactScrollView view, int value) {
283+
if (value > 0) {
284+
view.setVerticalFadingEdgeEnabled(true);
285+
view.setFadingEdgeLength(value);
286+
} else {
287+
view.setVerticalFadingEdgeEnabled(false);
288+
view.setFadingEdgeLength(0);
289+
}
290+
}
291+
281292
@Override
282293
public @Nullable Map<String, Object> getExportedCustomDirectEventTypeConstants() {
283294
return createExportedCustomDirectEventTypeConstants();

0 commit comments

Comments
 (0)