diff --git a/Libraries/Components/ScrollResponder.js b/Libraries/Components/ScrollResponder.js index 881194da374533..65d0fd3c8a5994 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'); @@ -535,19 +536,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 75bc311539f32e..be934aaa3c1182 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, @@ -779,7 +780,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; } @@ -942,13 +951,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 7bf6cf669f6b26..9a5532bb2f1237 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; @@ -1224,6 +1230,10 @@ const TextInput = createReactClass({ class InternalTextInputType extends ReactNative.NativeComponent { clear() {} + getNativeRef(): ?React.ElementRef< + Class>, + > {} + // $FlowFixMe isFocused(): boolean {} }