Skip to content

Commit 17ab5a5

Browse files
author
Malik Kawee
committed
#updated docs
#new version with minor changes
1 parent 5a6bcb6 commit 17ab5a5

File tree

6 files changed

+30
-13
lines changed

6 files changed

+30
-13
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ npm-debug.log
55
# Dependency directory
66
node_modules
77

8+
#assets for readme
9+
assets
10+
811
# Runtime data
912
tmp

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
# rn-faded-scrollview
22
A simple and customisable React Native component that allows you to add fade effect in ScrollView at both ends.
33

4+
Vertical Scroll | Horizontal Scroll
5+
:-------------------------:|:-------------------------:
6+
![](assets/vertical.gif) | ![](assets/horizontal.gif)
7+
48
## Installation
59
This library relies on [react-native-linear-gradient](https://github.com/react-native-community/react-native-linear-gradient). Follow setup instructions of linear gradient.
610

7-
And now finally Run `npm install rn-faded-scrollview` in your project directory.
11+
And now finally Run `npm install rn-faded-scrollview` in your project directory.
12+
13+
## Documentation
14+
This library accepts all the props of [ScrollView](https://reactnative.dev/docs/scrollview) and some additional props.
15+
### Props
16+
| Name | Description | Default | Type |
17+
|---------------------------|------------------------------------------|-------------|---------|
18+
| allowStartFade | Add fade at the start of ScrollView | false | Boolean |
19+
| allowEndFade | Add fade at the end of ScrollView | true | Boolean |
20+
| fadeSize | Fade size i.e( width incase of horizontal and height incase of vertical ScrollView) | 20 | Number |
21+
| fadeColors | Colors for fade effect | ['rgba(229, 229, 229, 0.18)', 'rgba(206, 201, 201, 0.6)', 'rgba(206, 201, 201, 0.9)'] | Array |

assets/horizontal.gif

869 KB
Loading

assets/vertical.gif

1.52 MB
Loading

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rn-faded-scrollview",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
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": {
@@ -13,6 +13,8 @@
1313
"keywords": [
1414
"react-native",
1515
"scrollview",
16+
"scrollview faded",
17+
"faded scrollview",
1618
"fadedscrollview",
1719
"faded",
1820
"rn-faded-scrollview",
@@ -27,10 +29,11 @@
2729
"homepage": "https://github.com/mak12/rn-faded-scrollview#readme",
2830
"peerDependencies": {
2931
"react": "16.11.0",
30-
"react-native": "0.62.2",
32+
"react-native": "0.62.2"
33+
},
34+
"dependencies": {
3135
"react-native-linear-gradient": "^2.5.6"
3236
},
33-
"dependencies": {},
3437
"devDependencies": {
3538
"metro-react-native-babel-preset": "^0.59.0"
3639
}

src/index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ export default class RNFadedScrollView extends Component {
3131
}
3232

3333
isEndFadeAllowed() {
34-
const sizeToCompare = this.props.isHorizontal ? this.state.scrollWidth : this.state.scrollHeight;
35-
const availableSpace = this.props.isHorizontal ? this.state.availableWidth : this.state.availableHeight;
34+
const sizeToCompare = this.props.horizontal ? this.state.scrollWidth : this.state.scrollHeight;
35+
const availableSpace = this.props.horizontal ? this.state.availableWidth : this.state.availableHeight;
3636
return this.props.allowEndFade ? sizeToCompare > availableSpace : false;
3737
}
3838

3939
ifCloseToStart({ layoutMeasurement, contentOffset, contentSize }) {
40-
return this.props.isHorizontal ? contentOffset.x < 10 : contentOffset.y < 10;
40+
return this.props.horizontal ? contentOffset.x < 10 : contentOffset.y < 10;
4141
}
4242
isCloseToBottom({ layoutMeasurement, contentOffset, contentSize }) {
4343
return layoutMeasurement.height + contentOffset.y >= contentSize.height - 20;
@@ -61,7 +61,7 @@ export default class RNFadedScrollView extends Component {
6161

6262
//get start fade view
6363
getStartFaade() {
64-
return (this.props.isHorizontal ?
64+
return (this.props.horizontal ?
6565
<LinearGradient
6666
start={{ x: 1, y: 0 }} end={{ x: 0, y: 0 }}
6767
style={{ position: 'absolute', start: 0, width: this.props.fadeSize, height: '100%' }}
@@ -78,7 +78,7 @@ export default class RNFadedScrollView extends Component {
7878
}
7979

8080
getEndFade() {
81-
return (this.props.isHorizontal ?
81+
return (this.props.horizontal ?
8282
<LinearGradient
8383
start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
8484
style={{ position: 'absolute', end: 0, width: this.props.fadeSize, height: '100%' }}
@@ -97,12 +97,11 @@ export default class RNFadedScrollView extends Component {
9797
render() {
9898
const endFadeEnable = this.isEndFadeAllowed();
9999
return (
100-
<View style={[styles.container, { flexDirection: this.props.isHorizontal ? "row" : "column" }]}
100+
<View style={[styles.container, { flexDirection: this.props.horizontal ? "row" : "column" }]}
101101
onLayout={this._onLayout.bind(this)}>
102102
<ScrollView
103103
{...this.props}
104104
style={[styles.scrollViewStyle, this.props.style]}
105-
horizontal={this.props.isHorizontal}
106105
onContentSizeChange={this.onContentSizeChange}
107106
scrollEventThrottle={16}
108107
onScroll={this.onScrolled}
@@ -128,14 +127,12 @@ const styles = StyleSheet.create({
128127
}
129128
});
130129
RNFadedScrollView.propTypes = {
131-
isHorizontal: PropTypes.bool,
132130
allowStartFade: PropTypes.bool,
133131
allowEndFade: PropTypes.bool,
134132
fadeSize: PropTypes.number,
135133
fadeColors: PropTypes.array,
136134
}
137135
RNFadedScrollView.defaultProps = {
138-
isHorizontal: false,
139136
allowStartFade: false,
140137
allowEndFade: true,
141138
fadeSize: 20,

0 commit comments

Comments
 (0)