Skip to content

Commit

Permalink
Migrate scrollResponderScrollNativeHandleToKeyboard function to take …
Browse files Browse the repository at this point in the history
…nativeRef

Summary:
We need to get rid of findNodeHandle calls so migrating scrollResponderScrollNativeHandleToKeyboard to take a ref to a host component.

I made this change with Flow, and tested by rendering UserJobApplicationForm

Reviewed By: mdvacca

Differential Revision: D17099280

fbshipit-source-id: 96af692006aace2c206f268f5416984b00f8a438
  • Loading branch information
TheSavior authored and facebook-github-bot committed Sep 20, 2019
1 parent 3e4c5c0 commit 0baacbe
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
28 changes: 20 additions & 8 deletions Libraries/Components/ScrollResponder.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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<T>(
nodeHandle:
| number
| React.ElementRef<Class<ReactNative.NativeComponent<T>>>,
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,
);
}
},

/**
Expand Down
27 changes: 22 additions & 5 deletions Libraries/Components/ScrollView/ScrollView.js
Expand Up @@ -69,6 +69,7 @@ export type ScrollResponderType = {
// issue by specifying them manually.
getScrollableNode: $PropertyType<ScrollView, 'getScrollableNode'>,
getInnerViewNode: $PropertyType<ScrollView, 'getInnerViewNode'>,
getInnerViewRef: $PropertyType<ScrollView, 'getInnerViewRef'>,
getNativeScrollRef: $PropertyType<ScrollView, 'getNativeScrollRef'>,

setNativeProps: $PropertyType<ScrollView, 'setNativeProps'>,
Expand Down Expand Up @@ -779,7 +780,15 @@ class ScrollView extends React.Component<Props, State> {
return ReactNative.findNodeHandle(this._innerViewRef);
}

getNativeScrollRef(): ?ScrollView {
getInnerViewRef(): ?React.ElementRef<
Class<ReactNative.NativeComponent<mixed>>,
> {
return this._innerViewRef;
}

getNativeScrollRef(): ?React.ElementRef<
Class<ReactNative.NativeComponent<mixed>>,
> {
return this._scrollViewRef;
}
Expand Down Expand Up @@ -942,13 +951,21 @@ class ScrollView extends React.Component<Props, State> {
this.props.onContentSizeChange(width, height);
};

_scrollViewRef: ?ScrollView = null;
_setScrollViewRef = (ref: ?ScrollView) => {
_scrollViewRef: ?React.ElementRef<
Class<ReactNative.NativeComponent<mixed>>,
> = null;
_setScrollViewRef = (
ref: ?React.ElementRef<Class<ReactNative.NativeComponent<mixed>>>,
) => {
this._scrollViewRef = ref;
};

_innerViewRef: ?NativeMethodsMixinType = null;
_setInnerViewRef = (ref: ?NativeMethodsMixinType) => {
_innerViewRef: ?React.ElementRef<
Class<ReactNative.NativeComponent<mixed>>,
> = null;
_setInnerViewRef = (
ref: ?React.ElementRef<Class<ReactNative.NativeComponent<mixed>>>,
) => {
this._innerViewRef = ref;
};

Expand Down
10 changes: 10 additions & 0 deletions Libraries/Components/TextInput/TextInput.js
Expand Up @@ -904,6 +904,12 @@ const TextInput = createReactClass({
this._inputRef = ref;
},

getNativeRef: function(): ?React.ElementRef<
Class<ReactNative.NativeComponent<mixed>>,
> {
return this._inputRef;
},

_renderIOSLegacy: function() {
let textContainer;

Expand Down Expand Up @@ -1224,6 +1230,10 @@ const TextInput = createReactClass({
class InternalTextInputType extends ReactNative.NativeComponent<Props> {
clear() {}

getNativeRef(): ?React.ElementRef<
Class<ReactNative.NativeComponent<mixed>>,
> {}

// $FlowFixMe
isFocused(): boolean {}
}
Expand Down

0 comments on commit 0baacbe

Please sign in to comment.