1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and 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 strict
    
  9.  */
    
  10. 
    
  11. import type {ElementRef, ElementType, Element, AbstractComponent} from 'react';
    
  12. 
    
  13. export type MeasureOnSuccessCallback = (
    
  14.   x: number,
    
  15.   y: number,
    
  16.   width: number,
    
  17.   height: number,
    
  18.   pageX: number,
    
  19.   pageY: number,
    
  20. ) => void;
    
  21. 
    
  22. export type MeasureInWindowOnSuccessCallback = (
    
  23.   x: number,
    
  24.   y: number,
    
  25.   width: number,
    
  26.   height: number,
    
  27. ) => void;
    
  28. 
    
  29. export type MeasureLayoutOnSuccessCallback = (
    
  30.   left: number,
    
  31.   top: number,
    
  32.   width: number,
    
  33.   height: number,
    
  34. ) => void;
    
  35. 
    
  36. export type AttributeType<T, V> =
    
  37.   | true
    
  38.   | $ReadOnly<{
    
  39.       diff?: (arg1: T, arg2: T) => boolean,
    
  40.       process?: (arg1: V) => T,
    
  41.     }>;
    
  42. 
    
  43. // We either force that `diff` and `process` always use mixed,
    
  44. // or we allow them to define specific types and use this hack
    
  45. export type AnyAttributeType = AttributeType<$FlowFixMe, $FlowFixMe>;
    
  46. 
    
  47. export type AttributeConfiguration = $ReadOnly<{
    
  48.   [propName: string]: AnyAttributeType,
    
  49.   style: $ReadOnly<{
    
  50.     [propName: string]: AnyAttributeType,
    
  51.     ...
    
  52.   }>,
    
  53.   ...
    
  54. }>;
    
  55. 
    
  56. export type PartialAttributeConfiguration = $ReadOnly<{
    
  57.   [propName: string]: AnyAttributeType,
    
  58.   style?: $ReadOnly<{
    
  59.     [propName: string]: AnyAttributeType,
    
  60.     ...
    
  61.   }>,
    
  62.   ...
    
  63. }>;
    
  64. 
    
  65. export type ViewConfig = $ReadOnly<{
    
  66.   Commands?: $ReadOnly<{[commandName: string]: number, ...}>,
    
  67.   Constants?: $ReadOnly<{[name: string]: mixed, ...}>,
    
  68.   Manager?: string,
    
  69.   NativeProps?: $ReadOnly<{[propName: string]: string, ...}>,
    
  70.   baseModuleName?: ?string,
    
  71.   bubblingEventTypes?: $ReadOnly<{
    
  72.     [eventName: string]: $ReadOnly<{
    
  73.       phasedRegistrationNames: $ReadOnly<{
    
  74.         captured: string,
    
  75.         bubbled: string,
    
  76.         skipBubbling?: ?boolean,
    
  77.       }>,
    
  78.     }>,
    
  79.     ...
    
  80.   }>,
    
  81.   directEventTypes?: $ReadOnly<{
    
  82.     [eventName: string]: $ReadOnly<{
    
  83.       registrationName: string,
    
  84.     }>,
    
  85.     ...
    
  86.   }>,
    
  87.   uiViewClassName: string,
    
  88.   validAttributes: AttributeConfiguration,
    
  89. }>;
    
  90. 
    
  91. export type PartialViewConfig = $ReadOnly<{
    
  92.   bubblingEventTypes?: $PropertyType<ViewConfig, 'bubblingEventTypes'>,
    
  93.   directEventTypes?: $PropertyType<ViewConfig, 'directEventTypes'>,
    
  94.   uiViewClassName: string,
    
  95.   validAttributes?: PartialAttributeConfiguration,
    
  96. }>;
    
  97. 
    
  98. /**
    
  99.  * Current usages should migrate to this definition
    
  100.  */
    
  101. export interface INativeMethods {
    
  102.   blur(): void;
    
  103.   focus(): void;
    
  104.   measure(callback: MeasureOnSuccessCallback): void;
    
  105.   measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
    
  106.   measureLayout(
    
  107.     relativeToNativeNode: number | ElementRef<HostComponent<mixed>>,
    
  108.     onSuccess: MeasureLayoutOnSuccessCallback,
    
  109.     onFail?: () => void,
    
  110.   ): void;
    
  111.   setNativeProps(nativeProps: {...}): void;
    
  112. }
    
  113. 
    
  114. export type NativeMethods = $ReadOnly<{|
    
  115.   blur(): void,
    
  116.   focus(): void,
    
  117.   measure(callback: MeasureOnSuccessCallback): void,
    
  118.   measureInWindow(callback: MeasureInWindowOnSuccessCallback): void,
    
  119.   measureLayout(
    
  120.     relativeToNativeNode: number | ElementRef<HostComponent<mixed>>,
    
  121.     onSuccess: MeasureLayoutOnSuccessCallback,
    
  122.     onFail?: () => void,
    
  123.   ): void,
    
  124.   setNativeProps(nativeProps: {...}): void,
    
  125. |}>;
    
  126. 
    
  127. // This validates that INativeMethods and NativeMethods stay in sync using Flow!
    
  128. declare var ensureNativeMethodsAreSynced: NativeMethods;
    
  129. (ensureNativeMethodsAreSynced: INativeMethods);
    
  130. 
    
  131. export type HostComponent<T> = AbstractComponent<T, $ReadOnly<NativeMethods>>;
    
  132. 
    
  133. type SecretInternalsType = {
    
  134.   computeComponentStackForErrorReporting(tag: number): string,
    
  135.   // TODO (bvaughn) Decide which additional types to expose here?
    
  136.   // And how much information to fill in for the above types.
    
  137.   ...
    
  138. };
    
  139. 
    
  140. type InspectorDataProps = $ReadOnly<{
    
  141.   [propName: string]: string,
    
  142.   ...
    
  143. }>;
    
  144. 
    
  145. type InspectorDataSource = $ReadOnly<{
    
  146.   fileName?: string,
    
  147.   lineNumber?: number,
    
  148. }>;
    
  149. 
    
  150. type InspectorDataGetter = (
    
  151.   <TElementType: ElementType>(
    
  152.     componentOrHandle: ElementRef<TElementType> | number,
    
  153.   ) => ?number,
    
  154. ) => $ReadOnly<{
    
  155.   measure: (callback: MeasureOnSuccessCallback) => void,
    
  156.   props: InspectorDataProps,
    
  157.   source: InspectorDataSource,
    
  158. }>;
    
  159. 
    
  160. export type InspectorData = $ReadOnly<{
    
  161.   closestInstance?: mixed,
    
  162.   hierarchy: Array<{
    
  163.     name: ?string,
    
  164.     getInspectorData: InspectorDataGetter,
    
  165.   }>,
    
  166.   selectedIndex: ?number,
    
  167.   props: InspectorDataProps,
    
  168.   source: ?InspectorDataSource,
    
  169. }>;
    
  170. 
    
  171. export type TouchedViewDataAtPoint = $ReadOnly<{
    
  172.   pointerY: number,
    
  173.   touchedViewTag?: number,
    
  174.   frame: $ReadOnly<{
    
  175.     top: number,
    
  176.     left: number,
    
  177.     width: number,
    
  178.     height: number,
    
  179.   }>,
    
  180.   ...InspectorData,
    
  181. }>;
    
  182. 
    
  183. /**
    
  184.  * Flat ReactNative renderer bundles are too big for Flow to parse efficiently.
    
  185.  * Provide minimal Flow typing for the high-level RN API and call it a day.
    
  186.  */
    
  187. export type ReactNativeType = {
    
  188.   findHostInstance_DEPRECATED<TElementType: ElementType>(
    
  189.     componentOrHandle: ?(ElementRef<TElementType> | number),
    
  190.   ): ?ElementRef<HostComponent<mixed>>,
    
  191.   findNodeHandle<TElementType: ElementType>(
    
  192.     componentOrHandle: ?(ElementRef<TElementType> | number),
    
  193.   ): ?number,
    
  194.   dispatchCommand(
    
  195.     handle: ElementRef<HostComponent<mixed>>,
    
  196.     command: string,
    
  197.     args: Array<mixed>,
    
  198.   ): void,
    
  199.   sendAccessibilityEvent(
    
  200.     handle: ElementRef<HostComponent<mixed>>,
    
  201.     eventType: string,
    
  202.   ): void,
    
  203.   render(
    
  204.     element: Element<ElementType>,
    
  205.     containerTag: number,
    
  206.     callback: ?() => void,
    
  207.   ): ?ElementRef<ElementType>,
    
  208.   unmountComponentAtNode(containerTag: number): void,
    
  209.   unmountComponentAtNodeAndRemoveContainer(containerTag: number): void,
    
  210.   unstable_batchedUpdates: <T>(fn: (T) => void, bookkeeping: T) => void,
    
  211.   __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: SecretInternalsType,
    
  212.   ...
    
  213. };
    
  214. 
    
  215. export opaque type Node = mixed;
    
  216. export opaque type InternalInstanceHandle = mixed;
    
  217. type PublicInstance = mixed;
    
  218. type PublicTextInstance = mixed;
    
  219. 
    
  220. export type ReactFabricType = {
    
  221.   findHostInstance_DEPRECATED<TElementType: ElementType>(
    
  222.     componentOrHandle: ?(ElementRef<TElementType> | number),
    
  223.   ): ?ElementRef<HostComponent<mixed>>,
    
  224.   findNodeHandle<TElementType: ElementType>(
    
  225.     componentOrHandle: ?(ElementRef<TElementType> | number),
    
  226.   ): ?number,
    
  227.   dispatchCommand(
    
  228.     handle: ElementRef<HostComponent<mixed>>,
    
  229.     command: string,
    
  230.     args: Array<mixed>,
    
  231.   ): void,
    
  232.   sendAccessibilityEvent(
    
  233.     handle: ElementRef<HostComponent<mixed>>,
    
  234.     eventType: string,
    
  235.   ): void,
    
  236.   render(
    
  237.     element: Element<ElementType>,
    
  238.     containerTag: number,
    
  239.     callback: ?() => void,
    
  240.     concurrentRoot: ?boolean,
    
  241.   ): ?ElementRef<ElementType>,
    
  242.   unmountComponentAtNode(containerTag: number): void,
    
  243.   getNodeFromInternalInstanceHandle(
    
  244.     internalInstanceHandle: InternalInstanceHandle,
    
  245.   ): ?Node,
    
  246.   getPublicInstanceFromInternalInstanceHandle(
    
  247.     internalInstanceHandle: InternalInstanceHandle,
    
  248.   ): PublicInstance | PublicTextInstance,
    
  249.   ...
    
  250. };
    
  251. 
    
  252. export type ReactFabricEventTouch = {
    
  253.   identifier: number,
    
  254.   locationX: number,
    
  255.   locationY: number,
    
  256.   pageX: number,
    
  257.   pageY: number,
    
  258.   screenX: number,
    
  259.   screenY: number,
    
  260.   target: number,
    
  261.   timestamp: number,
    
  262.   force: number,
    
  263.   ...
    
  264. };
    
  265. 
    
  266. export type ReactFabricEvent = {
    
  267.   touches: Array<ReactFabricEventTouch>,
    
  268.   changedTouches: Array<ReactFabricEventTouch>,
    
  269.   targetTouches: Array<ReactFabricEventTouch>,
    
  270.   target: number,
    
  271.   ...
    
  272. };
    
  273. 
    
  274. // Imperative LayoutAnimation API types
    
  275. //
    
  276. export type LayoutAnimationType =
    
  277.   | 'spring'
    
  278.   | 'linear'
    
  279.   | 'easeInEaseOut'
    
  280.   | 'easeIn'
    
  281.   | 'easeOut'
    
  282.   | 'keyboard';
    
  283. 
    
  284. export type LayoutAnimationProperty =
    
  285.   | 'opacity'
    
  286.   | 'scaleX'
    
  287.   | 'scaleY'
    
  288.   | 'scaleXY';
    
  289. 
    
  290. export type LayoutAnimationAnimationConfig = $ReadOnly<{
    
  291.   duration?: number,
    
  292.   delay?: number,
    
  293.   springDamping?: number,
    
  294.   initialVelocity?: number,
    
  295.   type?: LayoutAnimationType,
    
  296.   property?: LayoutAnimationProperty,
    
  297. }>;
    
  298. 
    
  299. export type LayoutAnimationConfig = $ReadOnly<{
    
  300.   duration: number,
    
  301.   create?: LayoutAnimationAnimationConfig,
    
  302.   update?: LayoutAnimationAnimationConfig,
    
  303.   delete?: LayoutAnimationAnimationConfig,
    
  304. }>;