| 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 | * @noformat |
| 8 | * @nolint |
| 9 | * @flow strict |
| 10 | */ |
| 11 | |
| 12 | import type { |
| 13 | // $FlowFixMe[nonstrict-import] TODO(@rubennorte) |
| 14 | HostInstance as PublicInstance, |
| 15 | // $FlowFixMe[nonstrict-import] TODO(@rubennorte) |
| 16 | MeasureOnSuccessCallback, |
| 17 | // $FlowFixMe[nonstrict-import] TODO(@rubennorte) |
| 18 | PublicRootInstance, |
| 19 | // $FlowFixMe[nonstrict-import] TODO(@rubennorte) |
| 20 | PublicTextInstance, |
| 21 | } from 'react-native'; |
| 22 | |
| 23 | import * as React from 'react'; |
| 24 | |
| 25 | export type AttributeType<T, V> = |
| 26 | | true |
| 27 | | Readonly<{ |
| 28 | diff?: (arg1: T, arg2: T) => boolean, |
| 29 | process?: (arg1: V) => T, |
| 30 | }>; |
| 31 | |
| 32 | // We either force that `diff` and `process` always use unknown, |
| 33 | // or we allow them to define specific types and use this hack |
| 34 | export type AnyAttributeType = AttributeType<$FlowFixMe, $FlowFixMe>; |
| 35 | |
| 36 | export type AttributeConfiguration = Readonly<{ |
| 37 | [propName: string]: AnyAttributeType | void, |
| 38 | style?: Readonly<{ |
| 39 | [propName: string]: AnyAttributeType, |
| 40 | ... |
| 41 | }>, |
| 42 | ... |
| 43 | }>; |
| 44 | |
| 45 | export type ViewConfig = Readonly<{ |
| 46 | Commands?: Readonly<{[commandName: string]: number, ...}>, |
| 47 | Constants?: Readonly<{[name: string]: unknown, ...}>, |
| 48 | Manager?: string, |
| 49 | NativeProps?: Readonly<{[propName: string]: string, ...}>, |
| 50 | baseModuleName?: ?string, |
| 51 | bubblingEventTypes?: Readonly<{ |
| 52 | [eventName: string]: Readonly<{ |
| 53 | phasedRegistrationNames: Readonly<{ |
| 54 | captured: string, |
| 55 | bubbled: string, |
| 56 | skipBubbling?: ?boolean, |
| 57 | }>, |
| 58 | }>, |
| 59 | ... |
| 60 | }>, |
| 61 | directEventTypes?: Readonly<{ |
| 62 | [eventName: string]: Readonly<{ |
| 63 | registrationName: string, |
| 64 | }>, |
| 65 | ... |
| 66 | }>, |
| 67 | supportsRawText?: boolean, |
| 68 | uiViewClassName: string, |
| 69 | validAttributes: AttributeConfiguration, |
| 70 | }>; |
| 71 | |
| 72 | export type PartialViewConfig = Readonly<{ |
| 73 | bubblingEventTypes?: ViewConfig['bubblingEventTypes'], |
| 74 | directEventTypes?: ViewConfig['directEventTypes'], |
| 75 | supportsRawText?: boolean, |
| 76 | uiViewClassName: string, |
| 77 | validAttributes?: AttributeConfiguration, |
| 78 | }>; |
| 79 | |
| 80 | type InspectorDataProps = Readonly<{ |
| 81 | [propName: string]: string, |
| 82 | ... |
| 83 | }>; |
| 84 | |
| 85 | type InspectorDataGetter = ( |
| 86 | <TElementType extends React.ElementType>( |
| 87 | componentOrHandle: React.ElementRef<TElementType> | number, |
| 88 | ) => ?number, |
| 89 | ) => Readonly<{ |
| 90 | measure: (callback: MeasureOnSuccessCallback) => void, |
| 91 | props: InspectorDataProps, |
| 92 | }>; |
| 93 | |
| 94 | export type InspectorData = Readonly<{ |
| 95 | closestInstance?: unknown, |
| 96 | hierarchy: Array<{ |
| 97 | name: ?string, |
| 98 | getInspectorData: InspectorDataGetter, |
| 99 | }>, |
| 100 | selectedIndex: ?number, |
| 101 | props: InspectorDataProps, |
| 102 | componentStack: string, |
| 103 | }>; |
| 104 | |
| 105 | export type TouchedViewDataAtPoint = Readonly< |
| 106 | { |
| 107 | pointerY: number, |
| 108 | touchedViewTag?: number, |
| 109 | frame: Readonly<{ |
| 110 | top: number, |
| 111 | left: number, |
| 112 | width: number, |
| 113 | height: number, |
| 114 | }>, |
| 115 | closestPublicInstance?: PublicInstance, |
| 116 | } & InspectorData, |
| 117 | >; |
| 118 | |
| 119 | export type RenderRootOptions = { |
| 120 | onUncaughtError?: ( |
| 121 | error: unknown, |
| 122 | errorInfo: {readonly componentStack?: ?string}, |
| 123 | ) => void, |
| 124 | onCaughtError?: ( |
| 125 | error: unknown, |
| 126 | errorInfo: { |
| 127 | readonly componentStack?: ?string, |
| 128 | // $FlowFixMe[unclear-type] unknown props and state. |
| 129 | // $FlowFixMe[value-as-type] Component in react repo is any-typed, but it will be well typed externally. |
| 130 | readonly errorBoundary?: ?React.Component<any, any>, |
| 131 | }, |
| 132 | ) => void, |
| 133 | onRecoverableError?: ( |
| 134 | error: unknown, |
| 135 | errorInfo: {readonly componentStack?: ?string}, |
| 136 | ) => void, |
| 137 | onDefaultTransitionIndicator?: () => void | (() => void), |
| 138 | }; |
| 139 | |
| 140 | export opaque type Node = unknown; |
| 141 | export opaque type InternalInstanceHandle = unknown; |
| 142 | |
| 143 | export type ReactFabricType = { |
| 144 | findHostInstance_DEPRECATED<TElementType extends React.ElementType>( |
| 145 | componentOrHandle: ?(React.ElementRef<TElementType> | number), |
| 146 | ): ?PublicInstance, |
| 147 | findNodeHandle<TElementType extends React.ElementType>( |
| 148 | componentOrHandle: ?(React.ElementRef<TElementType> | number), |
| 149 | ): ?number, |
| 150 | dispatchCommand( |
| 151 | handle: PublicInstance, |
| 152 | command: string, |
| 153 | args: Array<unknown>, |
| 154 | ): void, |
| 155 | isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean, |
| 156 | sendAccessibilityEvent(handle: PublicInstance, eventType: string): void, |
| 157 | render( |
| 158 | element: React.MixedElement, |
| 159 | containerTag: number, |
| 160 | callback: ?() => void, |
| 161 | concurrentRoot: ?boolean, |
| 162 | options: ?RenderRootOptions, |
| 163 | ): ?React.ElementRef<React.ElementType>, |
| 164 | unmountComponentAtNode(containerTag: number): void, |
| 165 | getNodeFromInternalInstanceHandle( |
| 166 | internalInstanceHandle: InternalInstanceHandle, |
| 167 | ): ?Node, |
| 168 | getPublicInstanceFromInternalInstanceHandle( |
| 169 | internalInstanceHandle: InternalInstanceHandle, |
| 170 | ): PublicInstance | PublicTextInstance | null, |
| 171 | getPublicInstanceFromRootTag(rootTag: number): PublicRootInstance | null, |
| 172 | ... |
| 173 | }; |
| 174 | |
| 175 | export type ReactFabricEventTouch = { |
| 176 | identifier: number, |
| 177 | locationX: number, |
| 178 | locationY: number, |
| 179 | pageX: number, |
| 180 | pageY: number, |
| 181 | screenX: number, |
| 182 | screenY: number, |
| 183 | target: number, |
| 184 | timestamp: number, |
| 185 | force: number, |
| 186 | ... |
| 187 | }; |
| 188 | |
| 189 | export type ReactFabricEvent = { |
| 190 | touches: Array<ReactFabricEventTouch>, |
| 191 | changedTouches: Array<ReactFabricEventTouch>, |
| 192 | targetTouches: Array<ReactFabricEventTouch>, |
| 193 | target: number, |
| 194 | ... |
| 195 | }; |
| 196 | |
| 197 | // Imperative LayoutAnimation API types |
| 198 | // |
| 199 | export type LayoutAnimationType = |
| 200 | | 'spring' |
| 201 | | 'linear' |
| 202 | | 'easeInEaseOut' |
| 203 | | 'easeIn' |
| 204 | | 'easeOut' |
| 205 | | 'keyboard'; |
| 206 | |
| 207 | export type LayoutAnimationProperty = |
| 208 | | 'opacity' |
| 209 | | 'scaleX' |
| 210 | | 'scaleY' |
| 211 | | 'scaleXY'; |
| 212 | |
| 213 | export type LayoutAnimationAnimationConfig = Readonly<{ |
| 214 | duration?: number, |
| 215 | delay?: number, |
| 216 | springDamping?: number, |
| 217 | initialVelocity?: number, |
| 218 | type?: LayoutAnimationType, |
| 219 | property?: LayoutAnimationProperty, |
| 220 | }>; |
| 221 | |
| 222 | export type LayoutAnimationConfig = Readonly<{ |
| 223 | duration: number, |
| 224 | create?: LayoutAnimationAnimationConfig, |
| 225 | update?: LayoutAnimationAnimationConfig, |
| 226 | delete?: LayoutAnimationAnimationConfig, |
| 227 | }>; |