diff --git a/Libraries/Components/ScrollResponder.js b/Libraries/Components/ScrollResponder.js index 689a6b7e861..449f73ba350 100644 --- a/Libraries/Components/ScrollResponder.js +++ b/Libraries/Components/ScrollResponder.js @@ -458,21 +458,10 @@ const ScrollResponderMixin = { } else { ({x, y, animated} = x || {}); } - - const thisRef: React.ElementRef = (this: any); - invariant( - thisRef.getNativeScrollRef != null, - 'Expected scrollTo to be called on a scrollViewRef. If this exception occurs it is likely a bug in React Native', - ); - const nativeScrollRef = thisRef.getNativeScrollRef(); - if (nativeScrollRef == null) { - return; - } - ScrollView.Commands.scrollTo( - nativeScrollRef, - x || 0, - y || 0, - animated !== false, + UIManager.dispatchViewManagerCommand( + nullthrows(this.scrollResponderGetScrollableNode()), + UIManager.getViewManagerConfig('RCTScrollView').Commands.scrollTo, + [x || 0, y || 0, animated !== false], ); }, @@ -487,18 +476,11 @@ const ScrollResponderMixin = { scrollResponderScrollToEnd: function(options?: {animated?: boolean}) { // Default to true const animated = (options && options.animated) !== false; - - const thisRef: React.ElementRef = (this: any); - invariant( - thisRef.getNativeScrollRef != null, - 'Expected scrollToEnd to be called on a scrollViewRef. If this exception occurs it is likely a bug in React Native', + UIManager.dispatchViewManagerCommand( + this.scrollResponderGetScrollableNode(), + UIManager.getViewManagerConfig('RCTScrollView').Commands.scrollToEnd, + [animated], ); - const nativeScrollRef = thisRef.getNativeScrollRef(); - if (nativeScrollRef == null) { - return; - } - - ScrollView.Commands.scrollToEnd(nativeScrollRef, animated); }, /** @@ -526,33 +508,27 @@ const ScrollResponderMixin = { '`scrollResponderZoomTo` `animated` argument is deprecated. Use `options.animated` instead', ); } - - const thisRef: React.ElementRef = this; invariant( - thisRef.getNativeScrollRef != null, + this.getNativeScrollRef != null, 'Expected zoomToRect to be called on a scrollViewRef. If this exception occurs it is likely a bug in React Native', ); - const nativeScrollRef = thisRef.getNativeScrollRef(); - if (nativeScrollRef == null) { - return; - } - ScrollView.Commands.zoomToRect(nativeScrollRef, rect, animated !== false); + ScrollView.Commands.zoomToRect( + this.getNativeScrollRef(), + rect, + animated !== false, + ); }, /** * Displays the scroll indicators momentarily. */ scrollResponderFlashScrollIndicators: function() { - const thisRef: React.ElementRef = (this: any); - invariant( - thisRef.getNativeScrollRef != null, - 'Expected flashScrollIndicators to be called on a scrollViewRef. If this exception occurs it is likely a bug in React Native', + UIManager.dispatchViewManagerCommand( + this.scrollResponderGetScrollableNode(), + UIManager.getViewManagerConfig('RCTScrollView').Commands + .flashScrollIndicators, + [], ); - const nativeScrollRef = thisRef.getNativeScrollRef(); - if (nativeScrollRef == null) { - return; - } - ScrollView.Commands.flashScrollIndicators(nativeScrollRef); }, /** diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index acc726c463a..b755bff7d66 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -585,22 +585,9 @@ export type Props = $ReadOnly<{| children?: React.Node, |}>; -type ScrollViewNativeComponentType = HostComponent; +type ScrollViewNativeComponentType = Class>; interface NativeCommands { - +flashScrollIndicators: ( - viewRef: React.ElementRef, - ) => void; - +scrollTo: ( - viewRef: React.ElementRef, - x: number, - y: number, - animated: boolean, - ) => void; - +scrollToEnd: ( - viewRef: React.ElementRef, - animated: boolean, - ) => void; +zoomToRect: ( viewRef: React.ElementRef, rect: {| @@ -1243,12 +1230,7 @@ const styles = StyleSheet.create({ }); ScrollView.Commands = codegenNativeCommands({ - supportedCommands: [ - 'flashScrollIndicators', - 'scrollTo', - 'scrollToEnd', - 'zoomToRect', - ], + supportedCommands: ['zoomToRect'], }); module.exports = ScrollView;