Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit b741de0

Browse files
janicduplessissatya164
authored andcommitted
feat: integrate 'InterationManager' in stack
1 parent ea4b467 commit b741de0

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/views/Stack/Card.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
StyleProp,
88
ViewStyle,
99
Platform,
10+
InteractionManager,
1011
} from 'react-native';
1112
import Animated from 'react-native-reanimated';
1213
import {
@@ -269,6 +270,8 @@ export default class Card extends React.Component<Props> {
269270
}
270271

271272
componentWillUnmount(): void {
273+
this.handleEndInteraction();
274+
272275
// It might sometimes happen than animation will be unmounted
273276
// during running. However, we need to invoke listener onClose
274277
// manually in this case
@@ -353,7 +356,24 @@ export default class Card extends React.Component<Props> {
353356
finished: new Value(FALSE),
354357
};
355358

359+
private interactionHandle: number | undefined;
360+
361+
private handleStartInteraction = () => {
362+
if (this.interactionHandle === undefined) {
363+
this.interactionHandle = InteractionManager.createInteractionHandle();
364+
}
365+
};
366+
367+
private handleEndInteraction = () => {
368+
if (this.interactionHandle !== undefined) {
369+
InteractionManager.clearInteractionHandle(this.interactionHandle);
370+
this.interactionHandle = undefined;
371+
}
372+
};
373+
356374
private handleTransitionEnd = () => {
375+
this.handleEndInteraction();
376+
357377
this.isRunningAnimation = false;
358378
this.interpolatedStyle = this.getInterpolatedStyle(
359379
this.props.styleInterpolator,
@@ -391,6 +411,8 @@ export default class Card extends React.Component<Props> {
391411
set(this.isVisible, isVisible),
392412
startClock(this.clock),
393413
call([this.isVisible], ([value]: ReadonlyArray<Binary>) => {
414+
this.handleStartInteraction();
415+
394416
const { onTransitionStart } = this.props;
395417
this.noAnimationStartedSoFar = false;
396418
this.isRunningAnimation = true;
@@ -532,8 +554,12 @@ export default class Card extends React.Component<Props> {
532554
} = this.props;
533555

534556
if (isSwiping === TRUE) {
557+
this.handleStartInteraction();
558+
535559
onGestureBegin && onGestureBegin();
536560
} else {
561+
this.handleEndInteraction();
562+
537563
if (isSwipeCancelled === TRUE) {
538564
onGestureCanceled && onGestureCanceled();
539565
} else {

0 commit comments

Comments
 (0)