Skip to content

Commit bde0411

Browse files
author
Malik Kawee
committed
#End fade issue fixed on Samsung devices
#Release 1.0.8
1 parent 3d133d4 commit bde0411

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ This library accepts all the props of [ScrollView](https://reactnative.dev/docs/
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 |
2828
| scrollThreshold | Threshold to control fade hide/show when it reaches start or end | 10 | Number |
2929
| allowDivider | Allow divider at fade end. | false | Boolean. |
30+
| isRtl | For RTL Layouts | false | Boolean. |
31+
3032

3133
### Events
3234
| Name | Callback param | Description |

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.5",
3+
"version": "1.0.8",
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: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { StyleSheet, ScrollView, View } from 'react-native';
2+
import { StyleSheet, ScrollView, View, Platform } from 'react-native';
33
import PropTypes from "prop-types";
44
import LinearGradient from "react-native-linear-gradient"
55
const defaultFadeColors = ['rgba(229, 229, 229, 0.18)', 'rgba(206, 201, 201, 0.6)', 'rgba(206, 201, 201, 0.9)'];
@@ -27,7 +27,7 @@ export default class RNFadedScrollView extends Component {
2727

2828
_onLayout(event) {
2929
const containerWidth = event.nativeEvent.layout.width;
30-
const containerHeight = event.nativeEvent.layout.width;
30+
const containerHeight = event.nativeEvent.layout.height;
3131

3232
this.setState({ availableWidth: containerWidth, availableHeight: containerHeight })
3333
}
@@ -45,6 +45,10 @@ export default class RNFadedScrollView extends Component {
4545
return this.props.horizontal ? layoutMeasurement.width + contentOffset.x >= contentSize.width - this.props.scrollThreshold : layoutMeasurement.height + contentOffset.y >= contentSize.height - this.props.scrollThreshold;
4646
}
4747

48+
//To avoid ScrollView RTL issue on andorid.
49+
allowReverse() {
50+
return Platform.OS == 'android' && this.props.isRtl
51+
}
4852
onScrolled = (e) => {
4953
if (this.props.isCloseToEnd) {
5054
this.props.isCloseToEnd(this.isCloseToBottom(e.nativeEvent));
@@ -53,19 +57,19 @@ export default class RNFadedScrollView extends Component {
5357
this.props.isCloseToStart(this.ifCloseToStart(e.nativeEvent));
5458
}
5559
if (this.props.allowStartFade) {
56-
if (this.ifCloseToStart(e.nativeEvent)) {
57-
this.setState({ allowStartFade: false })
60+
if (!this.allowReverse()) {
61+
this.setState({ allowStartFade: this.ifCloseToStart(e.nativeEvent) ? false : true })
5862
}
5963
else {
60-
this.setState({ allowStartFade: true })
64+
this.setState({ allowEndFade: this.ifCloseToStart(e.nativeEvent) ? false : true })
6165
}
6266
}
6367
if (this.props.allowEndFade) {
64-
if (this.isCloseToBottom(e.nativeEvent)) {
65-
this.setState({ allowEndFade: false })
68+
if (!this.allowReverse()) {
69+
this.setState({ allowEndFade: this.isCloseToBottom(e.nativeEvent) ? false : true })
6670
}
6771
else {
68-
this.setState({ allowEndFade: true })
72+
this.setState({ allowStartFade: this.isCloseToBottom(e.nativeEvent) ? false : true })
6973
}
7074
}
7175
if (this.props.onScroll) {
@@ -77,7 +81,7 @@ export default class RNFadedScrollView extends Component {
7781
getStartFaade() {
7882
return (this.props.horizontal ?
7983
<LinearGradient
80-
start={{ x: 1, y: 0 }} end={{ x: 0, y: 0 }}
84+
start={{ x: this.props.isRtl ? 0 : 1, y: 0 }} end={{ x: this.props.isRtl ? 1 : 0, y: 0 }}
8185
style={{ position: 'absolute', start: 0, width: this.props.fadeSize, height: '100%' }}
8286
colors={this.props.fadeColors}
8387
pointerEvents={'none'}
@@ -94,7 +98,7 @@ export default class RNFadedScrollView extends Component {
9498
getEndFade() {
9599
return (this.props.horizontal ?
96100
<LinearGradient
97-
start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
101+
start={{ x: this.props.isRtl ? 1 : 0, y: 0 }} end={{ x: this.props.isRtl ? 0 : 1, y: 0 }}
98102
style={{ position: 'absolute', end: 0, width: this.props.fadeSize, height: '100%' }}
99103
colors={this.props.fadeColors}
100104
pointerEvents={'none'}
@@ -155,13 +159,15 @@ RNFadedScrollView.propTypes = {
155159
isCloseToEnd: PropTypes.func,
156160
isCloseToStart: PropTypes.func,
157161
scrollThreshold: PropTypes.number,
158-
allowDivider: PropTypes.bool
162+
allowDivider: PropTypes.bool,
163+
isRtl: PropTypes.bool
159164
}
160165
RNFadedScrollView.defaultProps = {
161166
allowStartFade: false,
162167
allowEndFade: true,
163168
fadeSize: 20,
164169
fadeColors: defaultFadeColors,
165170
scrollThreshold: 10,
166-
allowDivider: false
171+
allowDivider: false,
172+
isRtl: false
167173
}

0 commit comments

Comments
 (0)