@@ -24,6 +24,8 @@ const warning = require('fbjs/lib/warning');
24
24
25
25
const { ScrollViewManager} = require ( 'NativeModules' ) ;
26
26
27
+ import type { PressEvent , ScrollEvent } from 'CoreEventTypes' ;
28
+ import type { KeyboardEvent } from 'Keyboard' ;
27
29
import type EmitterSubscription from 'EmitterSubscription' ;
28
30
29
31
/**
@@ -113,7 +115,6 @@ type State = {
113
115
observedScrollSinceBecomingResponder : boolean ,
114
116
becameResponderWhileAnimating : boolean ,
115
117
} ;
116
- type Event = Object ;
117
118
118
119
const ScrollResponderMixin = {
119
120
_subscriptionKeyboardWillShow : ( null : ?EmitterSubscription ) ,
@@ -168,7 +169,9 @@ const ScrollResponderMixin = {
168
169
* true.
169
170
*
170
171
*/
171
- scrollResponderHandleStartShouldSetResponder : function ( e : Event ) : boolean {
172
+ scrollResponderHandleStartShouldSetResponder : function (
173
+ e : PressEvent ,
174
+ ) : boolean {
172
175
const currentlyFocusedTextInput = TextInputState . currentlyFocusedField ( ) ;
173
176
174
177
if (
@@ -193,7 +196,7 @@ const ScrollResponderMixin = {
193
196
* Invoke this from an `onStartShouldSetResponderCapture` event.
194
197
*/
195
198
scrollResponderHandleStartShouldSetResponderCapture : function (
196
- e : Event ,
199
+ e : PressEvent ,
197
200
) : boolean {
198
201
// The scroll view should receive taps instead of its descendants if:
199
202
// * it is already animating/decelerating
@@ -212,6 +215,7 @@ const ScrollResponderMixin = {
212
215
if (
213
216
keyboardNeverPersistTaps &&
214
217
currentlyFocusedTextInput != null &&
218
+ e . target &&
215
219
! TextInputState . isTextInput ( e . target )
216
220
) {
217
221
return true ;
@@ -254,9 +258,9 @@ const ScrollResponderMixin = {
254
258
/**
255
259
* Invoke this from an `onTouchEnd` event.
256
260
*
257
- * @param {SyntheticEvent } e Event.
261
+ * @param {PressEvent } e Event.
258
262
*/
259
- scrollResponderHandleTouchEnd: function ( e : Event ) {
263
+ scrollResponderHandleTouchEnd: function ( e : PressEvent ) {
260
264
const nativeEvent = e . nativeEvent ;
261
265
this . state . isTouching = nativeEvent . touches . length !== 0 ;
262
266
this . props . onTouchEnd && this . props . onTouchEnd ( e ) ;
@@ -265,17 +269,17 @@ const ScrollResponderMixin = {
265
269
/**
266
270
* Invoke this from an `onTouchCancel` event.
267
271
*
268
- * @param {SyntheticEvent } e Event.
272
+ * @param {PressEvent } e Event.
269
273
*/
270
- scrollResponderHandleTouchCancel : function ( e : Event ) {
274
+ scrollResponderHandleTouchCancel : function ( e : PressEvent ) {
271
275
this . state . isTouching = false ;
272
276
this . props . onTouchCancel && this . props . onTouchCancel ( e ) ;
273
277
} ,
274
278
275
279
/**
276
280
* Invoke this from an `onResponderRelease` event.
277
281
*/
278
- scrollResponderHandleResponderRelease: function ( e : Event ) {
282
+ scrollResponderHandleResponderRelease: function ( e : PressEvent ) {
279
283
this . props . onResponderRelease && this . props . onResponderRelease ( e ) ;
280
284
281
285
// By default scroll views will unfocus a textField
@@ -295,15 +299,15 @@ const ScrollResponderMixin = {
295
299
}
296
300
} ,
297
301
298
- scrollResponderHandleScroll : function ( e : Event ) {
302
+ scrollResponderHandleScroll : function ( e : ScrollEvent ) {
299
303
this . state . observedScrollSinceBecomingResponder = true ;
300
304
this . props . onScroll && this . props . onScroll ( e ) ;
301
305
} ,
302
306
303
307
/**
304
308
* Invoke this from an `onResponderGrant` event.
305
309
*/
306
- scrollResponderHandleResponderGrant: function ( e : Event ) {
310
+ scrollResponderHandleResponderGrant: function ( e : ScrollEvent ) {
307
311
this . state . observedScrollSinceBecomingResponder = false ;
308
312
this . props . onResponderGrant && this . props . onResponderGrant ( e ) ;
309
313
this . state . becameResponderWhileAnimating = this . scrollResponderIsAnimating ( ) ;
@@ -316,15 +320,15 @@ const ScrollResponderMixin = {
316
320
*
317
321
* Invoke this from an `onScrollBeginDrag` event.
318
322
*/
319
- scrollResponderHandleScrollBeginDrag : function ( e : Event ) {
323
+ scrollResponderHandleScrollBeginDrag : function ( e : ScrollEvent ) {
320
324
FrameRateLogger . beginScroll ( ) ; // TODO: track all scrolls after implementing onScrollEndAnimation
321
325
this . props . onScrollBeginDrag && this . props . onScrollBeginDrag ( e ) ;
322
326
} ,
323
327
324
328
/**
325
329
* Invoke this from an `onScrollEndDrag` event.
326
330
*/
327
- scrollResponderHandleScrollEndDrag: function ( e : Event ) {
331
+ scrollResponderHandleScrollEndDrag: function ( e : ScrollEvent ) {
328
332
const { velocity} = e . nativeEvent ;
329
333
// - If we are animating, then this is a "drag" that is stopping the scrollview and momentum end
330
334
// will fire.
@@ -343,15 +347,15 @@ const ScrollResponderMixin = {
343
347
/**
344
348
* Invoke this from an `onMomentumScrollBegin` event.
345
349
*/
346
- scrollResponderHandleMomentumScrollBegin : function ( e : Event ) {
350
+ scrollResponderHandleMomentumScrollBegin : function ( e : ScrollEvent ) {
347
351
this . state . lastMomentumScrollBeginTime = performanceNow ( ) ;
348
352
this . props . onMomentumScrollBegin && this . props . onMomentumScrollBegin ( e ) ;
349
353
} ,
350
354
351
355
/**
352
356
* Invoke this from an `onMomentumScrollEnd` event.
353
357
*/
354
- scrollResponderHandleMomentumScrollEnd: function ( e : Event ) {
358
+ scrollResponderHandleMomentumScrollEnd: function ( e : ScrollEvent ) {
355
359
FrameRateLogger . endScroll ( ) ;
356
360
this . state . lastMomentumScrollEndTime = performanceNow ( ) ;
357
361
this . props . onMomentumScrollEnd && this . props . onMomentumScrollEnd ( e ) ;
@@ -366,9 +370,9 @@ const ScrollResponderMixin = {
366
370
* responder). The `onResponderReject` won't fire in that case - it only
367
371
* fires when a *current* responder rejects our request.
368
372
*
369
- * @param {SyntheticEvent } e Touch Start event.
373
+ * @param {PressEvent } e Touch Start event.
370
374
*/
371
- scrollResponderHandleTouchStart : function ( e : Event ) {
375
+ scrollResponderHandleTouchStart : function ( e : PressEvent ) {
372
376
this . state . isTouching = true ;
373
377
this . props . onTouchStart && this . props . onTouchStart ( e ) ;
374
378
} ,
@@ -382,9 +386,9 @@ const ScrollResponderMixin = {
382
386
* responder). The `onResponderReject` won't fire in that case - it only
383
387
* fires when a *current* responder rejects our request.
384
388
*
385
- * @param {SyntheticEvent } e Touch Start event.
389
+ * @param {PressEvent } e Touch Start event.
386
390
*/
387
- scrollResponderHandleTouchMove : function ( e : Event ) {
391
+ scrollResponderHandleTouchMove : function ( e : PressEvent ) {
388
392
this . props . onTouchMove && this . props . onTouchMove ( e ) ;
389
393
} ,
390
394
@@ -409,7 +413,7 @@ const ScrollResponderMixin = {
409
413
* Components can pass what node to use by defining a `getScrollableNode`
410
414
* function otherwise `this` is used.
411
415
*/
412
- scrollResponderGetScrollableNode : function ( ) : any {
416
+ scrollResponderGetScrollableNode : function ( ) : ? number {
413
417
return this . getScrollableNode
414
418
? this . getScrollableNode ( )
415
419
: ReactNative . findNodeHandle ( this ) ;
@@ -527,14 +531,14 @@ const ScrollResponderMixin = {
527
531
* This method should be used as the callback to onFocus in a TextInputs'
528
532
* parent view. Note that any module using this mixin needs to return
529
533
* the parent view's ref in getScrollViewRef() in order to use this method.
530
- * @param {any } nodeHandle The TextInput node handle
534
+ * @param {number } nodeHandle The TextInput node handle
531
535
* @param {number } additionalOffset The scroll view's bottom "contentInset".
532
536
* Default is 0.
533
537
* @param {bool } preventNegativeScrolling Whether to allow pulling the content
534
538
* down to make it meet the keyboard's top. Default is false.
535
539
*/
536
540
scrollResponderScrollNativeHandleToKeyboard : function (
537
- nodeHandle : any ,
541
+ nodeHandle : number ,
538
542
additionalOffset ? : number ,
539
543
preventNegativeScrollOffset ? : boolean ,
540
544
) {
@@ -584,8 +588,8 @@ const ScrollResponderMixin = {
584
588
this . preventNegativeScrollOffset = false ;
585
589
} ,
586
590
587
- scrollResponderTextInputFocusError : function ( e : Event ) {
588
- console . error ( 'Error measuring text field: ' , e ) ;
591
+ scrollResponderTextInputFocusError : function ( msg : string ) {
592
+ console . error ( 'Error measuring text field: ' , msg ) ;
589
593
} ,
590
594
591
595
/**
@@ -667,17 +671,17 @@ const ScrollResponderMixin = {
667
671
* relevant to you. (For example, only if you receive these callbacks after
668
672
* you had explicitly focused a node etc).
669
673
*/
670
- scrollResponderKeyboardWillShow : function ( e : Event ) {
674
+ scrollResponderKeyboardWillShow : function ( e : KeyboardEvent ) {
671
675
this . keyboardWillOpenTo = e ;
672
676
this . props . onKeyboardWillShow && this . props . onKeyboardWillShow ( e ) ;
673
677
} ,
674
678
675
- scrollResponderKeyboardWillHide : function ( e : Event ) {
679
+ scrollResponderKeyboardWillHide : function ( e : KeyboardEvent ) {
676
680
this . keyboardWillOpenTo = null ;
677
681
this . props . onKeyboardWillHide && this . props . onKeyboardWillHide ( e ) ;
678
682
} ,
679
683
680
- scrollResponderKeyboardDidShow : function ( e : Event ) {
684
+ scrollResponderKeyboardDidShow : function ( e : KeyboardEvent ) {
681
685
// TODO(7693961): The event for DidShow is not available on iOS yet.
682
686
// Use the one from WillShow and do not assign.
683
687
if ( e ) {
@@ -686,7 +690,7 @@ const ScrollResponderMixin = {
686
690
this . props . onKeyboardDidShow && this . props . onKeyboardDidShow ( e ) ;
687
691
} ,
688
692
689
- scrollResponderKeyboardDidHide : function ( e : Event ) {
693
+ scrollResponderKeyboardDidHide : function ( e : KeyboardEvent ) {
690
694
this . keyboardWillOpenTo = null ;
691
695
this . props . onKeyboardDidHide && this . props . onKeyboardDidHide ( e ) ;
692
696
} ,
0 commit comments