From 2f0c06de1040589622a1ff27d36a7f8913a2d2b8 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Tue, 18 Jun 2024 16:23:45 -0700 Subject: [PATCH] setup gating for (#45031) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45031 changelog: [internal] Reviewed By: rubennorte Differential Revision: D58672844 fbshipit-source-id: 2c99d3b66665c8dc0b796713b21d91211b469d81 --- packages/react-native/Libraries/Text/Text.js | 7 ++++++- .../__tests__/__snapshots__/public-api-test.js.snap | 2 +- .../featureflags/ReactNativeFeatureFlags.config.js | 4 ++++ .../src/private/featureflags/ReactNativeFeatureFlags.js | 8 +++++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/react-native/Libraries/Text/Text.js b/packages/react-native/Libraries/Text/Text.js index b9c10b3e736116..623fa98114fd7b 100644 --- a/packages/react-native/Libraries/Text/Text.js +++ b/packages/react-native/Libraries/Text/Text.js @@ -11,6 +11,7 @@ import type {PressEvent} from '../Types/CoreEventTypes'; import type {TextProps} from './TextProps'; +import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags'; import * as PressabilityDebug from '../Pressability/PressabilityDebug'; import usePressability from '../Pressability/usePressability'; import flattenStyle from '../StyleSheet/flattenStyle'; @@ -337,4 +338,8 @@ const verticalAlignToTextAlignVerticalMap = { middle: 'center', }; -module.exports = Text; +module.exports = ( + ReactNativeFeatureFlags.shouldUseOptimizedText() + ? require('./TextOptimized') + : Text +) as typeof Text; diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index 6269e4e9bc2e32..839995a83c7af7 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -8048,7 +8048,7 @@ exports[`public API should not change unintentionally Libraries/Text/Text.js 1`] TextProps, React.ElementRef, >; -declare module.exports: Text; +declare module.exports: typeof Text; " `; diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js index 313fffce5284ee..79884fb2b25019 100644 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -187,6 +187,10 @@ const definitions: FeatureFlagDefinitions = { description: 'Enables use of AnimatedObject for animating transform values.', }, + shouldUseOptimizedText: { + defaultValue: false, + description: 'Use optimized version of component.', + }, shouldUseRemoveClippedSubviewsAsDefaultOnIOS: { defaultValue: false, description: diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index 6bc4b7dd1cab57..56cb85ac155578 100644 --- a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<522f11a571457cb932f451cf81bd384a>> * @flow strict-local */ @@ -32,6 +32,7 @@ export type ReactNativeFeatureFlagsJsOnly = { enableAccessToHostTreeInFabric: Getter, isLayoutAnimationEnabled: Getter, shouldUseAnimatedObjectForTransform: Getter, + shouldUseOptimizedText: Getter, shouldUseRemoveClippedSubviewsAsDefaultOnIOS: Getter, shouldUseSetNativePropsInFabric: Getter, }; @@ -97,6 +98,11 @@ export const isLayoutAnimationEnabled: Getter = createJavaScriptFlagGet */ export const shouldUseAnimatedObjectForTransform: Getter = createJavaScriptFlagGetter('shouldUseAnimatedObjectForTransform', false); +/** + * Use optimized version of component. + */ +export const shouldUseOptimizedText: Getter = createJavaScriptFlagGetter('shouldUseOptimizedText', false); + /** * removeClippedSubviews prop will be used as the default in FlatList on iOS to match Android */