1
1
import React , { useCallback } from 'react' ;
2
2
import { ViewProps , ScrollView , ScrollViewProps , NativeSyntheticEvent , NativeScrollEvent } from 'react-native' ;
3
- import Fader from '../../components/ fader' ;
3
+ import Fader from '../fader' ;
4
4
import withScrollEnabler , { WithScrollEnablerProps } from '../../commons/withScrollEnabler' ;
5
5
import withScrollReached , { WithScrollReachedProps } from '../../commons/withScrollReached' ;
6
6
import forwardRef , { ForwardRefInjectedProps } from '../../commons/forwardRef' ;
7
+ import { Constants } from '../../helpers' ;
7
8
8
- export type FadedScrollViewProps = ViewProps & ScrollViewProps & {
9
- children ?: React . ReactNode | React . ReactNode [ ] ;
10
- } ;
9
+ export type FadedScrollViewProps = ViewProps &
10
+ ScrollViewProps & {
11
+ children ?: React . ReactNode | React . ReactNode [ ] ;
12
+ } ;
11
13
12
14
type ScrollReachedProps = FadedScrollViewProps & WithScrollReachedProps ;
13
15
type ScrollEnabledProps = ScrollReachedProps & WithScrollEnablerProps ;
@@ -17,16 +19,20 @@ const FADER_SIZE = 76;
17
19
18
20
const FadedScrollView = ( props : Props ) => {
19
21
const { scrollEnablerProps, scrollReachedProps, children, onScroll : propsOnScroll , ...other } = props ;
20
- const fadeLeft = scrollEnablerProps . scrollEnabled && ! scrollReachedProps . isScrollAtStart ;
21
- const fadeRight = scrollEnablerProps . scrollEnabled && ! scrollReachedProps . isScrollAtEnd ;
22
+ const showLeft =
23
+ scrollEnablerProps . scrollEnabled &&
24
+ ( Constants . isRTL ? ! scrollReachedProps . isScrollAtEnd : ! scrollReachedProps . isScrollAtStart ) ;
25
+ const leftPosition = Constants . isRTL ? Fader . position . RIGHT : Fader . position . LEFT ;
26
+ const showRight =
27
+ scrollEnablerProps . scrollEnabled &&
28
+ ( Constants . isRTL ? ! scrollReachedProps . isScrollAtStart : ! scrollReachedProps . isScrollAtEnd ) ;
29
+ const rightPosition = Constants . isRTL ? Fader . position . LEFT : Fader . position . RIGHT ;
22
30
23
- const onScroll = useCallback (
24
- ( event : NativeSyntheticEvent < NativeScrollEvent > ) => {
25
- scrollReachedProps . onScroll ( event ) ;
31
+ const onScroll = useCallback ( ( event : NativeSyntheticEvent < NativeScrollEvent > ) => {
32
+ scrollReachedProps . onScroll ( event ) ;
26
33
propsOnScroll ?.( event ) ;
27
- } ,
28
- [ scrollReachedProps . onScroll , propsOnScroll ]
29
- ) ;
34
+ } ,
35
+ [ scrollReachedProps . onScroll , propsOnScroll ] ) ;
30
36
31
37
if ( children ) {
32
38
return (
@@ -45,8 +51,8 @@ const FadedScrollView = (props: Props) => {
45
51
>
46
52
{ children }
47
53
</ ScrollView >
48
- < Fader visible = { fadeLeft } position = { Fader . position . LEFT } size = { FADER_SIZE } />
49
- < Fader visible = { fadeRight } position = { Fader . position . RIGHT } size = { FADER_SIZE } />
54
+ < Fader visible = { showLeft } position = { leftPosition } size = { FADER_SIZE } supportRTL />
55
+ < Fader visible = { showRight } position = { rightPosition } size = { FADER_SIZE } supportRTL />
50
56
</ >
51
57
) ;
52
58
}
0 commit comments