@@ -17,15 +17,14 @@ const COMMAND_SCROLL_TO = 1;
1717const COMMAND_SCROLL_TO_END = 2 ;
1818const COMMAND_FLASH_SCROLL_INDICATORS = 3 ;
1919
20-
2120type ScrollViewPropsWithRef = ScrollViewProps & React . RefAttributes < NativeScrollInstance | null > ;
2221type NativeScrollInstance = React . ComponentRef < NonNullable < typeof NativeInvertedScrollView > > ;
2322interface IScrollableMethods {
24- scrollTo ( options ?: { x ?: number ; y ?: number ; animated ?: boolean } ) : void ;
25- scrollToEnd ( options ?: { animated ?: boolean } ) : void ;
26- flashScrollIndicators ( ) : void ;
27- getScrollRef ( ) : NativeScrollInstance | null ;
28- setNativeProps ( props : object ) : void ;
23+ scrollTo ( options ?: { x ?: number ; y ?: number ; animated ?: boolean } ) : void ;
24+ scrollToEnd ( options ?: { animated ?: boolean } ) : void ;
25+ flashScrollIndicators ( ) : void ;
26+ getScrollRef ( ) : NativeScrollInstance | null ;
27+ setNativeProps ( props : object ) : void ;
2928}
3029
3130export type InvertedScrollViewRef = NativeScrollInstance & IScrollableMethods ;
@@ -37,89 +36,89 @@ const NativeInvertedScrollContentView = isAndroid
3736 : null ;
3837
3938const InvertedScrollView = forwardRef < InvertedScrollViewRef , ScrollViewProps > ( ( props , externalRef ) => {
40- const internalRef = useRef < NativeScrollInstance | null > ( null ) ;
41-
42- useLayoutEffect ( ( ) => {
43- const node = internalRef . current as any ;
44-
45- if ( node ) {
46-
47- // 1. Implementation of scrollTo
48- node . scrollTo = ( options ?: { x ?: number ; y ?: number ; animated ?: boolean } ) => {
49- const tag = findNodeHandle ( node ) ;
50- if ( tag != null ) {
51- const x = options ?. x || 0 ;
52- const y = options ?. y || 0 ;
53- const animated = options ?. animated !== false ;
54- UIManager . dispatchViewManagerCommand ( tag , COMMAND_SCROLL_TO , [ x , y , animated ] ) ;
55- }
56- } ;
57-
58- // 2. Implementation of scrollToEnd
59- node . scrollToEnd = ( options ?: { animated ?: boolean } ) => {
60- const tag = findNodeHandle ( node ) ;
61- if ( tag != null ) {
62- const animated = options ?. animated !== false ;
63- UIManager . dispatchViewManagerCommand ( tag , COMMAND_SCROLL_TO_END , [ animated ] ) ;
64- }
65- } ;
66-
67- // 3. Implementation of flashScrollIndicators
68- node . flashScrollIndicators = ( ) => {
69- const tag = findNodeHandle ( node as any ) ;
70- if ( tag !== null ) {
71- UIManager . dispatchViewManagerCommand ( tag , COMMAND_FLASH_SCROLL_INDICATORS , [ ] ) ;
72- }
73- } ;
74-
75- node . getScrollRef = ( ) => node ;
76-
77- if ( typeof node . setNativeProps !== 'function' ) {
78- node . setNativeProps = ( nativeProps : object ) => {
79- // Check again if the underlying node has the method hidden
80- if ( node && typeof ( node as any ) . setNativeProps === 'function' ) {
81- ( node as any ) . setNativeProps ( nativeProps ) ;
82- }
83- } ;
84- }
85- }
86- } ) ;
87-
88- // Callback Ref to handle merging internal and external refs
89- const setRef = ( node : NativeScrollInstance | null ) => {
90- internalRef . current = node ;
91-
92- if ( typeof externalRef === 'function' ) {
93- externalRef ( node as InvertedScrollViewRef ) ;
94- } else if ( externalRef ) {
95- ( externalRef as React . MutableRefObject < NativeScrollInstance | null > ) . current = node ;
96- }
97- } ;
98-
99- const {
100- children ,
101- contentContainerStyle ,
102- onContentSizeChange ,
103- removeClippedSubviews ,
104- maintainVisibleContentPosition ,
105- snapToAlignment ,
106- stickyHeaderIndices ,
107- ... rest
108- } = props ;
109-
110- const preserveChildren = maintainVisibleContentPosition != null || ( isAndroid && snapToAlignment != null ) ;
111- const hasStickyHeaders = Array . isArray ( stickyHeaderIndices ) && stickyHeaderIndices . length > 0 ;
112-
113- const contentContainerStyleArray = [ props . horizontal ? { flexDirection : 'row' as const } : null , contentContainerStyle ] ;
114-
115- const contentSizeChangeProps = onContentSizeChange == null
116- ? undefined
117- : {
118- onLayout : ( e : LayoutChangeEvent ) => {
119- const { width, height } = e . nativeEvent . layout ;
120- onContentSizeChange ( width , height ) ;
121- }
122- } ;
39+ const internalRef = useRef < NativeScrollInstance | null > ( null ) ;
40+
41+ useLayoutEffect ( ( ) => {
42+ const node = internalRef . current as any ;
43+
44+ if ( node ) {
45+ // 1. Implementation of scrollTo
46+ node . scrollTo = ( options ?: { x ?: number ; y ?: number ; animated ?: boolean } ) => {
47+ const tag = findNodeHandle ( node ) ;
48+ if ( tag != null ) {
49+ const x = options ?. x || 0 ;
50+ const y = options ?. y || 0 ;
51+ const animated = options ?. animated !== false ;
52+ UIManager . dispatchViewManagerCommand ( tag , COMMAND_SCROLL_TO , [ x , y , animated ] ) ;
53+ }
54+ } ;
55+
56+ // 2. Implementation of scrollToEnd
57+ node . scrollToEnd = ( options ?: { animated ?: boolean } ) => {
58+ const tag = findNodeHandle ( node ) ;
59+ if ( tag != null ) {
60+ const animated = options ?. animated !== false ;
61+ UIManager . dispatchViewManagerCommand ( tag , COMMAND_SCROLL_TO_END , [ animated ] ) ;
62+ }
63+ } ;
64+
65+ // 3. Implementation of flashScrollIndicators
66+ node . flashScrollIndicators = ( ) => {
67+ const tag = findNodeHandle ( node as any ) ;
68+ if ( tag !== null ) {
69+ UIManager . dispatchViewManagerCommand ( tag , COMMAND_FLASH_SCROLL_INDICATORS , [ ] ) ;
70+ }
71+ } ;
72+
73+ node . getScrollRef = ( ) => node ;
74+
75+ if ( typeof node . setNativeProps !== 'function' ) {
76+ node . setNativeProps = ( nativeProps : object ) => {
77+ // Check again if the underlying node has the method hidden
78+ if ( node && typeof ( node as any ) . setNativeProps === 'function' ) {
79+ ( node as any ) . setNativeProps ( nativeProps ) ;
80+ }
81+ } ;
82+ }
83+ }
84+ } ) ;
85+
86+ // Callback Ref to handle merging internal and external refs
87+ const setRef = ( node : NativeScrollInstance | null ) => {
88+ internalRef . current = node ;
89+
90+ if ( typeof externalRef === 'function' ) {
91+ externalRef ( node as InvertedScrollViewRef ) ;
92+ } else if ( externalRef ) {
93+ ( externalRef as React . MutableRefObject < NativeScrollInstance | null > ) . current = node ;
94+ }
95+ } ;
96+
97+ const {
98+ children ,
99+ contentContainerStyle ,
100+ onContentSizeChange ,
101+ removeClippedSubviews ,
102+ maintainVisibleContentPosition ,
103+ snapToAlignment ,
104+ stickyHeaderIndices ,
105+ ... rest
106+ } = props ;
107+
108+ const preserveChildren = maintainVisibleContentPosition != null || ( isAndroid && snapToAlignment != null ) ;
109+ const hasStickyHeaders = Array . isArray ( stickyHeaderIndices ) && stickyHeaderIndices . length > 0 ;
110+
111+ const contentContainerStyleArray = [ props . horizontal ? { flexDirection : 'row' as const } : null , contentContainerStyle ] ;
112+
113+ const contentSizeChangeProps =
114+ onContentSizeChange == null
115+ ? undefined
116+ : {
117+ onLayout : ( e : LayoutChangeEvent ) => {
118+ const { width, height } = e . nativeEvent . layout ;
119+ onContentSizeChange ( width , height ) ;
120+ }
121+ } ;
123122
124123 const horizontal = ! ! props . horizontal ;
125124 const baseStyle = horizontal ? styles . baseHorizontal : styles . baseVertical ;
0 commit comments