@@ -39,13 +39,19 @@ export default class RNFadedScrollView extends Component {
39
39
}
40
40
41
41
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 ;
43
43
}
44
44
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 ;
46
46
}
47
47
48
48
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
+ }
49
55
if ( this . props . allowStartFade ) {
50
56
if ( this . ifCloseToStart ( e . nativeEvent ) ) {
51
57
this . setState ( { allowStartFade : false } )
@@ -96,17 +102,25 @@ export default class RNFadedScrollView extends Component {
96
102
:
97
103
< LinearGradient
98
104
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 } }
100
106
colors = { this . props . fadeColors }
101
107
pointerEvents = { 'none' }
102
108
/> )
103
109
}
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
+ }
104
117
105
118
render ( ) {
106
119
const endFadeEnable = this . isEndFadeAllowed ( ) ;
107
120
return (
108
121
< View style = { [ styles . container , { flexDirection : this . props . horizontal ? "row" : "column" } ] }
109
122
onLayout = { this . _onLayout . bind ( this ) } >
123
+ { ( this . state . allowStartFade && this . props . allowDivider ) && this . getDivider ( ) }
110
124
< ScrollView
111
125
{ ...this . props }
112
126
style = { [ styles . scrollViewStyle , this . props . style ] }
@@ -116,6 +130,7 @@ export default class RNFadedScrollView extends Component {
116
130
>
117
131
{ this . props . children }
118
132
</ ScrollView >
133
+ { ( ( endFadeEnable && this . state . allowEndFade ) && this . props . allowDivider ) && this . getDivider ( ) }
119
134
{ ( this . state . allowStartFade ) && this . getStartFaade ( ) }
120
135
{ ( endFadeEnable && this . state . allowEndFade ) && this . getEndFade ( ) }
121
136
</ View >
@@ -137,10 +152,16 @@ RNFadedScrollView.propTypes = {
137
152
allowEndFade : PropTypes . bool ,
138
153
fadeSize : PropTypes . number ,
139
154
fadeColors : PropTypes . array ,
155
+ isCloseToEnd : PropTypes . func ,
156
+ isCloseToStart : PropTypes . func ,
157
+ scrollThreshold : PropTypes . number ,
158
+ allowDivider : PropTypes . bool
140
159
}
141
160
RNFadedScrollView . defaultProps = {
142
161
allowStartFade : false ,
143
162
allowEndFade : true ,
144
163
fadeSize : 20 ,
145
- fadeColors : defaultFadeColors
164
+ fadeColors : defaultFadeColors ,
165
+ scrollThreshold : 10 ,
166
+ allowDivider : false
146
167
}
0 commit comments