5
5
* LICENSE file in the root directory of this source tree.
6
6
*
7
7
* @format
8
- * @flow
8
+ * @flow strict-local
9
9
*/
10
10
11
11
'use strict' ;
@@ -18,7 +18,6 @@ const ScrollResponder = require('ScrollResponder');
18
18
const ScrollViewStickyHeader = require ( 'ScrollViewStickyHeader' ) ;
19
19
const StyleSheet = require ( 'StyleSheet' ) ;
20
20
const View = require ( 'View' ) ;
21
- const InternalScrollViewType = require ( 'InternalScrollViewType' ) ;
22
21
23
22
const dismissKeyboard = require ( 'dismissKeyboard' ) ;
24
23
const flattenStyle = require ( 'flattenStyle' ) ;
@@ -27,7 +26,7 @@ const processDecelerationRate = require('processDecelerationRate');
27
26
const requireNativeComponent = require ( 'requireNativeComponent' ) ;
28
27
const resolveAssetSource = require ( 'resolveAssetSource' ) ;
29
28
30
- import type { PressEvent } from 'CoreEventTypes' ;
29
+ import type { PressEvent , ScrollEvent , LayoutEvent } from 'CoreEventTypes' ;
31
30
import type { EdgeInsetsProp } from 'EdgeInsetsPropType' ;
32
31
import type { NativeMethodsMixinType } from 'ReactNativeTypes' ;
33
32
import type { ViewStyleProp } from 'StyleSheet' ;
@@ -227,7 +226,7 @@ type IOSProps = $ReadOnly<{|
227
226
* Fires when the scroll view scrolls to top after the status bar has been tapped
228
227
* @platform ios
229
228
*/
230
- onScrollToTop ?: ? Function ,
229
+ onScrollToTop ?: ( event : ScrollEvent ) => void ,
231
230
/**
232
231
* When true, shows a horizontal scroll indicator.
233
232
* The default value is true.
@@ -410,33 +409,30 @@ export type Props = $ReadOnly<{|
410
409
* - `false`, deprecated, use 'never' instead
411
410
* - `true`, deprecated, use 'always' instead
412
411
*/
413
- /* $FlowFixMe(>=0.92.0 site=react_native_fb) This comment suppresses an error
414
- * found when Flow v0.92 was deployed. To see the error, delete this comment
415
- * and run Flow. */
416
412
keyboardShouldPersistTaps ?: ?( 'always' | 'never' | 'handled' | false | true ) ,
417
413
/**
418
414
* Called when the momentum scroll starts (scroll which occurs as the ScrollView glides to a stop).
419
415
*/
420
- onMomentumScrollBegin ?: ? Function ,
416
+ onMomentumScrollBegin ?: ( event : ScrollEvent ) => void ,
421
417
/**
422
418
* Called when the momentum scroll ends (scroll which occurs as the ScrollView glides to a stop).
423
419
*/
424
- onMomentumScrollEnd ?: ? Function ,
420
+ onMomentumScrollEnd ?: ( event : ScrollEvent ) => void ,
425
421
426
422
/**
427
423
* Fires at most once per frame during scrolling. The frequency of the
428
424
* events can be controlled using the `scrollEventThrottle` prop.
429
425
*/
430
- onScroll ?: ? Function ,
426
+ onScroll ?: ( event : ScrollEvent ) => void ,
431
427
/**
432
428
* Called when the user begins to drag the scroll view.
433
429
*/
434
- onScrollBeginDrag ?: ? Function ,
430
+ onScrollBeginDrag ?: ( event : ScrollEvent ) => void ,
435
431
/**
436
432
* Called when the user stops dragging the scroll view and it either stops
437
433
* or begins to glide.
438
434
*/
439
- onScrollEndDrag ?: ? Function ,
435
+ onScrollEndDrag ?: ( event : ScrollEvent ) => void ,
440
436
/**
441
437
* Called when scrollable content view of the ScrollView changes.
442
438
*
@@ -446,7 +442,7 @@ export type Props = $ReadOnly<{|
446
442
* It's implemented using onLayout handler attached to the content container
447
443
* which this ScrollView renders.
448
444
*/
449
- onContentSizeChange ?: ? Function ,
445
+ onContentSizeChange ?: ( contentWidth : number , contentHeight : number ) => void ,
450
446
onKeyboardDidShow ?: ( event : PressEvent ) => void ,
451
447
/**
452
448
* When true, the scroll view stops on multiples of the scroll view's size
@@ -525,6 +521,7 @@ export type Props = $ReadOnly<{|
525
521
*
526
522
* See [RefreshControl](docs/refreshcontrol.html).
527
523
*/
524
+ // $FlowFixMe - how to handle generic type without existential opereator?
528
525
refreshControl ?: ?React . Element < any > ,
529
526
children ?: React . Node ,
530
527
| } > ;
@@ -598,8 +595,8 @@ class ScrollView extends React.Component<Props, State> {
598
595
*/
599
596
_scrollResponder : typeof ScrollResponder . Mixin = createScrollResponder ( this ) ;
600
597
601
- constructor ( ... args ) {
602
- super ( ... args ) ;
598
+ constructor ( props : Props ) {
599
+ super ( props ) ;
603
600
604
601
/**
605
602
* Part 2: Removing ScrollResponder.Mixin
@@ -617,6 +614,7 @@ class ScrollView extends React.Component<Props, State> {
617
614
typeof ScrollResponder . Mixin [ key ] === 'function' &&
618
615
key . startsWith ( 'scrollResponder' )
619
616
) {
617
+ // $FlowFixMe - dynamically adding properties to a class
620
618
( this : any ) [ key ] = ScrollResponder . Mixin [ key ] . bind ( this ) ;
621
619
}
622
620
}
@@ -630,6 +628,7 @@ class ScrollView extends React.Component<Props, State> {
630
628
Object . keys ( ScrollResponder . Mixin )
631
629
. filter ( key => typeof ScrollResponder . Mixin [ key ] !== 'function ')
632
630
. forEach ( key => {
631
+ // $FlowFixMe - dynamically adding properties to a class
633
632
( this : any ) [ key ] = ScrollResponder . Mixin [ key ] ;
634
633
} ) ;
635
634
}
@@ -685,7 +684,7 @@ class ScrollView extends React.Component<Props, State> {
685
684
}
686
685
}
687
686
688
- setNativeProps ( props : Object ) {
687
+ setNativeProps ( props : { [ key : string ] : mixed } ) {
689
688
this . _scrollViewRef && this . _scrollViewRef . setNativeProps ( props ) ;
690
689
}
691
690
@@ -699,17 +698,18 @@ class ScrollView extends React.Component<Props, State> {
699
698
...typeof ScrollView ,
700
699
...typeof ScrollResponder . Mixin ,
701
700
} {
701
+ // $FlowFixMe - overriding type to include ScrollResponder.Mixin
702
702
return ( ( this : any ) : {
703
703
...typeof ScrollView ,
704
704
...typeof ScrollResponder . Mixin ,
705
705
} ) ;
706
706
}
707
707
708
- getScrollableNode ( ) : any {
708
+ getScrollableNode ( ) : ? number {
709
709
return ReactNative . findNodeHandle ( this . _scrollViewRef ) ;
710
710
}
711
711
712
- getInnerViewNode ( ) : any {
712
+ getInnerViewNode ( ) : ? number {
713
713
return ReactNative . findNodeHandle ( this . _innerViewRef ) ;
714
714
}
715
715
@@ -725,17 +725,23 @@ class ScrollView extends React.Component<Props, State> {
725
725
* This is deprecated due to ambiguity (y before x), and SHOULD NOT BE USED.
726
726
*/
727
727
scrollTo (
728
- y ?: number | { x ?: number , y ?: number , animated ?: boolean } ,
729
- x ?: number ,
730
- animated ? : boolean ,
728
+ options ?: { x ?: number , y ?: number , animated ?: boolean } | number ,
729
+ deprecatedX ?: number ,
730
+ deprecatedAnimated ? : boolean ,
731
731
) {
732
- if ( typeof y === 'number' ) {
732
+ let x , y , animated ;
733
+ if ( typeof options === 'number' ) {
733
734
console . warn (
734
735
'`scrollTo(y, x, animated)` is deprecated. Use `scrollTo({x: 5, y: 5, ' +
735
736
'animated: true})` instead.' ,
736
737
) ;
737
- } else {
738
- ( { x, y, animated} = y || { } ) ;
738
+ y = options ;
739
+ x = deprecatedX ;
740
+ animated = deprecatedAnimated ;
741
+ } else if ( options ) {
742
+ y = options . y ;
743
+ x = options . x ;
744
+ animated = options . animated ;
739
745
}
740
746
this . _scrollResponder . scrollResponderScrollTo ( {
741
747
x : x || 0 ,
@@ -832,7 +838,7 @@ class ScrollView extends React.Component<Props, State> {
832
838
}
833
839
}
834
840
835
- _handleScroll = ( e : Object ) => {
841
+ _handleScroll = ( e : ScrollEvent ) => {
836
842
if ( __DEV__ ) {
837
843
if (
838
844
this . props . onScroll &&
@@ -859,16 +865,16 @@ class ScrollView extends React.Component<Props, State> {
859
865
this . _scrollResponder . scrollResponderHandleScroll ( e ) ;
860
866
} ;
861
867
862
- _handleLayout = ( e : Object ) => {
863
- if ( this . props . invertStickyHeaders ) {
868
+ _handleLayout = ( e : LayoutEvent ) => {
869
+ if ( this . props . invertStickyHeaders === true ) {
864
870
this . setState ( { layoutHeight : e . nativeEvent . layout . height } ) ;
865
871
}
866
872
if ( this . props . onLayout ) {
867
873
this . props . onLayout ( e ) ;
868
874
}
869
875
} ;
870
876
871
- _handleContentOnLayout = ( e : Object ) => {
877
+ _handleContentOnLayout = ( e : LayoutEvent ) => {
872
878
const { width, height} = e . nativeEvent . layout ;
873
879
this . props . onContentSizeChange &&
874
880
this . props . onContentSizeChange ( width , height ) ;
@@ -888,7 +894,7 @@ class ScrollView extends React.Component<Props, State> {
888
894
let ScrollViewClass ;
889
895
let ScrollContentContainerViewClass ;
890
896
if ( Platform . OS === 'android' ) {
891
- if ( this . props . horizontal ) {
897
+ if ( this . props . horizontal === true ) {
892
898
ScrollViewClass = AndroidHorizontalScrollView ;
893
899
ScrollContentContainerViewClass = AndroidHorizontalScrollContentView ;
894
900
} else {
@@ -911,10 +917,10 @@ class ScrollView extends React.Component<Props, State> {
911
917
) ;
912
918
913
919
const contentContainerStyle = [
914
- this . props . horizontal && styles . contentContainerHorizontal ,
920
+ this . props . horizontal === true && styles . contentContainerHorizontal ,
915
921
this . props . contentContainerStyle ,
916
922
] ;
917
- if ( __DEV__ && this . props . style ) {
923
+ if ( __DEV__ && this . props . style !== undefined ) {
918
924
const style = flattenStyle ( this . props . style ) ;
919
925
const childLayoutProps = [ 'alignItems' , 'justifyContent' ] . filter (
920
926
prop => style && style [ prop ] !== undefined ,
@@ -966,7 +972,7 @@ class ScrollView extends React.Component<Props, State> {
966
972
}
967
973
968
974
const hasStickyHeaders =
969
- stickyHeaderIndices && stickyHeaderIndices . length > 0 ;
975
+ Array . isArray ( stickyHeaderIndices ) && stickyHeaderIndices . length > 0 ;
970
976
971
977
const contentContainer = (
972
978
< ScrollContentContainerViewClass
@@ -999,14 +1005,15 @@ class ScrollView extends React.Component<Props, State> {
999
1005
const DEPRECATED_sendUpdatedChildFrames = ! ! this . props
1000
1006
. DEPRECATED_sendUpdatedChildFrames ;
1001
1007
1002
- const baseStyle = this . props . horizontal
1003
- ? styles . baseHorizontal
1004
- : styles . baseVertical ;
1008
+ const baseStyle =
1009
+ this . props . horizontal === true
1010
+ ? styles . baseHorizontal
1011
+ : styles . baseVertical ;
1005
1012
const props = {
1006
1013
...this . props ,
1007
1014
alwaysBounceHorizontal,
1008
1015
alwaysBounceVertical,
1009
- style : ( [ baseStyle , this . props . style ] : ? Array < any > ) ,
1016
+ style : [ baseStyle , this . props . style ] ,
1010
1017
// Override the onContentSizeChange from props, since this event can
1011
1018
// bubble up from TextInputs
1012
1019
onContentSizeChange : null ,
@@ -1057,12 +1064,12 @@ class ScrollView extends React.Component<Props, State> {
1057
1064
pagingEnabled : Platform . select ( {
1058
1065
// on iOS, pagingEnabled must be set to false to have snapToInterval / snapToOffsets work
1059
1066
ios :
1060
- this . props . pagingEnabled &&
1067
+ this . props . pagingEnabled === true &&
1061
1068
this . props . snapToInterval == null &&
1062
1069
this . props . snapToOffsets == null ,
1063
1070
// on Android, pagingEnabled must be set to true to have snapToInterval / snapToOffsets work
1064
1071
android :
1065
- this . props . pagingEnabled ||
1072
+ this . props . pagingEnabled === true ||
1066
1073
this . props . snapToInterval != null ||
1067
1074
this . props . snapToOffsets != null ,
1068
1075
} ) ,
@@ -1115,10 +1122,6 @@ class ScrollView extends React.Component<Props, State> {
1115
1122
}
1116
1123
}
1117
1124
1118
- const TypedScrollView = ( ( ScrollView : any ) : Class <
1119
- InternalScrollViewType < Props > ,
1120
- > ) ;
1121
-
1122
1125
const styles = StyleSheet . create ( {
1123
1126
baseVertical : {
1124
1127
flexGrow : 1 ,
@@ -1137,4 +1140,4 @@ const styles = StyleSheet.create({
1137
1140
} ,
1138
1141
} ) ;
1139
1142
1140
- module . exports = TypedScrollView ;
1143
+ module . exports = ScrollView ;
0 commit comments