ViewNativeComponent.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow
  9. */
  10. 'use strict';
  11. const Platform = require('../../Utilities/Platform');
  12. const ReactNativeViewViewConfigAndroid = require('./ReactNativeViewViewConfigAndroid');
  13. const registerGeneratedViewConfig = require('../../Utilities/registerGeneratedViewConfig');
  14. const requireNativeComponent = require('../../ReactNative/requireNativeComponent');
  15. import * as React from 'react';
  16. import codegenNativeCommands from '../../Utilities/codegenNativeCommands';
  17. import type {ViewProps} from './ViewPropTypes';
  18. import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
  19. export type ViewNativeComponentType = HostComponent<ViewProps>;
  20. let NativeViewComponent;
  21. let viewConfig:
  22. | {...}
  23. | {|
  24. bubblingEventTypes?: $ReadOnly<{
  25. [eventName: string]: $ReadOnly<{|
  26. phasedRegistrationNames: $ReadOnly<{|
  27. bubbled: string,
  28. captured: string,
  29. |}>,
  30. |}>,
  31. ...,
  32. }>,
  33. directEventTypes?: $ReadOnly<{
  34. [eventName: string]: $ReadOnly<{|registrationName: string|}>,
  35. ...,
  36. }>,
  37. uiViewClassName: string,
  38. validAttributes?: {
  39. [propName: string]:
  40. | true
  41. | $ReadOnly<{|
  42. diff?: <T>(arg1: any, arg2: any) => boolean,
  43. process?: (arg1: any) => any,
  44. |}>,
  45. ...,
  46. },
  47. |};
  48. if (__DEV__ || global.RN$Bridgeless) {
  49. // On Android, View extends the base component with additional view-only props
  50. // On iOS, the base component is View
  51. if (Platform.OS === 'android') {
  52. viewConfig = ReactNativeViewViewConfigAndroid;
  53. registerGeneratedViewConfig('RCTView', ReactNativeViewViewConfigAndroid);
  54. } else {
  55. viewConfig = {};
  56. registerGeneratedViewConfig('RCTView', {uiViewClassName: 'RCTView'});
  57. }
  58. NativeViewComponent = 'RCTView';
  59. } else {
  60. NativeViewComponent = requireNativeComponent('RCTView');
  61. }
  62. export const __INTERNAL_VIEW_CONFIG = viewConfig;
  63. interface NativeCommands {
  64. +hotspotUpdate: (
  65. viewRef: React.ElementRef<HostComponent<mixed>>,
  66. x: number,
  67. y: number,
  68. ) => void;
  69. +setPressed: (
  70. viewRef: React.ElementRef<HostComponent<mixed>>,
  71. pressed: boolean,
  72. ) => void;
  73. }
  74. export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
  75. supportedCommands: ['hotspotUpdate', 'setPressed'],
  76. });
  77. export default ((NativeViewComponent: any): ViewNativeComponentType);