Skip to content

Drawer - fix leftToggle for RTL #1673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/components/drawer/Swipeable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Props = {
disableHaptic?: boolean
};

type StateType = {
type State = {
dragX: Animated.Value,
rowTranslation: Animated.Value,
leftWidth: number | typeof undefined,
Expand All @@ -71,7 +71,7 @@ type StateType = {

export type SwipeableProps = Props;

export default class Swipeable extends Component<Props, StateType> {
export default class Swipeable extends Component<Props, State> {
static displayName = 'IGNORE';
static defaultProps = {
friction: 1,
Expand Down Expand Up @@ -167,7 +167,6 @@ export default class Swipeable extends Component<Props, StateType> {
leftWidth + (overshootLeft || overshootFriction > 1 ? 1 : 0)
],
});

return transX;
}

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

let toValue = 0;
if (this.rowState === 0) {
if (this._hasLeftActions && onToggleSwipeLeft && translationX > rowWidth * LEFT_TOGGLE_THRESHOLD && !this.dragThresholdReached) {
if (Constants.isRTL && this._hasLeftActions && onToggleSwipeLeft && translationX < -(rowWidth * LEFT_TOGGLE_THRESHOLD) && !this.dragThresholdReached) {
// Swipe left toggle RTL
toValue = -(rowWidth * LEFT_TOGGLE_THRESHOLD);
} else if (this._hasLeftActions && onToggleSwipeLeft && translationX > rowWidth * LEFT_TOGGLE_THRESHOLD && !this.dragThresholdReached) {
// Swipe left toggle
toValue = rowWidth * LEFT_TOGGLE_THRESHOLD;
} else if (!onToggleSwipeLeft && fullSwipeLeft && translationX > rowWidth * fullLeftThreshold) {
Expand Down Expand Up @@ -299,6 +301,7 @@ export default class Swipeable extends Component<Props, StateType> {
toValue = -rightWidth;
}
}

this._animateRow(startOffsetX, toValue, velocityX / friction);
};

Expand Down Expand Up @@ -336,6 +339,7 @@ export default class Swipeable extends Component<Props, StateType> {
...animationOptions
}).start(({finished}) => {
if (finished) {
// Final Callbacks
if (toValue === rowWidth && onFullSwipeLeft) {
onFullSwipeLeft();
} else if (toValue === -rowWidth && onFullSwipeRight) {
Expand All @@ -354,7 +358,12 @@ export default class Swipeable extends Component<Props, StateType> {
}
});

if ((toValue === rowWidth * LEFT_TOGGLE_THRESHOLD || this.dragThresholdReached) && onToggleSwipeLeft) {
// Transition Callbacks
if (Constants.isRTL && this._hasLeftActions && onToggleSwipeLeft && (toValue === -(rowWidth * LEFT_TOGGLE_THRESHOLD) || this.dragThresholdReached)) {
// left toggle RTL
onToggleSwipeLeft({rowWidth, leftWidth, released: true, triggerHaptic: !this.dragThresholdReached});
} else if (this._hasLeftActions && onToggleSwipeLeft && (toValue === rowWidth * LEFT_TOGGLE_THRESHOLD || this.dragThresholdReached)) {
// left toggle
onToggleSwipeLeft({rowWidth, leftWidth, released: true, triggerHaptic: !this.dragThresholdReached});
this.dragThresholdReached = false;
} else if (toValue === rowWidth && onWillFullSwipeLeft) {
Expand Down Expand Up @@ -405,9 +414,10 @@ export default class Swipeable extends Component<Props, StateType> {

toggleLeft = () => {
// Programmatically left toggle
if (this._hasLeftActions) {
const shouldAnimate = Constants.isRTL ? this._hasRightActions : this._hasLeftActions;
if (shouldAnimate) {
const {rowWidth} = this.state;
this._animateRow(this._currentOffset(), rowWidth * LEFT_TOGGLE_THRESHOLD);
this._animateRow(this._currentOffset(), (rowWidth * LEFT_TOGGLE_THRESHOLD) * (Constants.isRTL ? -1 : 1));
}
};

Expand Down