From a53e81ead9577ab8cc3cf39eea4a0ae153793e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Tue, 13 Jun 2023 16:36:04 -0700 Subject: [PATCH] Define FabricUIManager as an interface instead of as an object (#37849) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37849 The typing for `FabricUIManager` makes more sense as an interface (the same way we type native modules) than as an object, as the underlying implementation used to be a host object where properties were actually not enumerable, etc. This replaces that with a definition more aligned with how we actually use it. This also allows us to extend the mock with testing specific methods more easily (like in D45278720). Changelog: [internal] Reviewed By: javache Differential Revision: D46684044 fbshipit-source-id: 379cc3f95a7cbae733ed6a3a57e68b33efd21d34 --- .../Libraries/ReactNative/FabricUIManager.js | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/packages/react-native/Libraries/ReactNative/FabricUIManager.js b/packages/react-native/Libraries/ReactNative/FabricUIManager.js index dbdd96cae7f..ad6c089b78f 100644 --- a/packages/react-native/Libraries/ReactNative/FabricUIManager.js +++ b/packages/react-native/Libraries/ReactNative/FabricUIManager.js @@ -24,55 +24,55 @@ import defineLazyObjectProperty from '../Utilities/defineLazyObjectProperty'; export type NodeSet = Array; export type NodeProps = {...}; -export type Spec = {| +export interface Spec { +createNode: ( reactTag: number, viewName: string, rootTag: RootTag, props: NodeProps, instanceHandle: InternalInstanceHandle, - ) => Node, - +cloneNode: (node: Node) => Node, - +cloneNodeWithNewChildren: (node: Node) => Node, - +cloneNodeWithNewProps: (node: Node, newProps: NodeProps) => Node, - +cloneNodeWithNewChildrenAndProps: (node: Node, newProps: NodeProps) => Node, - +createChildSet: (rootTag: RootTag) => NodeSet, - +appendChild: (parentNode: Node, child: Node) => Node, - +appendChildToSet: (childSet: NodeSet, child: Node) => void, - +completeRoot: (rootTag: RootTag, childSet: NodeSet) => void, - +measure: (node: Node, callback: MeasureOnSuccessCallback) => void, + ) => Node; + +cloneNode: (node: Node) => Node; + +cloneNodeWithNewChildren: (node: Node) => Node; + +cloneNodeWithNewProps: (node: Node, newProps: NodeProps) => Node; + +cloneNodeWithNewChildrenAndProps: (node: Node, newProps: NodeProps) => Node; + +createChildSet: (rootTag: RootTag) => NodeSet; + +appendChild: (parentNode: Node, child: Node) => Node; + +appendChildToSet: (childSet: NodeSet, child: Node) => void; + +completeRoot: (rootTag: RootTag, childSet: NodeSet) => void; + +measure: (node: Node, callback: MeasureOnSuccessCallback) => void; +measureInWindow: ( node: Node, callback: MeasureInWindowOnSuccessCallback, - ) => void, + ) => void; +measureLayout: ( node: Node, relativeNode: Node, onFail: () => void, onSuccess: MeasureLayoutOnSuccessCallback, - ) => void, + ) => void; +configureNextLayoutAnimation: ( config: LayoutAnimationConfig, callback: () => void, // check what is returned here errorCallback: () => void, - ) => void, - +sendAccessibilityEvent: (node: Node, eventType: string) => void, - +findShadowNodeByTag_DEPRECATED: (reactTag: number) => ?Node, - +setNativeProps: (node: Node, newProps: NodeProps) => void, + ) => void; + +sendAccessibilityEvent: (node: Node, eventType: string) => void; + +findShadowNodeByTag_DEPRECATED: (reactTag: number) => ?Node; + +setNativeProps: (node: Node, newProps: NodeProps) => void; +dispatchCommand: ( node: Node, commandName: string, args: Array, - ) => void, + ) => void; /** * Support methods for the DOM-compatible APIs. */ - +getParentNode: (node: Node) => ?InternalInstanceHandle, - +getChildNodes: (node: Node) => $ReadOnlyArray, - +isConnected: (node: Node) => boolean, - +compareDocumentPosition: (node: Node, otherNode: Node) => number, - +getTextContent: (node: Node) => string, + +getParentNode: (node: Node) => ?InternalInstanceHandle; + +getChildNodes: (node: Node) => $ReadOnlyArray; + +isConnected: (node: Node) => boolean; + +compareDocumentPosition: (node: Node, otherNode: Node) => number; + +getTextContent: (node: Node) => string; +getBoundingClientRect: ( node: Node, ) => ?[ @@ -80,18 +80,18 @@ export type Spec = {| /* y: */ number, /* width: */ number, /* height: */ number, - ], + ]; +getOffset: ( node: Node, ) => ?[ /* offsetParent: */ InternalInstanceHandle, /* offsetTop: */ number, /* offsetLeft: */ number, - ], + ]; +getScrollPosition: ( node: Node, - ) => ?[/* scrollLeft: */ number, /* scrollTop: */ number], -|}; + ) => ?[/* scrollLeft: */ number, /* scrollTop: */ number]; +} let nativeFabricUIManagerProxy: ?Spec; @@ -154,6 +154,7 @@ function createProxyWithCachedProperties( const proxy = Object.create(implementation); for (const propertyName of propertiesToCache) { defineLazyObjectProperty(proxy, propertyName, { + // $FlowExpectedError[prop-missing] get: () => implementation[propertyName], }); }