refactor: use same type for animation context and interpolation props

This commit is contained in:
Satyajit Sahoo
2019-11-07 08:06:42 +01:00
parent c63259df37
commit 7aab6568eb
3 changed files with 28 additions and 37 deletions

View File

@@ -227,6 +227,7 @@ export type CardInterpolationProps = {
}; };
index: number; index: number;
closing: Animated.Node<0 | 1>; closing: Animated.Node<0 | 1>;
swiping: Animated.Node<0 | 1>;
layouts: { layouts: {
screen: Layout; screen: Layout;
}; };

View File

@@ -1,24 +1,6 @@
import * as React from 'react'; import * as React from 'react';
import Animated from 'react-native-reanimated'; import { CardInterpolationProps } from '../types';
import { Layout } from '../types';
type StackCardAnimationContextType = { export default React.createContext<CardInterpolationProps | undefined>(
current: { progress: Animated.Node<number> };
next?: { progress: Animated.Node<number> };
index: number;
closing: Animated.Node<0 | 1>;
swiping: Animated.Node<0 | 1>;
layouts: {
screen: Layout;
};
insets: {
top: number;
right: number;
bottom: number;
left: number;
};
};
export default React.createContext<StackCardAnimationContextType | undefined>(
undefined undefined
); );

View File

@@ -745,6 +745,7 @@ export default class Card extends React.Component<Props> {
current: { progress: current }, current: { progress: current },
next: next && { progress: next }, next: next && { progress: next },
closing: this.isClosing, closing: this.isClosing,
swiping: this.isSwiping,
layouts: { layouts: {
screen: layout, screen: layout,
}, },
@@ -779,20 +780,26 @@ export default class Card extends React.Component<Props> {
index: number, index: number,
current: Animated.Node<number>, current: Animated.Node<number>,
next: Animated.Node<number> | undefined, next: Animated.Node<number> | undefined,
isSwiping: Animated.Node<0 | 1>,
isClosing: Animated.Node<0 | 1>,
layout: Layout, layout: Layout,
insets: EdgeInsets insetTop: number,
insetRight: number,
insetBottom: number,
insetLeft: number
) => ({ ) => ({
index, index,
current: { progress: current }, current: { progress: current },
next: next && { progress: next }, next: next && { progress: next },
closing: isClosing, closing: this.isClosing,
swiping: isSwiping, swiping: this.isSwiping,
layouts: { layouts: {
screen: layout, screen: layout,
}, },
insets, insets: {
top: insetTop,
right: insetRight,
bottom: insetBottom,
left: insetLeft,
},
}) })
); );
@@ -878,6 +885,17 @@ export default class Card extends React.Component<Props> {
); );
} }
const animationContext = this.getCardAnimationContext(
index,
current,
next,
layout,
insets.top,
insets.right,
insets.bottom,
insets.left
);
const { const {
containerStyle, containerStyle,
cardStyle, cardStyle,
@@ -947,17 +965,7 @@ export default class Card extends React.Component<Props> {
contentStyle, contentStyle,
]} ]}
> >
<StackCardAnimationContext.Provider <StackCardAnimationContext.Provider value={animationContext}>
value={this.getCardAnimationContext(
index,
current,
next,
this.isClosing,
this.isSwiping,
this.props.layout,
this.props.insets
)}
>
{children} {children}
</StackCardAnimationContext.Provider> </StackCardAnimationContext.Provider>
</PointerEventsView> </PointerEventsView>