Skip to content

Commit ebe62d3

Browse files
authored
Drawer - fix leftToggle for RTL (#1673)
* Drawer - fix leftToggle for RTL * fix leftToggle with no items
1 parent 1e9fac7 commit ebe62d3

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/components/drawer/Swipeable.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type Props = {
6161
disableHaptic?: boolean
6262
};
6363

64-
type StateType = {
64+
type State = {
6565
dragX: Animated.Value,
6666
rowTranslation: Animated.Value,
6767
leftWidth: number | typeof undefined,
@@ -71,7 +71,7 @@ type StateType = {
7171

7272
export type SwipeableProps = Props;
7373

74-
export default class Swipeable extends Component<Props, StateType> {
74+
export default class Swipeable extends Component<Props, State> {
7575
static displayName = 'IGNORE';
7676
static defaultProps = {
7777
friction: 1,
@@ -167,7 +167,6 @@ export default class Swipeable extends Component<Props, StateType> {
167167
leftWidth + (overshootLeft || overshootFriction > 1 ? 1 : 0)
168168
],
169169
});
170-
171170
return transX;
172171
}
173172

@@ -267,7 +266,10 @@ export default class Swipeable extends Component<Props, StateType> {
267266

268267
let toValue = 0;
269268
if (this.rowState === 0) {
270-
if (this._hasLeftActions && onToggleSwipeLeft && translationX > rowWidth * LEFT_TOGGLE_THRESHOLD && !this.dragThresholdReached) {
269+
if (Constants.isRTL && this._hasLeftActions && onToggleSwipeLeft && translationX < -(rowWidth * LEFT_TOGGLE_THRESHOLD) && !this.dragThresholdReached) {
270+
// Swipe left toggle RTL
271+
toValue = -(rowWidth * LEFT_TOGGLE_THRESHOLD);
272+
} else if (this._hasLeftActions && onToggleSwipeLeft && translationX > rowWidth * LEFT_TOGGLE_THRESHOLD && !this.dragThresholdReached) {
271273
// Swipe left toggle
272274
toValue = rowWidth * LEFT_TOGGLE_THRESHOLD;
273275
} else if (!onToggleSwipeLeft && fullSwipeLeft && translationX > rowWidth * fullLeftThreshold) {
@@ -299,6 +301,7 @@ export default class Swipeable extends Component<Props, StateType> {
299301
toValue = -rightWidth;
300302
}
301303
}
304+
302305
this._animateRow(startOffsetX, toValue, velocityX / friction);
303306
};
304307

@@ -336,6 +339,7 @@ export default class Swipeable extends Component<Props, StateType> {
336339
...animationOptions
337340
}).start(({finished}) => {
338341
if (finished) {
342+
// Final Callbacks
339343
if (toValue === rowWidth && onFullSwipeLeft) {
340344
onFullSwipeLeft();
341345
} else if (toValue === -rowWidth && onFullSwipeRight) {
@@ -354,7 +358,12 @@ export default class Swipeable extends Component<Props, StateType> {
354358
}
355359
});
356360

357-
if ((toValue === rowWidth * LEFT_TOGGLE_THRESHOLD || this.dragThresholdReached) && onToggleSwipeLeft) {
361+
// Transition Callbacks
362+
if (Constants.isRTL && this._hasLeftActions && onToggleSwipeLeft && (toValue === -(rowWidth * LEFT_TOGGLE_THRESHOLD) || this.dragThresholdReached)) {
363+
// left toggle RTL
364+
onToggleSwipeLeft({rowWidth, leftWidth, released: true, triggerHaptic: !this.dragThresholdReached});
365+
} else if (this._hasLeftActions && onToggleSwipeLeft && (toValue === rowWidth * LEFT_TOGGLE_THRESHOLD || this.dragThresholdReached)) {
366+
// left toggle
358367
onToggleSwipeLeft({rowWidth, leftWidth, released: true, triggerHaptic: !this.dragThresholdReached});
359368
this.dragThresholdReached = false;
360369
} else if (toValue === rowWidth && onWillFullSwipeLeft) {
@@ -405,9 +414,10 @@ export default class Swipeable extends Component<Props, StateType> {
405414

406415
toggleLeft = () => {
407416
// Programmatically left toggle
408-
if (this._hasLeftActions) {
417+
const shouldAnimate = Constants.isRTL ? this._hasRightActions : this._hasLeftActions;
418+
if (shouldAnimate) {
409419
const {rowWidth} = this.state;
410-
this._animateRow(this._currentOffset(), rowWidth * LEFT_TOGGLE_THRESHOLD);
420+
this._animateRow(this._currentOffset(), (rowWidth * LEFT_TOGGLE_THRESHOLD) * (Constants.isRTL ? -1 : 1));
411421
}
412422
};
413423

0 commit comments

Comments
 (0)