diff --git a/packages/react-native/__typetests__/component-refs.tsx b/packages/react-native/__typetests__/component-refs.tsx new file mode 100644 index 00000000000..15099abadb3 --- /dev/null +++ b/packages/react-native/__typetests__/component-refs.tsx @@ -0,0 +1,59 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import * as React from 'react'; +import {View} from 'react-native'; + +// A ref to a host component resolves to its imperative handle, which exposes +// the native measurement and mutation methods. `React.ComponentRef` +// is the pattern that resolves to that handle under both the legacy and the +// strict public types; the `View` component type itself is not the handle. +type ViewHandle = React.ComponentRef; + +export function ViewImperativeHandle() { + const viewRef = React.useRef(null); + const targetRef = React.useRef(null); + + const measure = () => { + const view = viewRef.current; + const target = targetRef.current; + if (view == null || target == null) { + return; + } + + view.measure( + ( + x: number, + y: number, + width: number, + height: number, + pageX: number, + pageY: number, + ) => {}, + ); + + view.measureInWindow( + (x: number, y: number, width: number, height: number) => {}, + ); + + view.measureLayout( + target, + (left: number, top: number, width: number, height: number) => {}, + () => {}, + ); + + view.setNativeProps({}); + }; + + return ( + + + + ); +}