Skip to content

Commit 9563a27

Browse files
janicduplessissatya164
authored andcommitted
feat: integrate InterationManager in stack
1 parent f57a91c commit 9563a27

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/stack/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 {
@@ -262,6 +263,8 @@ export default class Card extends React.Component<Props> {
262263
}
263264

264265
componentWillUnmount(): void {
266+
this.handleEndInteraction();
267+
265268
// It might sometimes happen than animation will be unmounted
266269
// during running. However, we need to invoke listener onClose
267270
// manually in this case
@@ -342,7 +345,24 @@ export default class Card extends React.Component<Props> {
342345
finished: new Value(FALSE),
343346
};
344347

348+
private interactionHandle: number | undefined;
349+
350+
private handleStartInteraction = () => {
351+
if (this.interactionHandle === undefined) {
352+
this.interactionHandle = InteractionManager.createInteractionHandle();
353+
}
354+
};
355+
356+
private handleEndInteraction = () => {
357+
if (this.interactionHandle !== undefined) {
358+
InteractionManager.clearInteractionHandle(this.interactionHandle);
359+
this.interactionHandle = undefined;
360+
}
361+
};
362+
345363
private handleTransitionEnd = () => {
364+
this.handleEndInteraction();
365+
346366
this.isRunningAnimation = false;
347367
this.interpolatedStyle = this.getInterpolatedStyle(
348368
this.props.styleInterpolator,
@@ -380,6 +400,8 @@ export default class Card extends React.Component<Props> {
380400
set(this.isVisible, isVisible),
381401
startClock(this.clock),
382402
call([this.isVisible], ([value]: ReadonlyArray<Binary>) => {
403+
this.handleStartInteraction();
404+
383405
const { onTransitionStart } = this.props;
384406
this.noAnimationStartedSoFar = false;
385407
this.isRunningAnimation = true;
@@ -517,8 +539,12 @@ export default class Card extends React.Component<Props> {
517539
} = this.props;
518540

519541
if (isSwiping === TRUE) {
542+
this.handleStartInteraction();
543+
520544
onGestureBegin && onGestureBegin();
521545
} else {
546+
this.handleEndInteraction();
547+
522548
if (isSwipeCancelled === TRUE) {
523549
onGestureCanceled && onGestureCanceled();
524550
} else {

0 commit comments

Comments
 (0)