diff --git a/Libraries/Components/ScrollResponder.js b/Libraries/Components/ScrollResponder.js index 8c58f75c5d5126..4f8c86fc8a8cdb 100644 --- a/Libraries/Components/ScrollResponder.js +++ b/Libraries/Components/ScrollResponder.js @@ -10,6 +10,7 @@ 'use strict'; +const React = require('react'); const Dimensions = require('../Utilities/Dimensions'); const FrameRateLogger = require('../Interaction/FrameRateLogger'); const Keyboard = require('./Keyboard/Keyboard'); @@ -551,19 +552,30 @@ const ScrollResponderMixin = { * @param {bool} preventNegativeScrolling Whether to allow pulling the content * down to make it meet the keyboard's top. Default is false. */ - scrollResponderScrollNativeHandleToKeyboard: function( - nodeHandle: number, + scrollResponderScrollNativeHandleToKeyboard: function( + nodeHandle: + | number + | React.ElementRef>>, additionalOffset?: number, preventNegativeScrollOffset?: boolean, ) { this.additionalScrollOffset = additionalOffset || 0; this.preventNegativeScrollOffset = !!preventNegativeScrollOffset; - UIManager.measureLayout( - nodeHandle, - ReactNative.findNodeHandle(this.getInnerViewNode()), - this.scrollResponderTextInputFocusError, - this.scrollResponderInputMeasureAndScrollToKeyboard, - ); + + if (typeof nodeHandle === 'number') { + UIManager.measureLayout( + nodeHandle, + ReactNative.findNodeHandle(this.getInnerViewNode()), + this.scrollResponderTextInputFocusError, + this.scrollResponderInputMeasureAndScrollToKeyboard, + ); + } else { + nodeHandle.measureLayout( + this.getInnerViewRef(), + this.scrollResponderInputMeasureAndScrollToKeyboard, + this.scrollResponderTextInputFocusError, + ); + } }, /** diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index b15584381de031..46099f3481b05d 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -69,6 +69,7 @@ export type ScrollResponderType = { // issue by specifying them manually. getScrollableNode: $PropertyType, getInnerViewNode: $PropertyType, + getInnerViewRef: $PropertyType, getNativeScrollRef: $PropertyType, setNativeProps: $PropertyType, @@ -771,7 +772,15 @@ class ScrollView extends React.Component { return ReactNative.findNodeHandle(this._innerViewRef); } - getNativeScrollRef(): ?ScrollView { + getInnerViewRef(): ?React.ElementRef< + Class>, + > { + return this._innerViewRef; + } + + getNativeScrollRef(): ?React.ElementRef< + Class>, + > { return this._scrollViewRef; } @@ -944,13 +953,21 @@ class ScrollView extends React.Component { this.props.onContentSizeChange(width, height); }; - _scrollViewRef: ?ScrollView = null; - _setScrollViewRef = (ref: ?ScrollView) => { + _scrollViewRef: ?React.ElementRef< + Class>, + > = null; + _setScrollViewRef = ( + ref: ?React.ElementRef>>, + ) => { this._scrollViewRef = ref; }; - _innerViewRef: ?NativeMethodsMixinType = null; - _setInnerViewRef = (ref: ?NativeMethodsMixinType) => { + _innerViewRef: ?React.ElementRef< + Class>, + > = null; + _setInnerViewRef = ( + ref: ?React.ElementRef>>, + ) => { this._innerViewRef = ref; }; diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index 94315aa884124b..f05c1c8c94a6fd 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -904,6 +904,12 @@ const TextInput = createReactClass({ this._inputRef = ref; }, + getNativeRef: function(): ?React.ElementRef< + Class>, + > { + return this._inputRef; + }, + _renderIOSLegacy: function() { let textContainer; @@ -1227,6 +1233,10 @@ const TextInput = createReactClass({ class InternalTextInputType extends ReactNative.NativeComponent { clear() {} + getNativeRef(): ?React.ElementRef< + Class>, + > {} + // $FlowFixMe isFocused(): boolean {} }