Skip to content

Commit 3f79b2a

Browse files
empyricalfacebook-github-bot
authored andcommitted
Add flow types to PanResponder (#21291)
Summary: This PR adds flow types to the `PanResponder` module. It is part of my effort to flowtype the `Swipable*` classes. A new `touchHistory` field had to be added to `SyntheticEvent` as well. Pull Request resolved: #21291 Reviewed By: TheSavior Differential Revision: D10013265 Pulled By: RSNara fbshipit-source-id: 3cd65a0eae41c756d1605e6771588d820f040e2a
1 parent 57041ee commit 3f79b2a

File tree

3 files changed

+195
-61
lines changed

3 files changed

+195
-61
lines changed

Libraries/Experimental/SwipeableRow/SwipeableRow.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const View = require('View');
2525
const createReactClass = require('create-react-class');
2626
const emptyFunction = require('fbjs/lib/emptyFunction');
2727

28+
import type {LayoutEvent, PressEvent} from 'CoreEventTypes';
29+
import type {GestureState} from 'PanResponder';
30+
2831
const IS_RTL = I18nManager.isRTL;
2932

3033
// NOTE: Eventually convert these consts to an input object of configurations
@@ -204,24 +207,27 @@ const SwipeableRow = createReactClass({
204207
this._animateToClosedPosition();
205208
},
206209

207-
_onSwipeableViewLayout(event: Object): void {
210+
_onSwipeableViewLayout(event: LayoutEvent): void {
208211
this.setState({
209212
isSwipeableViewRendered: true,
210213
rowHeight: event.nativeEvent.layout.height,
211214
});
212215
},
213216

214217
_handleMoveShouldSetPanResponderCapture(
215-
event: Object,
216-
gestureState: Object,
218+
event: PressEvent,
219+
gestureState: GestureState,
217220
): boolean {
218221
// Decides whether a swipe is responded to by this component or its child
219222
return gestureState.dy < 10 && this._isValidSwipe(gestureState);
220223
},
221224

222-
_handlePanResponderGrant(event: Object, gestureState: Object): void {},
225+
_handlePanResponderGrant(
226+
event: PressEvent,
227+
gestureState: GestureState,
228+
): void {},
223229

224-
_handlePanResponderMove(event: Object, gestureState: Object): void {
230+
_handlePanResponderMove(event: PressEvent, gestureState: GestureState): void {
225231
if (this._isSwipingExcessivelyRightFromClosedPosition(gestureState)) {
226232
return;
227233
}
@@ -235,22 +241,24 @@ const SwipeableRow = createReactClass({
235241
}
236242
},
237243

238-
_isSwipingRightFromClosed(gestureState: Object): boolean {
244+
_isSwipingRightFromClosed(gestureState: GestureState): boolean {
239245
const gestureStateDx = IS_RTL ? -gestureState.dx : gestureState.dx;
240246
return this._previousLeft === CLOSED_LEFT_POSITION && gestureStateDx > 0;
241247
},
242248

243-
_swipeFullSpeed(gestureState: Object): void {
249+
_swipeFullSpeed(gestureState: GestureState): void {
244250
this.state.currentLeft.setValue(this._previousLeft + gestureState.dx);
245251
},
246252

247-
_swipeSlowSpeed(gestureState: Object): void {
253+
_swipeSlowSpeed(gestureState: GestureState): void {
248254
this.state.currentLeft.setValue(
249255
this._previousLeft + gestureState.dx / SLOW_SPEED_SWIPE_FACTOR,
250256
);
251257
},
252258

253-
_isSwipingExcessivelyRightFromClosedPosition(gestureState: Object): boolean {
259+
_isSwipingExcessivelyRightFromClosedPosition(
260+
gestureState: GestureState,
261+
): boolean {
254262
/**
255263
* We want to allow a BIT of right swipe, to allow users to know that
256264
* swiping is available, but swiping right does not do anything
@@ -264,8 +272,8 @@ const SwipeableRow = createReactClass({
264272
},
265273

266274
_onPanResponderTerminationRequest(
267-
event: Object,
268-
gestureState: Object,
275+
event: PressEvent,
276+
gestureState: GestureState,
269277
): boolean {
270278
return false;
271279
},
@@ -338,7 +346,7 @@ const SwipeableRow = createReactClass({
338346
},
339347

340348
// Ignore swipes due to user's finger moving slightly when tapping
341-
_isValidSwipe(gestureState: Object): boolean {
349+
_isValidSwipe(gestureState: GestureState): boolean {
342350
if (
343351
this.props.preventSwipeRight &&
344352
this._previousLeft === CLOSED_LEFT_POSITION &&
@@ -350,7 +358,7 @@ const SwipeableRow = createReactClass({
350358
return Math.abs(gestureState.dx) > HORIZONTAL_SWIPE_DISTANCE_THRESHOLD;
351359
},
352360

353-
_shouldAnimateRemainder(gestureState: Object): boolean {
361+
_shouldAnimateRemainder(gestureState: GestureState): boolean {
354362
/**
355363
* If user has swiped past a certain distance, animate the rest of the way
356364
* if they let go
@@ -361,7 +369,7 @@ const SwipeableRow = createReactClass({
361369
);
362370
},
363371

364-
_handlePanResponderEnd(event: Object, gestureState: Object): void {
372+
_handlePanResponderEnd(event: PressEvent, gestureState: GestureState): void {
365373
const horizontalDistance = IS_RTL ? -gestureState.dx : gestureState.dx;
366374
if (this._isSwipingRightFromClosed(gestureState)) {
367375
this.props.onOpen();

0 commit comments

Comments
 (0)