Skip to content

Commit 8294efc

Browse files
authored
feat: add gestureVelocityImpact as a prop for stack (facebook#123)
1 parent a27ade8 commit 8294efc

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

packages/stack/src/views/Stack/Card.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type Props = ViewProps & {
5555
close: TransitionSpec;
5656
};
5757
styleInterpolator: StackCardStyleInterpolator;
58+
gestureVelocityImpact: number;
5859
containerStyle?: StyleProp<ViewStyle>;
5960
contentStyle?: StyleProp<ViewStyle>;
6061
};
@@ -88,7 +89,7 @@ const MINUS_ONE_NODE = UNSET_NODE;
8889
const DIRECTION_VERTICAL = -1;
8990
const DIRECTION_HORIZONTAL = 1;
9091

91-
const SWIPE_VELOCITY_IMPACT = 0.3;
92+
const GESTURE_VELOCITY_IMPACT = 0.3;
9293

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

235237
componentDidUpdate(prevProps: Props) {
236-
const { layout, gestureDirection, closing } = this.props;
238+
const {
239+
layout,
240+
gestureDirection,
241+
closing,
242+
gestureVelocityImpact,
243+
} = this.props;
237244
const { width, height } = layout;
238245

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

254+
if (gestureVelocityImpact !== prevProps.gestureVelocityImpact) {
255+
this.gestureVelocityImpact.setValue(gestureVelocityImpact);
256+
}
257+
247258
if (gestureDirection !== prevProps.gestureDirection) {
248259
this.direction.setValue(
249260
gestureDirection === 'vertical'
@@ -279,6 +290,9 @@ export default class Card extends React.Component<Props> {
279290
}
280291

281292
private isVisible = new Value<Binary>(TRUE);
293+
private gestureVelocityImpact = new Value<number>(
294+
this.props.gestureVelocityImpact
295+
);
282296
private isVisibleValue: Binary = TRUE;
283297
private nextIsVisible = new Value<Binary | -1>(UNSET);
284298

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

475489
private extrapolatedPosition = add(
476490
this.gesture,
477-
multiply(this.velocity, SWIPE_VELOCITY_IMPACT)
491+
multiply(this.velocity, this.gestureVelocityImpact)
478492
);
479493

480494
private exec = [

packages/stack/src/views/Stack/StackItem.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type Props = TransitionPreset & {
5555
headerTransparent?: boolean;
5656
floatingHeaderHeight: number;
5757
hasCustomHeader: boolean;
58+
gestureVelocityImpact?: number;
5859
};
5960

6061
export default class StackItem extends React.PureComponent<Props> {
@@ -122,6 +123,7 @@ export default class StackItem extends React.PureComponent<Props> {
122123
transitionSpec,
123124
cardStyleInterpolator,
124125
headerStyleInterpolator,
126+
gestureVelocityImpact,
125127
} = this.props;
126128

127129
return (
@@ -156,6 +158,7 @@ export default class StackItem extends React.PureComponent<Props> {
156158
}
157159
contentStyle={cardStyle}
158160
style={StyleSheet.absoluteFill}
161+
gestureVelocityImpact={gestureVelocityImpact}
159162
>
160163
<View style={styles.container}>
161164
<View style={styles.scene}>

0 commit comments

Comments
 (0)