diff --git a/Libraries/Components/Touchable/TouchableNativeFeedback.android.js b/Libraries/Components/Touchable/TouchableNativeFeedback.android.js index a866f65e01..4ccbb7570b 100644 --- a/Libraries/Components/Touchable/TouchableNativeFeedback.android.js +++ b/Libraries/Components/Touchable/TouchableNativeFeedback.android.js @@ -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, diff --git a/Libraries/Components/View/ViewNativeComponent.js b/Libraries/Components/View/ViewNativeComponent.js index c735b5b864..8b58086b83 100644 --- a/Libraries/Components/View/ViewNativeComponent.js +++ b/Libraries/Components/View/ViewNativeComponent.js @@ -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, + x: Int32, + y: Int32, + ) => void; + +setPressed: ( + viewRef: React.ElementRef, + pressed: boolean, + ) => void; +} + +export const Commands = codegenNativeCommands({ + supportedCommands: ['hotspotUpdate', 'setPressed'], +}); + export const __INTERNAL_VIEW_CONFIG = viewConfig; export default ((NativeViewComponent: any): ViewNativeComponentType);