From fb32d93d177b38eb7dc375bc0884f71e9d0302fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 14 Nov 2024 06:20:47 -0800 Subject: [PATCH] Move ReactNativeTester to react-native repo (#47515) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47515 Changelog: [internal] Reviewed By: sammy-SC Differential Revision: D65661699 fbshipit-source-id: ab28b4e04254987f5b2f5617d83b9731ee6ad95a --- .../private/__tests__/ReactNativeTester.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 packages/react-native/src/private/__tests__/ReactNativeTester.js diff --git a/packages/react-native/src/private/__tests__/ReactNativeTester.js b/packages/react-native/src/private/__tests__/ReactNativeTester.js new file mode 100644 index 00000000000..121f057f3fb --- /dev/null +++ b/packages/react-native/src/private/__tests__/ReactNativeTester.js @@ -0,0 +1,46 @@ +/** + * 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. + * + * @flow strict-local + * @format + */ + +import type {MixedElement} from 'react'; + +import ReactFabric from '../../../Libraries/Renderer/shims/ReactFabric'; + +let globalSurfaceIdCounter = 1; + +class Root { + #surfaceId: number; + #hasRendered: boolean = false; + + constructor() { + this.#surfaceId = globalSurfaceIdCounter; + globalSurfaceIdCounter += 10; + } + + render(element: MixedElement) { + if (!this.#hasRendered) { + global.$$JSTesterModuleName$$.startSurface(this.#surfaceId); + this.#hasRendered = true; + } + ReactFabric.render(element, this.#surfaceId); + } + + destroy() { + // TODO: check for leaks. + global.$$JSTesterModuleName$$.stopSurface(this.#surfaceId); + } + + // TODO: add an API to check if all surfaces were deallocated when tests are finished. +} + +// TODO: Add option to define surface props and pass it to startSurface +// Surfacep rops: concurrentRoot, surfaceWidth, surfaceHeight, layoutDirection, pointScaleFactor. +export function createRoot(): Root { + return new Root(); +}