Skip to content

Commit 174313f

Browse files
authored
Drawer - block frame update for missing items (#1619)
* Drawer - block frame update for missing items * fix crash when swiping without right/left items * change func to const
1 parent 5f86d5e commit 174313f

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

src/components/drawer/Swipeable.tsx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ export default class Swipeable extends Component<Props, StateType> {
243243
}
244244
};
245245

246+
_hasLeftActions = this.props.renderLeftActions !== undefined;
247+
248+
_hasRightActions = this.props.renderRightActions !== undefined;
249+
246250
_handleRelease = nativeEvent => {
247251
const {velocityX, translationX: dragX} = nativeEvent;
248252
const {leftWidth = 0, rowWidth = 0} = this.state;
@@ -263,34 +267,38 @@ export default class Swipeable extends Component<Props, StateType> {
263267

264268
let toValue = 0;
265269
if (this.rowState === 0) {
266-
if (onToggleSwipeLeft && translationX > rowWidth * LEFT_TOGGLE_THRESHOLD && !this.dragThresholdReached) {
270+
if (this._hasLeftActions && onToggleSwipeLeft && translationX > rowWidth * LEFT_TOGGLE_THRESHOLD && !this.dragThresholdReached) {
267271
// Swipe left toggle
268272
toValue = rowWidth * LEFT_TOGGLE_THRESHOLD;
269273
} else if (!onToggleSwipeLeft && fullSwipeLeft && translationX > rowWidth * fullLeftThreshold) {
274+
// Full left swipe
270275
this._triggerHaptic();
271276
toValue = rowWidth;
272-
} else if (fullSwipeRight && translationX < -rowWidth * fullRightThreshold) {
277+
} else if (this._hasRightActions && fullSwipeRight && translationX < -rowWidth * fullRightThreshold) {
278+
// Full right swipe
273279
this._triggerHaptic();
274280
toValue = -rowWidth;
275-
} else if (translationX > leftThreshold) {
281+
} else if (this._hasLeftActions && translationX > leftThreshold) {
282+
// left swipe
276283
if (!onToggleSwipeLeft || onToggleSwipeLeft && translationX < rowWidth * LEFT_TOGGLE_THRESHOLD) {
284+
// left swipe with toggle
277285
toValue = leftWidth;
278286
}
279-
} else if (translationX < -rightThreshold) {
287+
} else if (this._hasRightActions && translationX < -rightThreshold) {
288+
// right swipe
280289
toValue = -rightWidth;
281290
}
282291
} else if (this.rowState === 1) {
283-
// swiped to left
292+
// swiped to the right (left swipe)
284293
if (translationX > -leftThreshold) {
285294
toValue = leftWidth;
286295
}
287296
} else {
288-
// swiped to right
297+
// swiped to the left (right swipe)
289298
if (translationX < rightThreshold) {
290299
toValue = -rightWidth;
291300
}
292301
}
293-
294302
this._animateRow(startOffsetX, toValue, velocityX / friction);
295303
};
296304

@@ -389,14 +397,18 @@ export default class Swipeable extends Component<Props, StateType> {
389397
};
390398

391399
openLeftFull = () => {
392-
const {rowWidth} = this.state;
393-
this._animateRow(this._currentOffset(), rowWidth);
400+
if (this._hasLeftActions) {
401+
const {rowWidth} = this.state;
402+
this._animateRow(this._currentOffset(), rowWidth);
403+
}
394404
};
395405

396406
toggleLeft = () => {
397407
// Programmatically left toggle
398-
const {rowWidth} = this.state;
399-
this._animateRow(this._currentOffset(), rowWidth * LEFT_TOGGLE_THRESHOLD);
408+
if (this._hasLeftActions) {
409+
const {rowWidth} = this.state;
410+
this._animateRow(this._currentOffset(), rowWidth * LEFT_TOGGLE_THRESHOLD);
411+
}
400412
};
401413

402414
openRight = () => {
@@ -407,8 +419,10 @@ export default class Swipeable extends Component<Props, StateType> {
407419
};
408420

409421
openRightFull = () => {
410-
const {rowWidth} = this.state;
411-
this._animateRow(this._currentOffset(), -rowWidth);
422+
if (this._hasRightActions) {
423+
const {rowWidth} = this.state;
424+
this._animateRow(this._currentOffset(), -rowWidth);
425+
}
412426
};
413427

414428
_onRowLayout = ({nativeEvent}) => this.handleMeasure('rowWidth', nativeEvent);
@@ -432,8 +446,8 @@ export default class Swipeable extends Component<Props, StateType> {
432446
break;
433447
}
434448

435-
const leftRender = this.props.renderLeftActions ? this.leftWidth : true;
436-
const rightRender = this.props.renderRightActions ? this.rightOffset : true;
449+
const leftRender = this._hasLeftActions ? this.leftWidth : true;
450+
const rightRender = this._hasRightActions ? this.rightOffset : true;
437451

438452
if (this.rowWidth && leftRender && rightRender) {
439453
this.setState({
@@ -457,7 +471,7 @@ export default class Swipeable extends Component<Props, StateType> {
457471
testID
458472
} = this.props;
459473

460-
const left = renderLeftActions && (
474+
const left = this._hasLeftActions && (
461475
<Animated.View
462476
style={[
463477
styles.leftActions,
@@ -470,7 +484,7 @@ export default class Swipeable extends Component<Props, StateType> {
470484
</Animated.View>
471485
);
472486

473-
const right = renderRightActions && (
487+
const right = this._hasRightActions && (
474488
<Animated.View
475489
style={[
476490
styles.rightActions,

0 commit comments

Comments
 (0)