Skip to content

Commit a84915b

Browse files
author
Malik Kawee
committed
#End scroll hide/show now working smoothly
#Release 1.0.4
1 parent 17ab5a5 commit a84915b

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ Vertical Scroll | Horizontal Scroll
88
## Installation
99
This library relies on [react-native-linear-gradient](https://github.com/react-native-community/react-native-linear-gradient). Follow setup instructions of linear gradient.
1010

11-
And now finally Run `npm install rn-faded-scrollview` in your project directory.
11+
And now finally run in your project directory.
12+
13+
`npm install rn-faded-scrollview`
14+
15+
OR
16+
17+
`yarn add rn-faded-scrollview`
1218

1319
## Documentation
1420
This library accepts all the props of [ScrollView](https://reactnative.dev/docs/scrollview) and some additional props.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rn-faded-scrollview",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
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": {
@@ -29,11 +29,10 @@
2929
"homepage": "https://github.com/mak12/rn-faded-scrollview#readme",
3030
"peerDependencies": {
3131
"react": "16.11.0",
32-
"react-native": "0.62.2"
33-
},
34-
"dependencies": {
35-
"react-native-linear-gradient": "^2.5.6"
32+
"react-native": "0.62.2",
33+
"react-native-linear-gradient": "^2.x.x"
3634
},
35+
"dependencies": {},
3736
"devDependencies": {
3837
"metro-react-native-babel-preset": "^0.59.0"
3938
}

src/index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export default class RNFadedScrollView extends Component {
1414
scrollWidth: 0,
1515
availableWidth: 0,
1616
availableHeight: 0,
17-
allowStartFade: false
17+
allowStartFade: false,
18+
allowEndFade: true
1819
}
1920
}
2021

@@ -23,6 +24,7 @@ export default class RNFadedScrollView extends Component {
2324
// Save the content height in state
2425
this.setState({ scrollHeight: contentHeight, scrollWidth: contentWidth });
2526
};
27+
2628
_onLayout(event) {
2729
const containerWidth = event.nativeEvent.layout.width;
2830
const containerHeight = event.nativeEvent.layout.width;
@@ -40,20 +42,26 @@ export default class RNFadedScrollView extends Component {
4042
return this.props.horizontal ? contentOffset.x < 10 : contentOffset.y < 10;
4143
}
4244
isCloseToBottom({ layoutMeasurement, contentOffset, contentSize }) {
43-
return layoutMeasurement.height + contentOffset.y >= contentSize.height - 20;
45+
return this.props.horizontal ? layoutMeasurement.width + contentOffset.x >= contentSize.width - 10 : layoutMeasurement.height + contentOffset.y >= contentSize.height - 10;
4446
}
4547

4648
onScrolled = (e) => {
4749
if (this.props.allowStartFade) {
4850
if (this.ifCloseToStart(e.nativeEvent)) {
4951
this.setState({ allowStartFade: false })
50-
5152
}
5253
else {
5354
this.setState({ allowStartFade: true })
5455
}
5556
}
56-
57+
if (this.props.allowEndFade) {
58+
if (this.isCloseToBottom(e.nativeEvent)) {
59+
this.setState({ allowEndFade: false })
60+
}
61+
else {
62+
this.setState({ allowEndFade: true })
63+
}
64+
}
5765
if (this.props.onScroll) {
5866
this.props.onScroll();
5967
}
@@ -109,12 +117,10 @@ export default class RNFadedScrollView extends Component {
109117
{this.props.children}
110118
</ScrollView>
111119
{(this.state.allowStartFade) && this.getStartFaade()}
112-
{endFadeEnable && this.getEndFade()}
120+
{(endFadeEnable && this.state.allowEndFade) && this.getEndFade()}
113121
</View>
114122
)
115123
}
116-
117-
118124
}
119125

120126
const styles = StyleSheet.create({

0 commit comments

Comments
 (0)