Skip to content

Commit 3d133d4

Browse files
author
Malik Kawee
committed
#updated docs
#release 1.0.5
1 parent a84915b commit 3d133d4

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ This library accepts all the props of [ScrollView](https://reactnative.dev/docs/
2525
| allowEndFade | Add fade at the end of ScrollView | true | Boolean |
2626
| fadeSize | Fade size i.e( width incase of horizontal and height incase of vertical ScrollView) | 20 | Number |
2727
| fadeColors | Colors for fade effect | ['rgba(229, 229, 229, 0.18)', 'rgba(206, 201, 201, 0.6)', 'rgba(206, 201, 201, 0.9)'] | Array |
28+
| scrollThreshold | Threshold to control fade hide/show when it reaches start or end | 10 | Number |
29+
| allowDivider | Allow divider at fade end. | false | Boolean. |
30+
31+
### Events
32+
| Name | Callback param | Description |
33+
|---------------------------|------------------------------------------|-------------|
34+
| isCloseToEnd | Boolean | if scroll is close to end or not. |
35+
| isCloseToStart | Boolean | if scroll is close to start or not. |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rn-faded-scrollview",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "A simple and customizable React Native component that allows you to add fade effect in ScrollView at both ends.",
55
"main": "src/index.js",
66
"scripts": {

src/index.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ export default class RNFadedScrollView extends Component {
3939
}
4040

4141
ifCloseToStart({ layoutMeasurement, contentOffset, contentSize }) {
42-
return this.props.horizontal ? contentOffset.x < 10 : contentOffset.y < 10;
42+
return this.props.horizontal ? contentOffset.x < this.props.scrollThreshold : contentOffset.y < this.props.scrollThreshold;
4343
}
4444
isCloseToBottom({ layoutMeasurement, contentOffset, contentSize }) {
45-
return this.props.horizontal ? layoutMeasurement.width + contentOffset.x >= contentSize.width - 10 : layoutMeasurement.height + contentOffset.y >= contentSize.height - 10;
45+
return this.props.horizontal ? layoutMeasurement.width + contentOffset.x >= contentSize.width - this.props.scrollThreshold : layoutMeasurement.height + contentOffset.y >= contentSize.height - this.props.scrollThreshold;
4646
}
4747

4848
onScrolled = (e) => {
49+
if (this.props.isCloseToEnd) {
50+
this.props.isCloseToEnd(this.isCloseToBottom(e.nativeEvent));
51+
}
52+
if (this.props.isCloseToStart) {
53+
this.props.isCloseToStart(this.ifCloseToStart(e.nativeEvent));
54+
}
4955
if (this.props.allowStartFade) {
5056
if (this.ifCloseToStart(e.nativeEvent)) {
5157
this.setState({ allowStartFade: false })
@@ -96,17 +102,25 @@ export default class RNFadedScrollView extends Component {
96102
:
97103
<LinearGradient
98104
start={{ x: 0, y: 0 }} end={{ x: 0, y: 1 }}
99-
style={{ position: 'absolute', bottom: 0, width: '100%', height: 20 }}
105+
style={{ position: 'absolute', bottom: 0, width: '100%', height: this.props.fadeSize }}
100106
colors={this.props.fadeColors}
101107
pointerEvents={'none'}
102108
/>)
103109
}
110+
getDivider() {
111+
return (this.props.horizontal ? <View
112+
style={[{ width: 1, height: '100%', backgroundColor: "#E6E6E6" }, this.props.dividerStyle]}
113+
/> : <View
114+
style={[{ width: '100%', height: 1, backgroundColor: "#E6E6E6" }, this.props.dividerStyle]}
115+
/>)
116+
}
104117

105118
render() {
106119
const endFadeEnable = this.isEndFadeAllowed();
107120
return (
108121
<View style={[styles.container, { flexDirection: this.props.horizontal ? "row" : "column" }]}
109122
onLayout={this._onLayout.bind(this)}>
123+
{(this.state.allowStartFade && this.props.allowDivider) && this.getDivider()}
110124
<ScrollView
111125
{...this.props}
112126
style={[styles.scrollViewStyle, this.props.style]}
@@ -116,6 +130,7 @@ export default class RNFadedScrollView extends Component {
116130
>
117131
{this.props.children}
118132
</ScrollView>
133+
{((endFadeEnable && this.state.allowEndFade) && this.props.allowDivider) && this.getDivider()}
119134
{(this.state.allowStartFade) && this.getStartFaade()}
120135
{(endFadeEnable && this.state.allowEndFade) && this.getEndFade()}
121136
</View>
@@ -137,10 +152,16 @@ RNFadedScrollView.propTypes = {
137152
allowEndFade: PropTypes.bool,
138153
fadeSize: PropTypes.number,
139154
fadeColors: PropTypes.array,
155+
isCloseToEnd: PropTypes.func,
156+
isCloseToStart: PropTypes.func,
157+
scrollThreshold: PropTypes.number,
158+
allowDivider: PropTypes.bool
140159
}
141160
RNFadedScrollView.defaultProps = {
142161
allowStartFade: false,
143162
allowEndFade: true,
144163
fadeSize: 20,
145-
fadeColors: defaultFadeColors
164+
fadeColors: defaultFadeColors,
165+
scrollThreshold: 10,
166+
allowDivider: false
146167
}

0 commit comments

Comments
 (0)