[react-native] Codemod .getNodeHandle, .getNativeNode to React.findNodeHandle
This commit is contained in:
parent
a2f73b4d77
commit
a0440daf98
|
@ -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
|
||||
|
|
|
@ -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]));
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -67,7 +67,7 @@ var RCTNavigatorItem = createReactNativeComponentClass({
|
|||
var NavigatorTransitionerIOS = React.createClass({
|
||||
requestSchedulingNavigation: function(cb) {
|
||||
RCTNavigatorManager.requestSchedulingJavaScriptNavigation(
|
||||
(this: any).getNodeHandle(),
|
||||
React.findNodeHandle(this),
|
||||
logError,
|
||||
cb
|
||||
);
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue