Migrate TouchableNativeFeedback to use codegenNativeCommands
Summary: Instead of dispatching the command with findNodeHandle and the UIManager, go through the new API. This is safe because codegenNativeCommands can work at runtime as well as with the babel transform. Changelog: [Internal] Reviewed By: rickhanlonii Differential Revision: D16909599 fbshipit-source-id: 90252862374290dbeb7202483fa585b6a7051c12
This commit is contained in:
Родитель
3b7eb7ed85
Коммит
2f7732b145
|
@ -13,11 +13,10 @@
|
|||
const Platform = require('../../Utilities/Platform');
|
||||
const React = require('react');
|
||||
const PropTypes = require('prop-types');
|
||||
const ReactNative = require('../../Renderer/shims/ReactNative');
|
||||
const Touchable = require('./Touchable');
|
||||
const TouchableWithoutFeedback = require('./TouchableWithoutFeedback');
|
||||
const UIManager = require('../../ReactNative/UIManager');
|
||||
const View = require('../View/View');
|
||||
const {Commands: ViewCommands} = require('../View/ViewNativeComponent');
|
||||
|
||||
const createReactClass = require('create-react-class');
|
||||
const ensurePositiveDelayProps = require('./ensurePositiveDelayProps');
|
||||
|
@ -262,20 +261,16 @@ const TouchableNativeFeedback = createReactClass({
|
|||
);
|
||||
},
|
||||
|
||||
_handleRef: function(ref) {
|
||||
this._viewRef = ref;
|
||||
},
|
||||
|
||||
_dispatchHotspotUpdate: function(destX, destY) {
|
||||
UIManager.dispatchViewManagerCommand(
|
||||
ReactNative.findNodeHandle(this),
|
||||
UIManager.getViewManagerConfig('RCTView').Commands.hotspotUpdate,
|
||||
[destX || 0, destY || 0],
|
||||
);
|
||||
ViewCommands.hotspotUpdate(this._viewRef, destX || 0, destY || 0);
|
||||
},
|
||||
|
||||
_dispatchPressedStateChange: function(pressed) {
|
||||
UIManager.dispatchViewManagerCommand(
|
||||
ReactNative.findNodeHandle(this),
|
||||
UIManager.getViewManagerConfig('RCTView').Commands.setPressed,
|
||||
[pressed],
|
||||
);
|
||||
ViewCommands.setPressed(this._viewRef, pressed);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
@ -318,6 +313,7 @@ const TouchableNativeFeedback = createReactClass({
|
|||
accessibilityActions: this.props.accessibilityActions,
|
||||
onAccessibilityAction: this.props.onAccessibilityAction,
|
||||
children,
|
||||
ref: this._handleRef,
|
||||
testID: this.props.testID,
|
||||
onLayout: this.props.onLayout,
|
||||
hitSlop: this.props.hitSlop,
|
||||
|
|
|
@ -10,13 +10,17 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const React = require('react');
|
||||
const Platform = require('../../Utilities/Platform');
|
||||
const ReactNative = require('../../Renderer/shims/ReactNative');
|
||||
const ReactNativeViewViewConfigAndroid = require('./ReactNativeViewViewConfigAndroid');
|
||||
|
||||
const registerGeneratedViewConfig = require('../../Utilities/registerGeneratedViewConfig');
|
||||
const requireNativeComponent = require('../../ReactNative/requireNativeComponent');
|
||||
const codegenNativeCommands = require('../../Utilities/codegenNativeCommands')
|
||||
.default;
|
||||
|
||||
import type {Int32} from '../../Types/CodegenTypes';
|
||||
import type {ViewProps} from './ViewPropTypes';
|
||||
|
||||
export type ViewNativeComponentType = Class<
|
||||
|
@ -66,5 +70,22 @@ if (__DEV__) {
|
|||
NativeViewComponent = requireNativeComponent('RCTView');
|
||||
}
|
||||
|
||||
// These commands are Android only
|
||||
interface NativeCommands {
|
||||
+hotspotUpdate: (
|
||||
viewRef: React.ElementRef<ViewNativeComponentType>,
|
||||
x: Int32,
|
||||
y: Int32,
|
||||
) => void;
|
||||
+setPressed: (
|
||||
viewRef: React.ElementRef<ViewNativeComponentType>,
|
||||
pressed: boolean,
|
||||
) => void;
|
||||
}
|
||||
|
||||
export const Commands = codegenNativeCommands<NativeCommands>({
|
||||
supportedCommands: ['hotspotUpdate', 'setPressed'],
|
||||
});
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = viewConfig;
|
||||
export default ((NativeViewComponent: any): ViewNativeComponentType);
|
||||
|
|
Загрузка…
Ссылка в новой задаче