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

Commit

Permalink
feat: integrate InterationManager in stack
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis authored and satya164 committed Sep 8, 2019
1 parent f57a91c commit 9563a27
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/stack/src/views/Stack/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
StyleProp,
ViewStyle,
Platform,
InteractionManager,
} from 'react-native';
import Animated from 'react-native-reanimated';
import {
Expand Down Expand Up @@ -262,6 +263,8 @@ export default class Card extends React.Component<Props> {
}

componentWillUnmount(): void {
this.handleEndInteraction();

// It might sometimes happen than animation will be unmounted
// during running. However, we need to invoke listener onClose
// manually in this case
Expand Down Expand Up @@ -342,7 +345,24 @@ export default class Card extends React.Component<Props> {
finished: new Value(FALSE),
};

private interactionHandle: number | undefined;

private handleStartInteraction = () => {
if (this.interactionHandle === undefined) {
this.interactionHandle = InteractionManager.createInteractionHandle();
}
};

private handleEndInteraction = () => {
if (this.interactionHandle !== undefined) {
InteractionManager.clearInteractionHandle(this.interactionHandle);
this.interactionHandle = undefined;
}
};

private handleTransitionEnd = () => {
this.handleEndInteraction();

this.isRunningAnimation = false;
this.interpolatedStyle = this.getInterpolatedStyle(
this.props.styleInterpolator,
Expand Down Expand Up @@ -380,6 +400,8 @@ export default class Card extends React.Component<Props> {
set(this.isVisible, isVisible),
startClock(this.clock),
call([this.isVisible], ([value]: ReadonlyArray<Binary>) => {
this.handleStartInteraction();

const { onTransitionStart } = this.props;
this.noAnimationStartedSoFar = false;
this.isRunningAnimation = true;
Expand Down Expand Up @@ -517,8 +539,12 @@ export default class Card extends React.Component<Props> {
} = this.props;

if (isSwiping === TRUE) {
this.handleStartInteraction();

onGestureBegin && onGestureBegin();
} else {
this.handleEndInteraction();

if (isSwipeCancelled === TRUE) {
onGestureCanceled && onGestureCanceled();
} else {
Expand Down

0 comments on commit 9563a27

Please sign in to comment.