Skip to content

Commit 2377b58

Browse files
committed
Fix Fader in RTL
1 parent ca6b157 commit 2377b58

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

demo/src/screens/componentScreens/FaderScreen.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import _ from 'lodash';
22
import React, {Component} from 'react';
33
import {StyleSheet, ScrollView} from 'react-native';
44
import {
5+
Constants,
56
Colors,
67
Text,
78
View,
@@ -34,7 +35,7 @@ class FaderScreen extends Component<WithScrollReachedProps> {
3435
const {scrollReachedProps} = this.props;
3536
const visible =
3637
faderPosition === Fader.position.BOTTOM ||
37-
faderPosition === Fader.position.RIGHT
38+
(faderPosition === Fader.position.RIGHT && !Constants.isRTL)
3839
? !scrollReachedProps.isScrollAtEnd
3940
: !scrollReachedProps.isScrollAtStart;
4041

@@ -54,6 +55,7 @@ class FaderScreen extends Component<WithScrollReachedProps> {
5455
{_.times(numberOfItems, this.renderItem)}
5556
</ScrollView>
5657
<Fader
58+
supportRTL
5759
visible={visible}
5860
position={faderPosition}
5961
tintColor={tintColor}

generatedTypes/components/fader/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/// <reference types="react" />
2+
import { ImageProps } from '../image';
23
export declare enum FaderPosition {
34
LEFT = "LEFT",
45
RIGHT = "RIGHT",
56
TOP = "TOP",
67
BOTTOM = "BOTTOM"
78
}
8-
export declare type FaderProps = {
9+
export declare type FaderProps = Pick<ImageProps, 'supportRTL'> & {
910
/**
1011
* Whether the fader is visible (default is true)
1112
*/

src/components/fader/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash';
22
import React, {useCallback} from 'react';
33
import {StyleSheet} from 'react-native';
44
import View from '../view';
5-
import Image from '../image';
5+
import Image, {ImageProps} from '../image';
66

77
export enum FaderPosition {
88
LEFT = 'LEFT',
@@ -11,7 +11,7 @@ export enum FaderPosition {
1111
BOTTOM = 'BOTTOM'
1212
}
1313

14-
export type FaderProps = {
14+
export type FaderProps = Pick<ImageProps, 'supportRTL'> & {
1515
/**
1616
* Whether the fader is visible (default is true)
1717
*/
@@ -80,6 +80,7 @@ function Fader(props: FaderProps) {
8080
<View pointerEvents={'none'} style={styles.containerStyle}>
8181
{(props.visible || _.isUndefined(props.visible)) && (
8282
<Image
83+
supportRTL={props.supportRTL}
8384
source={styles.imageSource}
8485
tintColor={props.tintColor}
8586
style={styles.imageStyle}

src/components/tabController/FadedScrollView.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import React, {useCallback} from 'react';
22
import {ViewProps, ScrollView, ScrollViewProps, NativeSyntheticEvent, NativeScrollEvent} from 'react-native';
3-
import Fader from '../../components/fader';
3+
import Fader from '../fader';
44
import withScrollEnabler, {WithScrollEnablerProps} from '../../commons/withScrollEnabler';
55
import withScrollReached, {WithScrollReachedProps} from '../../commons/withScrollReached';
66
import forwardRef, {ForwardRefInjectedProps} from '../../commons/forwardRef';
7+
import {Constants} from '../../helpers';
78

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+
};
1113

1214
type ScrollReachedProps = FadedScrollViewProps & WithScrollReachedProps;
1315
type ScrollEnabledProps = ScrollReachedProps & WithScrollEnablerProps;
@@ -17,16 +19,20 @@ const FADER_SIZE = 76;
1719

1820
const FadedScrollView = (props: Props) => {
1921
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;
2230

23-
const onScroll = useCallback(
24-
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
25-
scrollReachedProps.onScroll(event);
31+
const onScroll = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => {
32+
scrollReachedProps.onScroll(event);
2633
propsOnScroll?.(event);
27-
},
28-
[scrollReachedProps.onScroll, propsOnScroll]
29-
);
34+
},
35+
[scrollReachedProps.onScroll, propsOnScroll]);
3036

3137
if (children) {
3238
return (
@@ -45,8 +51,8 @@ const FadedScrollView = (props: Props) => {
4551
>
4652
{children}
4753
</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/>
5056
</>
5157
);
5258
}

0 commit comments

Comments
 (0)