Files
react-native/Libraries/Components/View/ViewNativeComponent.js
T
Eli White 2f7732b145 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
2019-08-22 14:02:16 -07:00

92 lines
2.6 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'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<
ReactNative.NativeComponent<ViewProps>,
>;
let NativeViewComponent;
let viewConfig:
| {...}
| {|
bubblingEventTypes?: $ReadOnly<{
[eventName: string]: $ReadOnly<{|
phasedRegistrationNames: $ReadOnly<{|
bubbled: string,
captured: string,
|}>,
|}>,
}>,
directEventTypes?: $ReadOnly<{
[eventName: string]: $ReadOnly<{|registrationName: string|}>,
}>,
uiViewClassName: string,
validAttributes?: {
[propName: string]:
| true
| $ReadOnly<{|
diff?: <T>(arg1: any, arg2: any) => boolean,
process?: (arg1: any) => any,
|}>,
},
|};
// Only use the JS view config in DEV
if (__DEV__) {
// On Android, View extends the base component with additional view-only props
// On iOS, the base component is View
if (Platform.OS === 'android') {
viewConfig = ReactNativeViewViewConfigAndroid;
registerGeneratedViewConfig('RCTView', ReactNativeViewViewConfigAndroid);
} else {
viewConfig = {};
registerGeneratedViewConfig('RCTView', {uiViewClassName: 'RCTView'});
}
NativeViewComponent = 'RCTView';
} else {
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);