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

feat: swipe velocity impact as prop #249

Merged
merged 9 commits into from
Oct 5, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Array [
"top": 0,
}
}
swipeVelocityImpact={0.3}
transitionSpec={
Object {
"close": Object {
Expand Down Expand Up @@ -209,6 +210,7 @@ Array [
"top": 0,
}
}
swipeVelocityImpact={0.3}
transitionSpec={
Object {
"close": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Array [
"top": 0,
}
}
swipeVelocityImpact={0.3}
transitionSpec={
Object {
"close": Object {
Expand Down Expand Up @@ -378,6 +379,7 @@ Array [
"top": 0,
}
}
swipeVelocityImpact={0.3}
transitionSpec={
Object {
"close": Object {
Expand Down
1 change: 1 addition & 0 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export type NavigationStackOptions = HeaderOptions &
};
onTransitionStart?: (props: TransitionCallbackProps) => void;
onTransitionEnd?: (props: TransitionCallbackProps) => void;
swipeVelocityImpact?: number;
};

export type NavigationStackConfig = {
Expand Down
39 changes: 29 additions & 10 deletions src/views/Stack/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Props = ViewProps & {
close: TransitionSpec;
};
styleInterpolator: CardStyleInterpolator;
swipeVelocityImpact: number;
containerStyle?: StyleProp<ViewStyle>;
contentStyle?: StyleProp<ViewStyle>;
};
Expand Down Expand Up @@ -232,10 +233,16 @@ export default class Card extends React.Component<Props> {
overlayEnabled: Platform.OS !== 'ios',
shadowEnabled: true,
gestureEnabled: true,
swipeVelocityImpact: SWIPE_VELOCITY_IMPACT,
};

componentDidUpdate(prevProps: Props) {
const { layout, gestureDirection, closing } = this.props;
const {
layout,
gestureDirection,
closing,
swipeVelocityImpact,
} = this.props;
const { width, height } = layout;

if (width !== prevProps.layout.width) {
Expand All @@ -246,6 +253,10 @@ export default class Card extends React.Component<Props> {
this.layout.height.setValue(height);
}

if (swipeVelocityImpact !== prevProps.swipeVelocityImpact) {
this.swipeVelocityImpact.setValue(swipeVelocityImpact);
}

if (gestureDirection !== prevProps.gestureDirection) {
this.direction.setValue(
gestureDirection === 'vertical' ||
Expand Down Expand Up @@ -285,6 +296,9 @@ export default class Card extends React.Component<Props> {
}

private isVisible = new Value<Binary>(TRUE);
private swipeVelocityImpact = new Value<number>(
this.props.swipeVelocityImpact
);
private isVisibleValue: Binary = TRUE;
private nextIsVisible = new Value<Binary | -1>(UNSET);
private verticalGestureDirection = new Value(
Expand Down Expand Up @@ -483,18 +497,19 @@ export default class Card extends React.Component<Props> {

private extrapolatedPosition = add(
this.gesture,
multiply(this.velocity, SWIPE_VELOCITY_IMPACT)
multiply(this.velocity, this.swipeVelocityImpact)
);

private exec = [
cond(
eq(this.direction, DIRECTION_HORIZONTAL),
set(
this.gesture,
set(
this.gesture,
cond(
eq(this.direction, DIRECTION_HORIZONTAL),
multiply(
this.gestureUntraversed,
I18nManager.isRTL ? MINUS_ONE_NODE : TRUE_NODE
)
),
this.gestureUntraversed
Comment on lines +504 to +512
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured out it's a bug here. We weren't updating this.gesture in vertical mode.

)
),
set(
Expand Down Expand Up @@ -593,9 +608,13 @@ export default class Card extends React.Component<Props> {
cond(
this.distance,
divide(
multiply(
this.gestureUntraversed,
I18nManager.isRTL ? MINUS_ONE_NODE : TRUE_NODE
cond(
eq(this.direction, DIRECTION_HORIZONTAL),
multiply(
this.gestureUntraversed,
I18nManager.isRTL ? MINUS_ONE_NODE : TRUE_NODE
),
this.gestureUntraversed
Comment on lines +611 to +617
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was another bug here. In RTL we were multiplying a gesture in vertical mode as well.

),
this.distance
),
Expand Down
2 changes: 2 additions & 0 deletions src/views/Stack/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export default class Stack extends React.Component<Props, State> {
transitionSpec = defaultTransitionPreset.transitionSpec,
cardStyleInterpolator = defaultTransitionPreset.cardStyleInterpolator,
headerStyleInterpolator = defaultTransitionPreset.headerStyleInterpolator,
swipeVelocityImpact,
} = descriptor
? descriptor.options
: ({} as NavigationStackOptions);
Expand Down Expand Up @@ -404,6 +405,7 @@ export default class Stack extends React.Component<Props, State> {
transitionSpec={transitionSpec}
cardStyleInterpolator={cardStyleInterpolator}
headerStyleInterpolator={headerStyleInterpolator}
swipeVelocityImpact={swipeVelocityImpact}
/>
</MaybeScreen>
);
Expand Down
3 changes: 3 additions & 0 deletions src/views/Stack/StackItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Props = TransitionPreset & {
headerTransparent?: boolean;
floatingHeaderHeight: number;
hasCustomHeader: boolean;
swipeVelocityImpact?: number;
};

export default class StackItem extends React.PureComponent<Props> {
Expand Down Expand Up @@ -120,6 +121,7 @@ export default class StackItem extends React.PureComponent<Props> {
transitionSpec,
cardStyleInterpolator,
headerStyleInterpolator,
swipeVelocityImpact,
} = this.props;

return (
Expand Down Expand Up @@ -153,6 +155,7 @@ export default class StackItem extends React.PureComponent<Props> {
}
contentStyle={cardStyle}
style={StyleSheet.absoluteFill}
swipeVelocityImpact={swipeVelocityImpact}
>
<View style={styles.container}>
<View style={styles.scene}>
Expand Down