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

Commit

Permalink
feat: add gestureVelocityImpact as a prop for stack (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
osdnk authored Oct 5, 2019
1 parent a27ade8 commit 8294efc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/stack/src/views/Stack/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Props = ViewProps & {
close: TransitionSpec;
};
styleInterpolator: StackCardStyleInterpolator;
gestureVelocityImpact: number;
containerStyle?: StyleProp<ViewStyle>;
contentStyle?: StyleProp<ViewStyle>;
};
Expand Down Expand Up @@ -88,7 +89,7 @@ const MINUS_ONE_NODE = UNSET_NODE;
const DIRECTION_VERTICAL = -1;
const DIRECTION_HORIZONTAL = 1;

const SWIPE_VELOCITY_IMPACT = 0.3;
const GESTURE_VELOCITY_IMPACT = 0.3;

/**
* The distance of touch start from the edge of the screen where the gesture will be recognized
Expand Down Expand Up @@ -230,10 +231,16 @@ export default class Card extends React.Component<Props> {
overlayEnabled: Platform.OS !== 'ios',
shadowEnabled: true,
gestureEnabled: true,
gestureVelocityImpact: GESTURE_VELOCITY_IMPACT,
};

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

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

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

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

private isVisible = new Value<Binary>(TRUE);
private gestureVelocityImpact = new Value<number>(
this.props.gestureVelocityImpact
);
private isVisibleValue: Binary = TRUE;
private nextIsVisible = new Value<Binary | -1>(UNSET);

Expand Down Expand Up @@ -474,7 +488,7 @@ export default class Card extends React.Component<Props> {

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

private exec = [
Expand Down
3 changes: 3 additions & 0 deletions packages/stack/src/views/Stack/StackItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Props = TransitionPreset & {
headerTransparent?: boolean;
floatingHeaderHeight: number;
hasCustomHeader: boolean;
gestureVelocityImpact?: number;
};

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

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

0 comments on commit 8294efc

Please sign in to comment.