From a0440daf98d525f77e21148c1702b92c577b7592 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Tue, 12 May 2015 18:55:13 -0700 Subject: [PATCH] [react-native] Codemod .getNodeHandle, .getNativeNode to React.findNodeHandle --- Libraries/Animation/AnimationExperimental.js | 3 ++- Libraries/Animation/POPAnimationMixin.js | 5 +++-- .../Components/Navigation/NavigatorIOS.ios.js | 2 +- Libraries/Components/ScrollResponder.js | 7 ++++--- Libraries/Components/TextInput/TextInput.js | 2 +- Libraries/Components/TextInput/TextInputState.js | 12 ++++++------ Libraries/Components/WebView/WebView.android.js | 2 +- Libraries/Components/WebView/WebView.ios.js | 2 +- Libraries/CustomComponents/ListView/ListView.js | 4 ++-- Libraries/ReactIOS/NativeMethodsMixin.js | 15 ++++++++------- .../ReactNative/ReactNativeBaseComponentMixin.js | 8 ++++---- 11 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Libraries/Animation/AnimationExperimental.js b/Libraries/Animation/AnimationExperimental.js index 0a32c3f44..b66b1d056 100644 --- a/Libraries/Animation/AnimationExperimental.js +++ b/Libraries/Animation/AnimationExperimental.js @@ -12,6 +12,7 @@ 'use strict'; var RCTAnimationManager = require('NativeModules').AnimationExperimentalManager; +var React = require('React'); var AnimationUtils = require('AnimationUtils'); type EasingFunction = (t: number) => number; @@ -47,7 +48,7 @@ var AnimationExperimental = { }, callback?: ?(finished: bool) => void ): number { - var nodeHandle = anim.node.getNodeHandle(); + var nodeHandle = React.findNodeHandle(anim.node); var easingSample = AnimationUtils.evaluateEasingFunction( anim.duration, anim.easing diff --git a/Libraries/Animation/POPAnimationMixin.js b/Libraries/Animation/POPAnimationMixin.js index 213023290..115e58a01 100644 --- a/Libraries/Animation/POPAnimationMixin.js +++ b/Libraries/Animation/POPAnimationMixin.js @@ -12,6 +12,7 @@ 'use strict'; var POPAnimationOrNull = require('POPAnimation'); +var React = require('React'); if (!POPAnimationOrNull) { // POP animation isn't available in the OSS fork - this is a temporary @@ -83,7 +84,7 @@ var POPAnimationMixin = { 'Invalid refKey ' + refKey + ' for anim:\n' + JSON.stringify(anim) + '\nvalid refs: ' + JSON.stringify(Object.keys(this.refs)) ); - var refNodeHandle = this.refs[refKey].getNodeHandle(); + var refNodeHandle = React.findNodeHandle(this.refs[refKey]); this.startAnimationWithNodeHandle(refNodeHandle, animID, doneCallback); }, @@ -192,7 +193,7 @@ var POPAnimationMixin = { */ stopAnimations: function(refKey: string) { invariant(this.refs[refKey], 'invalid ref'); - this.stopNodeHandleAnimations(this.refs[refKey].getNodeHandle()); + this.stopNodeHandleAnimations(React.findNodeHandle(this.refs[refKey])); }, /** diff --git a/Libraries/Components/Navigation/NavigatorIOS.ios.js b/Libraries/Components/Navigation/NavigatorIOS.ios.js index 5741a72da..ef3ecd158 100644 --- a/Libraries/Components/Navigation/NavigatorIOS.ios.js +++ b/Libraries/Components/Navigation/NavigatorIOS.ios.js @@ -67,7 +67,7 @@ var RCTNavigatorItem = createReactNativeComponentClass({ var NavigatorTransitionerIOS = React.createClass({ requestSchedulingNavigation: function(cb) { RCTNavigatorManager.requestSchedulingJavaScriptNavigation( - (this: any).getNodeHandle(), + React.findNodeHandle(this), logError, cb ); diff --git a/Libraries/Components/ScrollResponder.js b/Libraries/Components/ScrollResponder.js index 74be17a46..0818a0bf9 100644 --- a/Libraries/Components/ScrollResponder.js +++ b/Libraries/Components/ScrollResponder.js @@ -13,6 +13,7 @@ var NativeModules = require('NativeModules'); var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); +var React = require('React'); var Subscribable = require('Subscribable'); var TextInputState = require('TextInputState'); @@ -350,7 +351,7 @@ var ScrollResponderMixin = { * can also be used to quickly scroll to any element we want to focus */ scrollResponderScrollTo: function(offsetX: number, offsetY: number) { - RCTUIManagerDeprecated.scrollTo(this.getNodeHandle(), offsetX, offsetY); + RCTUIManagerDeprecated.scrollTo(React.findNodeHandle(this), offsetX, offsetY); }, /** @@ -358,7 +359,7 @@ var ScrollResponderMixin = { * @param {object} rect Should have shape {x, y, width, height} */ scrollResponderZoomTo: function(rect: { x: number; y: number; width: number; height: number; }) { - RCTUIManagerDeprecated.zoomToRect(this.getNodeHandle(), rect); + RCTUIManagerDeprecated.zoomToRect(React.findNodeHandle(this), rect); }, /** @@ -376,7 +377,7 @@ var ScrollResponderMixin = { this.preventNegativeScrollOffset = !!preventNegativeScrollOffset; RCTUIManager.measureLayout( nodeHandle, - this.getNodeHandle(), + React.findNodeHandle(this), this.scrollResponderTextInputFocusError, this.scrollResponderInputMeasureAndScrollToKeyboard ); diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index 0a35cb5f4..7d44754f3 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -305,7 +305,7 @@ var TextInput = React.createClass({ isFocused: function(): boolean { return TextInputState.currentlyFocusedField() === - this.refs.input.getNativeNode(); + React.findNodeHandle(this.refs.input); }, getDefaultProps: function(): DefaultProps { diff --git a/Libraries/Components/TextInput/TextInputState.js b/Libraries/Components/TextInput/TextInputState.js index f22ac7927..da1f5cf60 100644 --- a/Libraries/Components/TextInput/TextInputState.js +++ b/Libraries/Components/TextInput/TextInputState.js @@ -21,22 +21,22 @@ var TextInputState = { /** * Internal state */ - _currentlyFocusedID: (null: ?string), + _currentlyFocusedID: (null: ?number), /** * Returns the ID of the currently focused text field, if one exists * If no text field is focused it returns null */ - currentlyFocusedField: function(): ?string { + currentlyFocusedField: function(): ?number { return this._currentlyFocusedID; }, /** - * @param {string} TextInputID id of the text field to focus + * @param {number} TextInputID id of the text field to focus * Focuses the specified text field * noop if the text field was already focused */ - focusTextInput: function(textFieldID: string) { + focusTextInput: function(textFieldID: ?number) { if (this._currentlyFocusedID !== textFieldID && textFieldID !== null) { this._currentlyFocusedID = textFieldID; RCTUIManager.focus(textFieldID); @@ -44,11 +44,11 @@ var TextInputState = { }, /** - * @param {string} textFieldID id of the text field to focus + * @param {number} textFieldID id of the text field to focus * Unfocuses the specified text field * noop if it wasn't focused */ - blurTextInput: function(textFieldID: string) { + blurTextInput: function(textFieldID: ?number) { if (this._currentlyFocusedID === textFieldID && textFieldID !== null) { this._currentlyFocusedID = null; RCTUIManager.blur(textFieldID); diff --git a/Libraries/Components/WebView/WebView.android.js b/Libraries/Components/WebView/WebView.android.js index 10b65a31c..a9ee724fa 100644 --- a/Libraries/Components/WebView/WebView.android.js +++ b/Libraries/Components/WebView/WebView.android.js @@ -143,7 +143,7 @@ var WebView = React.createClass({ }, getWebWiewHandle: function() { - return this.refs[RCT_WEBVIEW_REF].getNodeHandle(); + return React.findNodeHandle(this.refs[RCT_WEBVIEW_REF]); }, onLoadingStart: function(event) { diff --git a/Libraries/Components/WebView/WebView.ios.js b/Libraries/Components/WebView/WebView.ios.js index b4a5d8002..de9ff2ef1 100644 --- a/Libraries/Components/WebView/WebView.ios.js +++ b/Libraries/Components/WebView/WebView.ios.js @@ -189,7 +189,7 @@ var WebView = React.createClass({ }, getWebWiewHandle: function(): any { - return this.refs[RCT_WEBVIEW_REF].getNodeHandle(); + return React.findNodeHandle(this.refs[RCT_WEBVIEW_REF]); }, onLoadingStart: function(event: Event) { diff --git a/Libraries/CustomComponents/ListView/ListView.js b/Libraries/CustomComponents/ListView/ListView.js index 3fdb980b5..0a03bd38b 100644 --- a/Libraries/CustomComponents/ListView/ListView.js +++ b/Libraries/CustomComponents/ListView/ListView.js @@ -346,12 +346,12 @@ var ListView = React.createClass({ _measureAndUpdateScrollProps: function() { RCTUIManager.measureLayout( this.refs[SCROLLVIEW_REF].getInnerViewNode(), - this.refs[SCROLLVIEW_REF].getNodeHandle(), + React.findNodeHandle(this.refs[SCROLLVIEW_REF]), logError, this._setScrollContentHeight ); RCTUIManager.measureLayoutRelativeToParent( - this.refs[SCROLLVIEW_REF].getNodeHandle(), + React.findNodeHandle(this.refs[SCROLLVIEW_REF]), logError, this._setScrollVisibleHeight ); diff --git a/Libraries/ReactIOS/NativeMethodsMixin.js b/Libraries/ReactIOS/NativeMethodsMixin.js index 9d413e5c7..1bbf30b06 100644 --- a/Libraries/ReactIOS/NativeMethodsMixin.js +++ b/Libraries/ReactIOS/NativeMethodsMixin.js @@ -16,6 +16,7 @@ var RCTPOPAnimationManager = NativeModules.POPAnimationManager; var RCTUIManager = NativeModules.UIManager; var TextInputState = require('TextInputState'); +var findNodeHandle = require('findNodeHandle'); var flattenStyle = require('flattenStyle'); var invariant = require('invariant'); var mergeFast = require('mergeFast'); @@ -51,16 +52,16 @@ var animationIDInvariant = function( var NativeMethodsMixin = { addAnimation: function(anim: number, callback?: (finished: bool) => void) { animationIDInvariant('addAnimation', anim); - RCTPOPAnimationManager.addAnimation(this.getNodeHandle(), anim, callback); + RCTPOPAnimationManager.addAnimation(findNodeHandle(this), anim, callback); }, removeAnimation: function(anim: number) { animationIDInvariant('removeAnimation', anim); - RCTPOPAnimationManager.removeAnimation(this.getNodeHandle(), anim); + RCTPOPAnimationManager.removeAnimation(findNodeHandle(this), anim); }, measure: function(callback: MeasureOnSuccessCallback) { - RCTUIManager.measure(this.getNodeHandle(), callback); + RCTUIManager.measure(findNodeHandle(this), callback); }, measureLayout: function( @@ -69,7 +70,7 @@ var NativeMethodsMixin = { onFail: () => void /* currently unused */ ) { RCTUIManager.measureLayout( - this.getNodeHandle(), + findNodeHandle(this), relativeToNativeNode, onFail, onSuccess @@ -106,18 +107,18 @@ var NativeMethodsMixin = { } RCTUIManager.updateView( - this.getNodeHandle(), + findNodeHandle(this), this.viewConfig.uiViewClassName, props ); }, focus: function() { - TextInputState.focusTextInput(this.getNodeHandle()); + TextInputState.focusTextInput(findNodeHandle(this)); }, blur: function() { - TextInputState.blurTextInput(this.getNodeHandle()); + TextInputState.blurTextInput(findNodeHandle(this)); } }; diff --git a/Libraries/ReactNative/ReactNativeBaseComponentMixin.js b/Libraries/ReactNative/ReactNativeBaseComponentMixin.js index 6f10ce7c2..7cbf97077 100644 --- a/Libraries/ReactNative/ReactNativeBaseComponentMixin.js +++ b/Libraries/ReactNative/ReactNativeBaseComponentMixin.js @@ -15,15 +15,15 @@ var findNodeHandle = require('findNodeHandle'); var ReactNativeComponentMixin = { /** - * This has no particular meaning in ReactNative. If this were in the DOM, this - * would return the DOM node. There should be nothing that invokes this - * method. Any current callers of this are mistaken - they should be invoking - * `getNodeHandle`. + * This method is deprecated; use `React.findNodeHandle` instead. */ getNativeNode: function() { return findNodeHandle(this); }, + /** + * This method is deprecated; use `React.findNodeHandle` instead. + */ getNodeHandle: function() { return findNodeHandle(this); }