From 7fc01f00121406d66de3cb3893e3282617195ffc Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Thu, 22 Oct 2026 18:25:30 +0200 Subject: [PATCH] Rework I18nManager: runtime forceRTL, no left / right swap --- .../jest-preset/jest/mocks/NativeModules.js | 6 +- .../react-native/Libraries/Modal/Modal.js | 10 +- .../Libraries/Modal/__tests__/Modal-itest.js | 7 +- .../Libraries/ReactNative/I18nManager.js | 99 +++++++------ .../ReactNative/__tests__/I18nManager-test.js | 46 ++++++ .../React/CoreModules/RCTI18nManager.mm | 44 ++++-- .../React/Fabric/RCTSurfacePresenter.h | 5 + .../React/Fabric/RCTSurfacePresenter.mm | 10 ++ .../React/Fabric/Surface/RCTFabricSurface.h | 6 + .../React/Fabric/Surface/RCTFabricSurface.mm | 10 +- .../react-native/React/Modules/RCTI18nUtil.h | 4 - .../react-native/React/Modules/RCTI18nUtil.m | 62 +++----- .../React/Modules/RCTSurfacePresenterStub.h | 1 + packages/react-native/React/Views/RCTView.m | 74 ++-------- .../ReactAndroid/api/ReactAndroid.api | 5 +- .../react/fabric/FabricUIManager.java | 8 +- .../react/fabric/FabricUIManagerBinding.kt | 2 - .../react/fabric/SurfaceHandlerBinding.kt | 3 - .../modules/i18nmanager/I18nManagerModule.kt | 27 ++-- .../react/modules/i18nmanager/I18nUtil.kt | 54 ++----- .../react/runtime/BridgelessReactContext.kt | 4 + .../facebook/react/runtime/ReactHostImpl.kt | 6 + .../react/runtime/ReactSurfaceImpl.kt | 5 - .../react/runtime/ReactSurfaceView.kt | 9 +- .../uimanager/BackgroundStyleApplicator.kt | 7 +- .../react/uimanager/LayoutShadowNode.kt | 23 +-- .../uimanager/drawable/BackgroundDrawable.kt | 3 +- .../drawable/BackgroundImageDrawable.kt | 3 +- .../uimanager/drawable/BorderDrawable.kt | 5 +- .../drawable/CompositeBackgroundDrawable.kt | 3 +- .../drawable/InsetBoxShadowDrawable.kt | 3 +- .../uimanager/drawable/OutlineDrawable.kt | 1 - .../drawable/OutsetBoxShadowDrawable.kt | 2 +- .../react/uimanager/style/BorderColors.kt | 85 ++++------- .../react/uimanager/style/BorderInsets.kt | 83 ++++------- .../uimanager/style/BorderRadiusStyle.kt | 66 +++------ .../react/fabric/FabricUIManagerBinding.cpp | 8 +- .../jni/react/fabric/FabricUIManagerBinding.h | 6 +- .../react/fabric/SurfaceHandlerBinding.cpp | 2 - .../jni/react/fabric/SurfaceHandlerBinding.h | 1 - .../fabric/test/SurfaceHandlerBindingTest.cpp | 4 - ...abricMountingManagerInstrumentationTest.kt | 1 - .../react/runtime/ReactSurfaceTest.kt | 2 +- .../react/uimanager/BorderRadiusStyleTest.kt | 85 +---------- .../react/uimanager/style/BorderInsetsTest.kt | 4 +- .../view/YogaLayoutableShadowNode.cpp | 136 +----------------- .../view/YogaLayoutableShadowNode.h | 34 +---- .../components/view/tests/ViewTest.cpp | 111 -------------- .../react/renderer/core/LayoutContext.h | 29 +--- .../react/renderer/core/LayoutMetrics.h | 4 - packages/react-native/ReactNativeApi.d.ts | 10 +- .../SafeAreaView_INTERNAL_DO_NOT_USE.js | 11 +- .../elementinspector/resolveBoxStyle.js | 6 +- .../modules/NativeI18nManager.js | 7 +- .../Libraries/ReactNative/I18nManager.d.ts | 21 ++- packages/rn-tester/RNTester/Info.plist | 2 + .../rn-tester/js/examples/RTL/RTLExample.js | 65 ++++----- .../api-snapshots/ReactAndroidDebugCxx.api | 22 ++- .../ReactAndroidFrameworksCxx.api | 19 ++- .../api-snapshots/ReactAndroidNewarchCxx.api | 19 ++- .../api-snapshots/ReactAndroidReleaseCxx.api | 19 ++- .../api-snapshots/ReactAppleDebugCxx.api | 33 ++--- .../api-snapshots/ReactAppleFrameworksCxx.api | 30 ++-- .../api-snapshots/ReactAppleNewarchCxx.api | 30 ++-- .../api-snapshots/ReactAppleReleaseCxx.api | 30 ++-- .../api-snapshots/ReactCommonDebugCxx.api | 2 - .../ReactCommonFrameworksCxx.api | 2 - .../api-snapshots/ReactCommonNewarchCxx.api | 2 - .../api-snapshots/ReactCommonReleaseCxx.api | 2 - 69 files changed, 501 insertions(+), 1049 deletions(-) create mode 100644 packages/react-native/Libraries/ReactNative/__tests__/I18nManager-test.js diff --git a/packages/jest-preset/jest/mocks/NativeModules.js b/packages/jest-preset/jest/mocks/NativeModules.js index 63bc6f410e44..8f2ab2bd79bc 100644 --- a/packages/jest-preset/jest/mocks/NativeModules.js +++ b/packages/jest-preset/jest/mocks/NativeModules.js @@ -219,12 +219,10 @@ const NativeModules = { removeListeners: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>, }, I18nManager: { - allowRTL: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>, - forceRTL: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>, - swapLeftAndRightInRTL: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>, + forceRTL: jest.fn(() => false) as JestMockFn<$FlowFixMe, $FlowFixMe>, getConstants: (): $FlowFixMe => ({ isRTL: false, - doLeftAndRightSwapInRTL: true, + localeIdentifier: 'en-US', }), }, }; diff --git a/packages/react-native/Libraries/Modal/Modal.js b/packages/react-native/Libraries/Modal/Modal.js index d525d98ddd49..4330e0411667 100644 --- a/packages/react-native/Libraries/Modal/Modal.js +++ b/packages/react-native/Libraries/Modal/Modal.js @@ -22,7 +22,6 @@ import * as React from 'react'; const ScrollView = require('../Components/ScrollView/ScrollView').default; const View = require('../Components/View/View').default; const AppContainer = require('../ReactNative/AppContainer').default; -const I18nManager = require('../ReactNative/I18nManager').default; const {RootTagContext} = require('../ReactNative/RootTag'); const StyleSheet = require('../StyleSheet/StyleSheet').default; @@ -368,20 +367,13 @@ class Modal extends React.Component { } } -const side = I18nManager.getConstants().isRTL ? 'right' : 'left'; const styles = StyleSheet.create({ modal: { position: 'absolute', }, - /* $FlowFixMe[incompatible-type] Natural Inference rollout. See - * https://fburl.com/workplace/6291gfvu */ container: { - /* $FlowFixMe[invalid-computed-prop] (>=0.111.0 site=react_native_fb) This - * comment suppresses an error found when Flow v0.111 was deployed. To see - * the error, delete this comment and run Flow. */ - // $FlowFixMe[incompatible-type] - [side]: 0, top: 0, + start: 0, flex: 1, backgroundColor: 'white', }, diff --git a/packages/react-native/Libraries/Modal/__tests__/Modal-itest.js b/packages/react-native/Libraries/Modal/__tests__/Modal-itest.js index 34e268d2442a..68c6d1762455 100644 --- a/packages/react-native/Libraries/Modal/__tests__/Modal-itest.js +++ b/packages/react-native/Libraries/Modal/__tests__/Modal-itest.js @@ -19,7 +19,12 @@ import {createRef} from 'react'; import {Modal} from 'react-native'; const DEFAULT_MODAL_CHILD_VIEW = ( - + ); describe('', () => { diff --git a/packages/react-native/Libraries/ReactNative/I18nManager.js b/packages/react-native/Libraries/ReactNative/I18nManager.js index 01cd6ef998a4..54251a36bc93 100644 --- a/packages/react-native/Libraries/ReactNative/I18nManager.js +++ b/packages/react-native/Libraries/ReactNative/I18nManager.js @@ -8,24 +8,25 @@ * @format */ -import type {I18nManagerConstants} from './NativeI18nManager'; - +import warnOnce from '../Utilities/warnOnce'; import NativeI18nManager from './NativeI18nManager'; -const i18nConstants: I18nManagerConstants = getI18nManagerConstants(); - -function getI18nManagerConstants(): I18nManagerConstants { - if (NativeI18nManager) { - const {isRTL, doLeftAndRightSwapInRTL, localeIdentifier} = - NativeI18nManager.getConstants(); - return {isRTL, doLeftAndRightSwapInRTL, localeIdentifier}; - } +type I18nManagerConstants = { + /** + * @deprecated Has no effect, and is always `false`. Use `start` and `end` + * style properties, such as `marginStart`, instead. + */ + doLeftAndRightSwapInRTL: boolean, + isRTL: boolean, + localeIdentifier: string, +}; - return { - isRTL: false, - doLeftAndRightSwapInRTL: true, - }; -} +let i18nConstants: I18nManagerConstants = { + doLeftAndRightSwapInRTL: false, + isRTL: false, + localeIdentifier: 'en-US', + ...NativeI18nManager?.getConstants(), +}; /** * Utilities for managing Right-to-Left (RTL) layout support. @@ -38,45 +39,61 @@ export default { }, /** - * Allows the app to opt in to RTL layout behavior. Should be called early - * in app startup. Takes effect on the next app reload. + * @deprecated Has no effect. Set `RCTSupportsRTL` to `true` in Info.plist on + * iOS, or `android:supportsRtl="true"` in AndroidManifest.xml on Android, + * instead. */ - allowRTL: (shouldAllow: boolean) => { - if (!NativeI18nManager) { - return; - } - - NativeI18nManager.allowRTL(shouldAllow); + allowRTL: (shouldAllow: boolean): void => { + warnOnce( + 'I18nManager.allowRTL', + 'I18nManager.allowRTL() is deprecated and has no effect. Set ' + + '`RCTSupportsRTL` to `true` in Info.plist on iOS, or ' + + '`android:supportsRtl="true"` in AndroidManifest.xml on Android, ' + + 'instead.', + ); }, /** * Forces the app into RTL layout mode, regardless of the device locale. - * Takes effect on the next app reload. */ - forceRTL: (shouldForce: boolean) => { - if (!NativeI18nManager) { - return; + forceRTL: (shouldForce: boolean): void => { + if (NativeI18nManager != null) { + const isRTL = NativeI18nManager.forceRTL(shouldForce); + i18nConstants = {...i18nConstants, isRTL}; } - - NativeI18nManager.forceRTL(shouldForce); }, /** - * Controls whether `left`/`right` style properties are automatically swapped - * in RTL layouts. When enabled, `left` becomes `right` and vice versa. + * @deprecated Has no effect. Use `start` and `end` style properties, such as + * `marginStart`, instead. */ - swapLeftAndRightInRTL: (flipStyles: boolean) => { - if (!NativeI18nManager) { - return; - } - - NativeI18nManager.swapLeftAndRightInRTL(flipStyles); + swapLeftAndRightInRTL: (flipStyles: boolean): void => { + warnOnce( + 'I18nManager.swapLeftAndRightInRTL', + 'I18nManager.swapLeftAndRightInRTL() is deprecated and has no effect. ' + + 'Use `start` and `end` style properties, such as `marginStart`, ' + + 'instead.', + ); }, /** Whether the current layout direction is Right-to-Left. */ - isRTL: i18nConstants.isRTL as I18nManagerConstants['isRTL'], + // $FlowFixMe[unsafe-getters-setters] + get isRTL(): I18nManagerConstants['isRTL'] { + return i18nConstants.isRTL; + }, - /** Whether left and right style properties are swapped in RTL mode. */ - doLeftAndRightSwapInRTL: - i18nConstants.doLeftAndRightSwapInRTL as I18nManagerConstants['doLeftAndRightSwapInRTL'], + /** + * @deprecated Has no effect, and is always `false`. Use `start` and `end` + * style properties, such as `marginStart`, instead. + */ + // $FlowFixMe[unsafe-getters-setters] + get doLeftAndRightSwapInRTL(): I18nManagerConstants['doLeftAndRightSwapInRTL'] { + warnOnce( + 'I18nManager.doLeftAndRightSwapInRTL', + 'I18nManager.doLeftAndRightSwapInRTL is deprecated and has no effect, it ' + + 'is always false. Use `start` and `end` style properties, such as ' + + '`marginStart`, instead.', + ); + return false; + }, }; diff --git a/packages/react-native/Libraries/ReactNative/__tests__/I18nManager-test.js b/packages/react-native/Libraries/ReactNative/__tests__/I18nManager-test.js new file mode 100644 index 000000000000..32c030b34519 --- /dev/null +++ b/packages/react-native/Libraries/ReactNative/__tests__/I18nManager-test.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 + */ + +'use strict'; + +import type {I18nManagerConstants} from '../NativeI18nManager'; + +const nativeConstants: I18nManagerConstants = { + isRTL: false, + localeIdentifier: 'en-US', +}; + +const nativeModule = { + getConstants: jest.fn(() => nativeConstants), + forceRTL: jest.fn((forceRTL: boolean) => forceRTL), +}; + +jest.mock('../NativeI18nManager', () => ({ + __esModule: true, + default: nativeModule, +})); + +describe('I18nManager', () => { + it('updates the constants when forceRTL returns', () => { + const I18nManager = require('../I18nManager').default; + + I18nManager.forceRTL(true); + + expect(nativeModule.forceRTL).toHaveBeenCalledWith(true); + expect(nativeModule.getConstants).toHaveBeenCalledTimes(1); + expect(I18nManager.isRTL).toBe(true); + + expect(I18nManager.getConstants()).toEqual({ + doLeftAndRightSwapInRTL: false, + isRTL: true, + localeIdentifier: 'en-US', + }); + }); +}); diff --git a/packages/react-native/React/CoreModules/RCTI18nManager.mm b/packages/react-native/React/CoreModules/RCTI18nManager.mm index e24c2e60ff64..f26b86a82608 100644 --- a/packages/react-native/React/CoreModules/RCTI18nManager.mm +++ b/packages/react-native/React/CoreModules/RCTI18nManager.mm @@ -8,6 +8,7 @@ #import #import +#import #import "RCTI18nManager.h" #import "CoreModulesPlugins.h" @@ -17,7 +18,9 @@ @interface RCTI18nManager () @end -@implementation RCTI18nManager +@implementation RCTI18nManager { + __weak id _surfacePresenter; +} RCT_EXPORT_MODULE() @@ -26,19 +29,26 @@ + (BOOL)requiresMainQueueSetup return NO; } -- (void)allowRTL:(BOOL)value +- (void)setSurfacePresenter:(id)surfacePresenter { - [[RCTI18nUtil sharedInstance] allowRTL:value]; + _surfacePresenter = surfacePresenter; } -- (void)forceRTL:(BOOL)value +- (NSNumber *)forceRTL:(BOOL)value { + BOOL wasRTL = [[RCTI18nUtil sharedInstance] isRTL]; [[RCTI18nUtil sharedInstance] forceRTL:value]; -} + BOOL isRTL = [[RCTI18nUtil sharedInstance] isRTL]; -- (void)swapLeftAndRightInRTL:(BOOL)value -{ - [[RCTI18nUtil sharedInstance] swapLeftAndRightInRTL:value]; + if (isRTL != wasRTL) { + // Returns before the relayout, so JS reads the new value before any layout event + id surfacePresenter = _surfacePresenter; + dispatch_async(dispatch_get_main_queue(), ^{ + [surfacePresenter updateLayoutDirectionOfSurfaces]; + }); + } + + return @(isRTL); } - (NSDictionary *)constantsToExport @@ -50,10 +60,26 @@ - (NSDictionary *)getConstants { return @{ @"isRTL" : @([[RCTI18nUtil sharedInstance] isRTL]), - @"doLeftAndRightSwapInRTL" : @([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) + @"localeIdentifier" : [self _localeIdentifier], }; } +// BCP 47 language tag (e.g. "en-US", "zh-Hans-CN"), the same format as Android and the web +- (NSString *)_localeIdentifier +{ + NSLocale *locale = [NSLocale currentLocale]; + NSMutableArray *subtags = [NSMutableArray arrayWithObject:locale.languageCode]; + + if (locale.scriptCode != nil) { + [subtags addObject:locale.scriptCode]; + } + if (locale.countryCode != nil) { + [subtags addObject:locale.countryCode]; + } + + return [subtags componentsJoinedByString:@"-"]; +} + - (std::shared_ptr)getTurboModule:(const ObjCTurboModule::InitParams &)params { return std::make_shared(params); diff --git a/packages/react-native/React/Fabric/RCTSurfacePresenter.h b/packages/react-native/React/Fabric/RCTSurfacePresenter.h index 44e3ee9b6d4e..68ee63c48e47 100644 --- a/packages/react-native/React/Fabric/RCTSurfacePresenter.h +++ b/packages/react-native/React/Fabric/RCTSurfacePresenter.h @@ -65,6 +65,11 @@ NS_ASSUME_NONNULL_BEGIN - (nullable RCTFabricSurface *)surfaceForRootTag:(ReactTag)rootTag; +/* + * Lays out all surfaces again with the current layout direction. Must be called on the main thread. + */ +- (void)updateLayoutDirectionOfSurfaces; + - (void)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props; - (void)schedulerDidSynchronouslyUpdateViewOnUIThread:(ReactTag)tag props:(folly::dynamic)props; diff --git a/packages/react-native/React/Fabric/RCTSurfacePresenter.mm b/packages/react-native/React/Fabric/RCTSurfacePresenter.mm index e5b19bd47658..b24e9780b72b 100644 --- a/packages/react-native/React/Fabric/RCTSurfacePresenter.mm +++ b/packages/react-native/React/Fabric/RCTSurfacePresenter.mm @@ -168,6 +168,16 @@ - (RCTFabricSurface *)surfaceForRootTag:(ReactTag)rootTag return [_surfaceRegistry surfaceForRootTag:rootTag]; } +- (void)updateLayoutDirectionOfSurfaces +{ + RCTAssertMainQueue(); + [_surfaceRegistry enumerateWithBlock:^(NSEnumerator *enumerator) { + for (RCTFabricSurface *surface in enumerator) { + [surface updateLayoutContext]; + } + }]; +} + - (id)createFabricSurfaceForModuleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties { diff --git a/packages/react-native/React/Fabric/Surface/RCTFabricSurface.h b/packages/react-native/React/Fabric/Surface/RCTFabricSurface.h index fd00787cf94f..81bab098279f 100644 --- a/packages/react-native/React/Fabric/Surface/RCTFabricSurface.h +++ b/packages/react-native/React/Fabric/Surface/RCTFabricSurface.h @@ -115,6 +115,12 @@ NS_ASSUME_NONNULL_BEGIN - (const facebook::react::SurfaceHandler &)surfaceHandler; +/** + * Lays out the Surface again with the current layout direction, screen scale + * and font size multiplier. Must be called on the main thread. + */ +- (void)updateLayoutContext; + @end NS_ASSUME_NONNULL_END diff --git a/packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm b/packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm index 77452c49febb..bb5c0ff57feb 100644 --- a/packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm +++ b/packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm @@ -63,7 +63,7 @@ - (instancetype)initWithSurfacePresenter:(RCTSurfacePresenter *)surfacePresenter [self setMinimumSize:CGSizeZero maximumSize:RCTViewportSize()]; - [self _updateLayoutContext]; + [self updateLayoutContext]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleContentSizeCategoryDidChangeNotification:) @@ -157,7 +157,7 @@ - (RCTSurfaceView *)view if (!_view) { _view = [[RCTSurfaceView alloc] initWithSurface:self]; - [self _updateLayoutContext]; + [self updateLayoutContext]; #if !TARGET_OS_TV _touchHandler = [RCTSurfaceTouchHandler new]; [_touchHandler attachToView:_view]; @@ -186,7 +186,7 @@ - (void)_propagateStageChange } } -- (void)_updateLayoutContext +- (void)updateLayoutContext { auto layoutConstraints = _surfaceHandler->getLayoutConstraints(); layoutConstraints.layoutDirection = RCTLayoutDirection([[RCTI18nUtil sharedInstance] isRTL]); @@ -194,8 +194,6 @@ - (void)_updateLayoutContext auto layoutContext = _surfaceHandler->getLayoutContext(); layoutContext.pointScaleFactor = RCTScreenScale(); - layoutContext.swapLeftAndRightInRTL = - [[RCTI18nUtil sharedInstance] isRTL] && [[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]; layoutContext.fontSizeMultiplier = RCTFontSizeMultiplier(); _surfaceHandler->constraintLayout(layoutConstraints, layoutContext); @@ -290,7 +288,7 @@ - (BOOL)synchronouslyWaitFor:(NSTimeInterval)timeout - (void)handleContentSizeCategoryDidChangeNotification:(NSNotification *)notification { - [self _updateLayoutContext]; + [self updateLayoutContext]; } #pragma mark - Private diff --git a/packages/react-native/React/Modules/RCTI18nUtil.h b/packages/react-native/React/Modules/RCTI18nUtil.h index c105344bf019..ce65aa1ac92f 100644 --- a/packages/react-native/React/Modules/RCTI18nUtil.h +++ b/packages/react-native/React/Modules/RCTI18nUtil.h @@ -18,11 +18,7 @@ + (instancetype)sharedInstance; - (BOOL)isRTL; -- (BOOL)isRTLAllowed; -- (void)allowRTL:(BOOL)value; - (BOOL)isRTLForced; - (void)forceRTL:(BOOL)value; -- (BOOL)doLeftAndRightSwapInRTL; -- (void)swapLeftAndRightInRTL:(BOOL)value; @end diff --git a/packages/react-native/React/Modules/RCTI18nUtil.m b/packages/react-native/React/Modules/RCTI18nUtil.m index f1a41772d2d7..4af9fbc08a84 100644 --- a/packages/react-native/React/Modules/RCTI18nUtil.m +++ b/packages/react-native/React/Modules/RCTI18nUtil.m @@ -9,7 +9,10 @@ #import -@implementation RCTI18nUtil +@implementation RCTI18nUtil { + BOOL _isRTLSupported; + BOOL _isRTLForced; +} + (instancetype)sharedInstance { @@ -17,74 +20,53 @@ + (instancetype)sharedInstance static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [self new]; - [sharedInstance swapLeftAndRightInRTL:true]; }); return sharedInstance; } +- (instancetype)init +{ + if (self = [super init]) { + _isRTLSupported = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTSupportsRTL"] boolValue]; + _isRTLForced = NO; + } + return self; +} + /** * Check if the app is currently running on an RTL locale. - * This only happens when the app: + * Always false unless `RCTSupportsRTL` is true in Info.plist. + * Otherwise, this only happens when the app: * - is forcing RTL layout, regardless of the active language (for development purpose) - * - allows RTL layout when using RTL locale + * - or is using an RTL locale */ - (BOOL)isRTL { + if (!_isRTLSupported) { + return NO; + } if ([self isRTLForced]) { return YES; } - if ([self isRTLAllowed] && [self isApplicationPreferredLanguageRTL]) { + if ([self isApplicationPreferredLanguageRTL]) { return YES; } return NO; } -/** - * Should be used very early during app start up - * Before the bridge is initialized - * @return whether the app allows RTL layout, default is true - */ -- (BOOL)isRTLAllowed -{ - NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"RCTI18nUtil_allowRTL"]; - if (value == nil) { - return YES; - } - return [value boolValue]; -} - -- (void)allowRTL:(BOOL)rtlStatus -{ - [[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_allowRTL"]; - [[NSUserDefaults standardUserDefaults] synchronize]; -} - /** * Could be used to test RTL layout with English * Used for development and testing purpose */ - (BOOL)isRTLForced { - BOOL rtlStatus = [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_forceRTL"]; - return rtlStatus; + return _isRTLForced; } - (void)forceRTL:(BOOL)rtlStatus { - [[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_forceRTL"]; - [[NSUserDefaults standardUserDefaults] synchronize]; -} - -- (BOOL)doLeftAndRightSwapInRTL -{ - return [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"]; -} - -- (void)swapLeftAndRightInRTL:(BOOL)value -{ - [[NSUserDefaults standardUserDefaults] setBool:value forKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"]; - [[NSUserDefaults standardUserDefaults] synchronize]; + _isRTLForced = rtlStatus; } // Check if the current device language is RTL diff --git a/packages/react-native/React/Modules/RCTSurfacePresenterStub.h b/packages/react-native/React/Modules/RCTSurfacePresenterStub.h index fa17741f1143..14b2b7718f9a 100644 --- a/packages/react-native/React/Modules/RCTSurfacePresenterStub.h +++ b/packages/react-native/React/Modules/RCTSurfacePresenterStub.h @@ -35,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props; - (void)addObserver:(id)observer; - (void)removeObserver:(id)observer; +- (void)updateLayoutDirectionOfSurfaces; @end diff --git a/packages/react-native/React/Views/RCTView.m b/packages/react-native/React/Views/RCTView.m index bc39a7212f7b..3a2900226f4f 100644 --- a/packages/react-native/React/Views/RCTView.m +++ b/packages/react-native/React/Views/RCTView.m @@ -13,7 +13,6 @@ #import "RCTAutoInsetsProtocol.h" #import "RCTBorderCurve.h" #import "RCTBorderDrawing.h" -#import "RCTI18nUtil.h" #import "RCTLocalizedString.h" #import "RCTLog.h" #import "RCTViewUtils.h" @@ -652,21 +651,6 @@ - (UIEdgeInsets)bordersAsInsets const CGFloat borderWidth = MAX(0, _borderWidth); const BOOL isRTL = _reactLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft; - if ([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) { - const CGFloat borderStartWidth = RCTDefaultIfNegativeTo(_borderLeftWidth, _borderStartWidth); - const CGFloat borderEndWidth = RCTDefaultIfNegativeTo(_borderRightWidth, _borderEndWidth); - - const CGFloat directionAwareBorderLeftWidth = isRTL ? borderEndWidth : borderStartWidth; - const CGFloat directionAwareBorderRightWidth = isRTL ? borderStartWidth : borderEndWidth; - - return (UIEdgeInsets){ - RCTDefaultIfNegativeTo(borderWidth, _borderTopWidth), - RCTDefaultIfNegativeTo(borderWidth, directionAwareBorderLeftWidth), - RCTDefaultIfNegativeTo(borderWidth, _borderBottomWidth), - RCTDefaultIfNegativeTo(borderWidth, directionAwareBorderRightWidth), - }; - } - const CGFloat directionAwareBorderLeftWidth = isRTL ? _borderEndWidth : _borderStartWidth; const CGFloat directionAwareBorderRightWidth = isRTL ? _borderStartWidth : _borderEndWidth; @@ -693,36 +677,19 @@ - (RCTCornerRadii)cornerRadii const CGFloat logicalBottomStartRadius = RCTDefaultIfNegativeTo(_borderEndStartRadius, _borderBottomStartRadius); const CGFloat logicalBottomEndRadius = RCTDefaultIfNegativeTo(_borderEndEndRadius, _borderBottomEndRadius); - if ([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) { - const CGFloat topStartRadius = RCTDefaultIfNegativeTo(_borderTopLeftRadius, logicalTopStartRadius); - const CGFloat topEndRadius = RCTDefaultIfNegativeTo(_borderTopRightRadius, logicalTopEndRadius); - const CGFloat bottomStartRadius = RCTDefaultIfNegativeTo(_borderBottomLeftRadius, logicalBottomStartRadius); - const CGFloat bottomEndRadius = RCTDefaultIfNegativeTo(_borderBottomRightRadius, logicalBottomEndRadius); - - const CGFloat directionAwareTopLeftRadius = isRTL ? topEndRadius : topStartRadius; - const CGFloat directionAwareTopRightRadius = isRTL ? topStartRadius : topEndRadius; - const CGFloat directionAwareBottomLeftRadius = isRTL ? bottomEndRadius : bottomStartRadius; - const CGFloat directionAwareBottomRightRadius = isRTL ? bottomStartRadius : bottomEndRadius; - - topLeftRadius = RCTDefaultIfNegativeTo(radius, directionAwareTopLeftRadius); - topRightRadius = RCTDefaultIfNegativeTo(radius, directionAwareTopRightRadius); - bottomLeftRadius = RCTDefaultIfNegativeTo(radius, directionAwareBottomLeftRadius); - bottomRightRadius = RCTDefaultIfNegativeTo(radius, directionAwareBottomRightRadius); - } else { - const CGFloat directionAwareTopLeftRadius = isRTL ? logicalTopEndRadius : logicalTopStartRadius; - const CGFloat directionAwareTopRightRadius = isRTL ? logicalTopStartRadius : logicalTopEndRadius; - const CGFloat directionAwareBottomLeftRadius = isRTL ? logicalBottomEndRadius : logicalBottomStartRadius; - const CGFloat directionAwareBottomRightRadius = isRTL ? logicalBottomStartRadius : logicalBottomEndRadius; - - topLeftRadius = - RCTDefaultIfNegativeTo(radius, RCTDefaultIfNegativeTo(_borderTopLeftRadius, directionAwareTopLeftRadius)); - topRightRadius = - RCTDefaultIfNegativeTo(radius, RCTDefaultIfNegativeTo(_borderTopRightRadius, directionAwareTopRightRadius)); - bottomLeftRadius = - RCTDefaultIfNegativeTo(radius, RCTDefaultIfNegativeTo(_borderBottomLeftRadius, directionAwareBottomLeftRadius)); - bottomRightRadius = RCTDefaultIfNegativeTo( - radius, RCTDefaultIfNegativeTo(_borderBottomRightRadius, directionAwareBottomRightRadius)); - } + const CGFloat directionAwareTopLeftRadius = isRTL ? logicalTopEndRadius : logicalTopStartRadius; + const CGFloat directionAwareTopRightRadius = isRTL ? logicalTopStartRadius : logicalTopEndRadius; + const CGFloat directionAwareBottomLeftRadius = isRTL ? logicalBottomEndRadius : logicalBottomStartRadius; + const CGFloat directionAwareBottomRightRadius = isRTL ? logicalBottomStartRadius : logicalBottomEndRadius; + + topLeftRadius = + RCTDefaultIfNegativeTo(radius, RCTDefaultIfNegativeTo(_borderTopLeftRadius, directionAwareTopLeftRadius)); + topRightRadius = + RCTDefaultIfNegativeTo(radius, RCTDefaultIfNegativeTo(_borderTopRightRadius, directionAwareTopRightRadius)); + bottomLeftRadius = + RCTDefaultIfNegativeTo(radius, RCTDefaultIfNegativeTo(_borderBottomLeftRadius, directionAwareBottomLeftRadius)); + bottomRightRadius = + RCTDefaultIfNegativeTo(radius, RCTDefaultIfNegativeTo(_borderBottomRightRadius, directionAwareBottomRightRadius)); // Get scale factors required to prevent radii from overlapping const CGSize size = self.bounds.size; @@ -748,19 +715,8 @@ - (RCTBorderColors)borderColorsWithTraitCollection:(UITraitCollection *)traitCol { const BOOL isRTL = _reactLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft; - UIColor *directionAwareBorderLeftColor = nil; - UIColor *directionAwareBorderRightColor = nil; - - if ([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) { - UIColor *borderStartColor = _borderStartColor ?: _borderLeftColor; - UIColor *borderEndColor = _borderEndColor ?: _borderRightColor; - - directionAwareBorderLeftColor = isRTL ? borderEndColor : borderStartColor; - directionAwareBorderRightColor = isRTL ? borderStartColor : borderEndColor; - } else { - directionAwareBorderLeftColor = (isRTL ? _borderEndColor : _borderStartColor) ?: _borderLeftColor; - directionAwareBorderRightColor = (isRTL ? _borderStartColor : _borderEndColor) ?: _borderRightColor; - } + UIColor *directionAwareBorderLeftColor = (isRTL ? _borderEndColor : _borderStartColor) ?: _borderLeftColor; + UIColor *directionAwareBorderRightColor = (isRTL ? _borderStartColor : _borderEndColor) ?: _borderRightColor; UIColor *borderColor = _borderColor; UIColor *borderTopColor = _borderTopColor; diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index a5fa388742a7..310671dd3c03 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2746,12 +2746,9 @@ public final class com/facebook/react/modules/fresco/ReactNetworkImageRequest$Co public final class com/facebook/react/modules/i18nmanager/I18nUtil { public static final field Companion Lcom/facebook/react/modules/i18nmanager/I18nUtil$Companion; - public final fun allowRTL (Landroid/content/Context;Z)V - public final fun doLeftAndRightSwapInRTL (Landroid/content/Context;)Z - public final fun forceRTL (Landroid/content/Context;Z)V + public final fun forceRTL (Z)V public static final fun getInstance ()Lcom/facebook/react/modules/i18nmanager/I18nUtil; public final fun isRTL (Landroid/content/Context;)Z - public final fun swapLeftAndRightInRTL (Landroid/content/Context;Z)V } public final class com/facebook/react/modules/i18nmanager/I18nUtil$Companion { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 2727e880d083..f7fde23fd5da 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -389,8 +389,7 @@ public int startSurface( getMaxSize(heightMeasureSpec), viewportOffset.x, viewportOffset.y, - I18nUtil.getInstance().isRTL(context), - I18nUtil.getInstance().doLeftAndRightSwapInRTL(context)); + I18nUtil.getInstance().isRTL(context)); return rootTag; } @@ -1148,10 +1147,8 @@ public void updateRootLayoutSpecs( Context context = surfaceMountingManager.getContext(); boolean isRTL = false; - boolean doLeftAndRightSwapInRTL = false; if (context != null) { isRTL = I18nUtil.getInstance().isRTL(context); - doLeftAndRightSwapInRTL = I18nUtil.getInstance().doLeftAndRightSwapInRTL(context); } Assertions.assertNotNull(mBinding, "Binding in FabricUIManager is null"); @@ -1163,8 +1160,7 @@ public void updateRootLayoutSpecs( getMaxSize(heightMeasureSpec), offsetX, offsetY, - isRTL, - doLeftAndRightSwapInRTL); + isRTL); } @Override diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt index b1b3f12f50c2..1e3d86dd8c84 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt @@ -46,7 +46,6 @@ internal class FabricUIManagerBinding : HybridClassBase() { offsetX: Float, offsetY: Float, isRTL: Boolean, - doLeftAndRightSwapInRTL: Boolean, ) external fun startSurfaceWithSurfaceHandler( @@ -74,7 +73,6 @@ internal class FabricUIManagerBinding : HybridClassBase() { offsetX: Float, offsetY: Float, isRTL: Boolean, - doLeftAndRightSwapInRTL: Boolean, ) external fun driveCxxAnimations() diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.kt index 3ae993b04f78..40e39eee2757 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.kt @@ -39,7 +39,6 @@ internal open class SurfaceHandlerBinding(moduleName: String) : HybridClassBase( heightMeasureSpec: Int, offsetX: Int, offsetY: Int, - doLeftAndRightSwapInRTL: Boolean, isRTL: Boolean, pixelDensity: Float, fontScale: Float, @@ -51,7 +50,6 @@ internal open class SurfaceHandlerBinding(moduleName: String) : HybridClassBase( LayoutMetricsConversions.getMaxSize(heightMeasureSpec) / pixelDensity, offsetX / pixelDensity, offsetY / pixelDensity, - doLeftAndRightSwapInRTL, isRTL, pixelDensity, fontScale, @@ -65,7 +63,6 @@ internal open class SurfaceHandlerBinding(moduleName: String) : HybridClassBase( maxHeight: Float, offsetX: Float, offsetY: Float, - doLeftAndRightSwapInRTL: Boolean, isRTL: Boolean, pixelDensity: Float, fontScale: Float, diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.kt index c52101536779..2ca1c15f5287 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.kt @@ -10,10 +10,12 @@ package com.facebook.react.modules.i18nmanager import androidx.core.os.ConfigurationCompat import com.facebook.fbreact.specs.NativeI18nManagerSpec import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.bridge.UiThreadUtil import com.facebook.react.module.annotations.ReactModule +import com.facebook.react.runtime.BridgelessReactContext import java.util.Locale -/** [com.facebook.react.bridge.NativeModule] that allows JS to set allowRTL and get isRTL status. */ +/** [com.facebook.react.bridge.NativeModule] that allows JS to set forceRTL and get isRTL status. */ @ReactModule(name = NativeI18nManagerSpec.NAME) internal class I18nManagerModule(context: ReactApplicationContext?) : NativeI18nManagerSpec(context) { @@ -24,21 +26,24 @@ internal class I18nManagerModule(context: ReactApplicationContext?) : return mapOf( "isRTL" to I18nUtil.instance.isRTL(context), - "doLeftAndRightSwapInRTL" to I18nUtil.instance.doLeftAndRightSwapInRTL(context), - "localeIdentifier" to locale.toString(), + "localeIdentifier" to locale.toLanguageTag(), ) } - override fun allowRTL(value: Boolean) { - I18nUtil.instance.allowRTL(reactApplicationContext, value) - } + override fun forceRTL(value: Boolean): Boolean { + val wasRTL = I18nUtil.instance.isRTL(reactApplicationContext) + I18nUtil.instance.forceRTL(value) + val isRTL = I18nUtil.instance.isRTL(reactApplicationContext) - override fun forceRTL(value: Boolean) { - I18nUtil.instance.forceRTL(reactApplicationContext, value) - } + if (isRTL != wasRTL) { + // Returns before the relayout, so JS reads the new value before any layout event + UiThreadUtil.runOnUiThread { + (reactApplicationContext as? BridgelessReactContext) + ?.updateLayoutDirectionOfAttachedSurfaces() + } + } - override fun swapLeftAndRightInRTL(value: Boolean) { - I18nUtil.instance.swapLeftAndRightInRTL(reactApplicationContext, value) + return isRTL } companion object { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.kt index b991a34bdcf4..d3311dc9a019 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.kt @@ -15,14 +15,16 @@ import androidx.core.text.TextUtilsCompat import java.util.Locale public class I18nUtil private constructor() { + @Volatile private var rtlForced: Boolean = false + /** - * Check if the device is currently running on an RTL locale. This only happens when the app: + * Check if the device is currently running on an RTL locale. This only happens when the app + * supports RTL, and: * * is forcing RTL layout, regardless of the active language (for development purpose) - * * allows RTL layout when using RTL locale + * * or is running on an RTL locale */ public fun isRTL(context: Context): Boolean = - applicationHasRtlSupport(context) && - (isRTLForced(context) || (isRTLAllowed(context) && isDevicePreferredLanguageRTL(context))) + applicationHasRtlSupport(context) && (isRTLForced() || isDevicePreferredLanguageRTL(context)) /** * Android relies on the presence of `android:supportsRtl="true"` being set in order to resolve @@ -33,32 +35,13 @@ public class I18nUtil private constructor() { return (context.applicationInfo.flags and ApplicationInfo.FLAG_SUPPORTS_RTL) != 0 } - /** - * Should be used very early during app start up Before the bridge is initialized - * - * @return whether the app allows RTL layout, default is true - */ - private fun isRTLAllowed(context: Context): Boolean = - isPrefSet(context, KEY_FOR_PREFS_ALLOWRTL, true) - - public fun allowRTL(context: Context, allowRTL: Boolean) { - setPref(context, KEY_FOR_PREFS_ALLOWRTL, allowRTL) - } - - public fun doLeftAndRightSwapInRTL(context: Context): Boolean = - isPrefSet(context, KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES, true) - - public fun swapLeftAndRightInRTL(context: Context, flip: Boolean) { - setPref(context, KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES, flip) - } - /** Could be used to test RTL layout with English Used for development and testing purpose */ - private fun isRTLForced(context: Context): Boolean = - isPrefSet(context, KEY_FOR_PREFS_FORCERTL, false) || + private fun isRTLForced(): Boolean = + rtlForced || System.getProperty("FORCE_RTL_FOR_TESTING", "false").equals("true", ignoreCase = true) - public fun forceRTL(context: Context, forceRTL: Boolean) { - setPref(context, KEY_FOR_PREFS_FORCERTL, forceRTL) + public fun forceRTL(forceRTL: Boolean) { + rtlForced = forceRTL } // Check if the current device language is RTL @@ -69,27 +52,10 @@ public class I18nUtil private constructor() { return directionality == View.LAYOUT_DIRECTION_RTL } - private fun isPrefSet(context: Context, key: String, defaultValue: Boolean): Boolean = - context - .getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE) - .getBoolean(key, defaultValue) - - private fun setPref(context: Context, key: String, value: Boolean) { - val editor = context.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE).edit() - editor.putBoolean(key, value) - editor.apply() - } - public companion object { public val instance: I18nUtil = I18nUtil() @JvmStatic get() = field - private const val SHARED_PREFS_NAME = "com.facebook.react.modules.i18nmanager.I18nUtil" - private const val KEY_FOR_PREFS_ALLOWRTL = "RCTI18nUtil_allowRTL" - private const val KEY_FOR_PREFS_FORCERTL = "RCTI18nUtil_forceRTL" - private const val KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES = - "RCTI18nUtil_makeRTLFlipLeftAndRightStyles" - /** * We're just re-adding this to reduce a breaking change for libraries in React Native 0.75. * diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.kt index ad604e53a1ef..11a51dd51c62 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.kt @@ -68,6 +68,10 @@ internal class BridgelessReactContext(context: Context, private val reactHost: R override fun getSourceURL(): String? = sourceURLRef.get() + fun updateLayoutDirectionOfAttachedSurfaces() { + reactHost.updateLayoutDirectionOfAttachedSurfaces() + } + fun setSourceURL(sourceURL: String?) { sourceURLRef.set(sourceURL) } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt index f54557bf6906..25052cd3dd5c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt @@ -819,6 +819,12 @@ public class ReactHostImpl( synchronized(attachedSurfaces) { attachedSurfaces.remove(surface) } } + @ThreadConfined(ThreadConfined.UI) + internal fun updateLayoutDirectionOfAttachedSurfaces() { + val surfaces = synchronized(attachedSurfaces) { attachedSurfaces.toList() } + surfaces.forEach { surface -> surface.view?.updateLastLayoutSpecs() } + } + internal fun isSurfaceAttached(surface: ReactSurfaceImpl): Boolean = synchronized(attachedSurfaces) { return attachedSurfaces.contains(surface) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceImpl.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceImpl.kt index a851485cf908..e3de0e1b99f8 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceImpl.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceImpl.kt @@ -75,7 +75,6 @@ internal constructor( MeasureSpec.makeMeasureSpec(displayMetrics.heightPixels, MeasureSpec.AT_MOST), 0, 0, - doRTLSwap(context), isRTL(context), displayMetrics.density, getFontScale(context), @@ -185,7 +184,6 @@ internal constructor( heightMeasureSpec, offsetX, offsetY, - doRTLSwap(context), isRTL(context), context.resources.displayMetrics.density, getFontScale(context), @@ -216,8 +214,5 @@ internal constructor( private fun isRTL(context: Context): Boolean = I18nUtil.instance.isRTL(context) private fun getFontScale(context: Context): Float = context.resources.configuration.fontScale - - private fun doRTLSwap(context: Context): Boolean = - I18nUtil.instance.doLeftAndRightSwapInRTL(context) } } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt index 6ff3c2860575..72d1ff1272b1 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt @@ -118,7 +118,14 @@ public class ReactSurfaceView(context: Context?, internal val surface: ReactSurf override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { // Call updateLayoutSpecs to update locationOnScreen offsets, in case they've changed - if (wasMeasured && changed) { + if (changed) { + updateLastLayoutSpecs() + } + } + + /** Sends the last measured layout specs again, so the surface reads the current RTL values. */ + internal fun updateLastLayoutSpecs() { + if (wasMeasured) { val viewportOffset = viewportOffset surface.updateLayoutSpecs( widthMeasureSpec, diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BackgroundStyleApplicator.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BackgroundStyleApplicator.kt index c3af3626ae6e..844d82a5f731 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BackgroundStyleApplicator.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BackgroundStyleApplicator.kt @@ -479,8 +479,7 @@ public object BackgroundStyleApplicator { */ internal fun getPaddingBoxRect(view: View, outRect: Rect) { val composite = getCompositeBackgroundDrawable(view) - val computedBorderInsets = - composite?.borderInsets?.resolve(composite.layoutDirection, view.context) + val computedBorderInsets = composite?.borderInsets?.resolve(composite.layoutDirection) if (computedBorderInsets == null) { outRect.set(0, 0, view.width, view.height) return @@ -526,8 +525,7 @@ public object BackgroundStyleApplicator { val paddingBoxRect = RectF() - val computedBorderInsets = - composite.borderInsets?.resolve(composite.layoutDirection, view.context) + val computedBorderInsets = composite.borderInsets?.resolve(composite.layoutDirection) paddingBoxRect.left = composite.bounds.left + (computedBorderInsets?.left?.dpToPx() ?: 0f) paddingBoxRect.top = composite.bounds.top + (computedBorderInsets?.top?.dpToPx() ?: 0f) @@ -757,7 +755,6 @@ public object BackgroundStyleApplicator { val computedBorderRadius = composite.borderRadius?.resolve( composite.layoutDirection, - view.context, PixelUtil.toDIPFromPixel(composite.bounds.width().toFloat()), PixelUtil.toDIPFromPixel(composite.bounds.height().toFloat()), ) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.kt index 05b8b123afa8..69ce78861d47 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.kt @@ -14,7 +14,6 @@ import com.facebook.react.common.ReactConstants import com.facebook.react.common.annotations.internal.LegacyArchitecture import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger -import com.facebook.react.modules.i18nmanager.I18nUtil import com.facebook.react.uimanager.annotations.ReactProp import com.facebook.react.uimanager.annotations.ReactPropGroup import com.facebook.yoga.YogaAlign @@ -579,8 +578,7 @@ public open class LayoutShadowNode : ReactShadowNodeImpl() { return } - val spacingType = - maybeTransformLeftRightToStartEnd(ViewProps.PADDING_MARGIN_SPACING_TYPES[index]) + val spacingType = ViewProps.PADDING_MARGIN_SPACING_TYPES[index] tempYogaValue.setFromDynamic(margin) when (tempYogaValue.unit) { @@ -613,8 +611,7 @@ public open class LayoutShadowNode : ReactShadowNodeImpl() { return } - val spacingType = - maybeTransformLeftRightToStartEnd(ViewProps.PADDING_MARGIN_SPACING_TYPES[index]) + val spacingType = ViewProps.PADDING_MARGIN_SPACING_TYPES[index] tempYogaValue.setFromDynamic(padding) when (tempYogaValue.unit) { @@ -644,7 +641,7 @@ public open class LayoutShadowNode : ReactShadowNodeImpl() { if (isVirtual()) { return } - val spacingType = maybeTransformLeftRightToStartEnd(ViewProps.BORDER_SPACING_TYPES[index]) + val spacingType = ViewProps.BORDER_SPACING_TYPES[index] setBorder(spacingType, PixelUtil.toPixelFromDIP(borderWidth)) } @@ -674,7 +671,7 @@ public open class LayoutShadowNode : ReactShadowNodeImpl() { Spacing.BOTTOM, ) - val spacingType = maybeTransformLeftRightToStartEnd(positionSpacingTypes[index]) + val spacingType = positionSpacingTypes[index] tempYogaValue.setFromDynamic(position) when (tempYogaValue.unit) { @@ -687,18 +684,6 @@ public open class LayoutShadowNode : ReactShadowNodeImpl() { position.recycle() } - private fun maybeTransformLeftRightToStartEnd(spacingType: Int): Int { - if (!I18nUtil.instance.doLeftAndRightSwapInRTL(getThemedContext())) { - return spacingType - } - - return when (spacingType) { - Spacing.LEFT -> Spacing.START - Spacing.RIGHT -> Spacing.END - else -> spacingType - } - } - @ReactProp(name = ViewProps.POSITION) public open fun setPosition(position: String?) { if (isVirtual()) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BackgroundDrawable.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BackgroundDrawable.kt index d5a2c2d342aa..d0d9eced5948 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BackgroundDrawable.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BackgroundDrawable.kt @@ -115,7 +115,7 @@ internal class BackgroundDrawable( } private fun computeBorderInsets(): RectF = - borderInsets?.resolve(layoutDirection, context).let { + borderInsets?.resolve(layoutDirection).let { RectF( it?.left?.dpToPx() ?: 0f, it?.top?.dpToPx() ?: 0f, @@ -136,7 +136,6 @@ internal class BackgroundDrawable( computedBorderRadius = borderRadius?.resolve( layoutDirection, - context, bounds.width().pxToDp(), bounds.height().pxToDp(), ) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BackgroundImageDrawable.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BackgroundImageDrawable.kt index 66e04d3e7cbc..eabd44d33ac5 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BackgroundImageDrawable.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BackgroundImageDrawable.kt @@ -267,7 +267,7 @@ internal class BackgroundImageDrawable( } private fun computeBorderInsets(): RectF = - borderInsets?.resolve(layoutDirection, context).let { + borderInsets?.resolve(layoutDirection).let { RectF( it?.left?.dpToPx() ?: 0f, it?.top?.dpToPx() ?: 0f, @@ -309,7 +309,6 @@ internal class BackgroundImageDrawable( val computedBorderRadius = borderRadius?.resolve( layoutDirection, - context, bounds.width().pxToDp(), bounds.height().pxToDp(), ) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BorderDrawable.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BorderDrawable.kt index ef22623c9cff..41fe8bb7553b 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BorderDrawable.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BorderDrawable.kt @@ -170,7 +170,7 @@ internal class BorderDrawable( override fun draw(canvas: Canvas) { updatePathEffect() - computedBorderColors = borderColors?.resolve(layoutDirection, context) ?: computedBorderColors + computedBorderColors = borderColors?.resolve(layoutDirection) ?: computedBorderColors if (borderRadius?.hasRoundedBorders() == true) { drawRoundedBorders(canvas) } else { @@ -547,7 +547,7 @@ internal class BorderDrawable( } private fun computeBorderInsets(): RectF { - borderInsets?.resolve(layoutDirection, context)?.let { + borderInsets?.resolve(layoutDirection)?.let { return RectF( if (it.left.isNaN()) 0f else it.left.dpToPx(), if (it.top.isNaN()) 0f else it.top.dpToPx(), @@ -715,7 +715,6 @@ internal class BorderDrawable( computedBorderRadius = this.borderRadius?.resolve( layoutDirection, - this.context, outerClipTempRectForBorderRadius?.width()?.pxToDp() ?: 0f, outerClipTempRectForBorderRadius?.height()?.pxToDp() ?: 0f, ) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/CompositeBackgroundDrawable.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/CompositeBackgroundDrawable.kt index b42948166d46..339b65be4f66 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/CompositeBackgroundDrawable.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/CompositeBackgroundDrawable.kt @@ -206,12 +206,11 @@ internal class CompositeBackgroundDrawable( val computedBorderRadius = borderRadius?.resolve( layoutDirection, - context, bounds.width().toFloat(), bounds.height().toFloat(), ) - val computedBorderInsets = borderInsets?.resolve(layoutDirection, context) + val computedBorderInsets = borderInsets?.resolve(layoutDirection) val radii = computedBorderRadius?.let { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/InsetBoxShadowDrawable.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/InsetBoxShadowDrawable.kt index c59484be0f7f..275ae52bd886 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/InsetBoxShadowDrawable.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/InsetBoxShadowDrawable.kt @@ -152,7 +152,6 @@ internal class InsetBoxShadowDrawable( val resolvedBorderRadii = borderRadius?.resolve( layoutDirection, - context, bounds.width().toFloat().pxToDp(), bounds.height().toFloat().pxToDp(), ) @@ -186,7 +185,7 @@ internal class InsetBoxShadowDrawable( } private fun computeBorderInsets(): RectF? = - borderInsets?.resolve(layoutDirection, context)?.let { + borderInsets?.resolve(layoutDirection)?.let { RectF(it.left.dpToPx(), it.top.dpToPx(), it.right.dpToPx(), it.bottom.dpToPx()) } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/OutlineDrawable.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/OutlineDrawable.kt index e544e3122b9a..9a5618e81ea0 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/OutlineDrawable.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/OutlineDrawable.kt @@ -124,7 +124,6 @@ internal class OutlineDrawable( computedBorderRadius = borderRadius?.resolve( layoutDirection, - context, bounds.width().pxToDp(), bounds.height().pxToDp(), ) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/OutsetBoxShadowDrawable.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/OutsetBoxShadowDrawable.kt index c67596d44bea..95cfa66ee38a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/OutsetBoxShadowDrawable.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/OutsetBoxShadowDrawable.kt @@ -81,7 +81,7 @@ internal class OutsetBoxShadowDrawable( val resolutionWidth = bounds.width().toFloat().pxToDp() val resolutionHeight = bounds.height().toFloat().pxToDp() val computedBorderRadii = - borderRadius?.resolve(layoutDirection, context, resolutionWidth, resolutionHeight)?.let { + borderRadius?.resolve(layoutDirection, resolutionWidth, resolutionHeight)?.let { ComputedBorderRadius( topLeft = CornerRadii(it.topLeft.horizontal.dpToPx(), it.topLeft.vertical.dpToPx()), topRight = diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderColors.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderColors.kt index 4969be54eecb..da1006b3edf3 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderColors.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderColors.kt @@ -7,11 +7,9 @@ package com.facebook.react.uimanager.style -import android.content.Context import android.graphics.Color import android.util.LayoutDirection import androidx.annotation.ColorInt -import com.facebook.react.modules.i18nmanager.I18nUtil /** * Represents resolved border colors for all four physical edges of a box. @@ -49,16 +47,14 @@ internal value class BorderColors( /** * Resolves logical edge colors to physical edge colors based on layout direction. * - * This method handles RTL layout direction and the doLeftAndRightSwapInRTL setting to correctly - * map logical properties (start, end, block-start, block-end) to physical edges (left, right, - * top, bottom). + * This method handles RTL layout direction to correctly map logical properties (start, end, + * block-start, block-end) to physical edges (left, right, top, bottom). * * @param layoutDirection The resolved layout direction (LTR or RTL) - * @param context Android context for RTL swap preference * @return ColorEdges with resolved physical edge colors * @throws IllegalArgumentException if layoutDirection is not LTR or RTL */ - fun resolve(layoutDirection: Int, context: Context): ColorEdges { + fun resolve(layoutDirection: Int): ColorEdges { return when (layoutDirection) { LayoutDirection.LTR -> ColorEdges( @@ -86,57 +82,30 @@ internal value class BorderColors( ?: Color.BLACK, ) LayoutDirection.RTL -> - if (I18nUtil.instance.doLeftAndRightSwapInRTL(context)) { - ColorEdges( - edgeColors[LogicalEdge.END.ordinal] - ?: edgeColors[LogicalEdge.RIGHT.ordinal] - ?: edgeColors[LogicalEdge.HORIZONTAL.ordinal] - ?: edgeColors[LogicalEdge.ALL.ordinal] - ?: Color.BLACK, - edgeColors[LogicalEdge.BLOCK_START.ordinal] - ?: edgeColors[LogicalEdge.TOP.ordinal] - ?: edgeColors[LogicalEdge.BLOCK.ordinal] - ?: edgeColors[LogicalEdge.VERTICAL.ordinal] - ?: edgeColors[LogicalEdge.ALL.ordinal] - ?: Color.BLACK, - edgeColors[LogicalEdge.START.ordinal] - ?: edgeColors[LogicalEdge.LEFT.ordinal] - ?: edgeColors[LogicalEdge.HORIZONTAL.ordinal] - ?: edgeColors[LogicalEdge.ALL.ordinal] - ?: Color.BLACK, - edgeColors[LogicalEdge.BLOCK_END.ordinal] - ?: edgeColors[LogicalEdge.BOTTOM.ordinal] - ?: edgeColors[LogicalEdge.BLOCK.ordinal] - ?: edgeColors[LogicalEdge.VERTICAL.ordinal] - ?: edgeColors[LogicalEdge.ALL.ordinal] - ?: Color.BLACK, - ) - } else { - ColorEdges( - edgeColors[LogicalEdge.END.ordinal] - ?: edgeColors[LogicalEdge.LEFT.ordinal] - ?: edgeColors[LogicalEdge.HORIZONTAL.ordinal] - ?: edgeColors[LogicalEdge.ALL.ordinal] - ?: Color.BLACK, - edgeColors[LogicalEdge.BLOCK_START.ordinal] - ?: edgeColors[LogicalEdge.TOP.ordinal] - ?: edgeColors[LogicalEdge.BLOCK.ordinal] - ?: edgeColors[LogicalEdge.VERTICAL.ordinal] - ?: edgeColors[LogicalEdge.ALL.ordinal] - ?: Color.BLACK, - edgeColors[LogicalEdge.START.ordinal] - ?: edgeColors[LogicalEdge.RIGHT.ordinal] - ?: edgeColors[LogicalEdge.HORIZONTAL.ordinal] - ?: edgeColors[LogicalEdge.ALL.ordinal] - ?: Color.BLACK, - edgeColors[LogicalEdge.BLOCK_END.ordinal] - ?: edgeColors[LogicalEdge.BOTTOM.ordinal] - ?: edgeColors[LogicalEdge.BLOCK.ordinal] - ?: edgeColors[LogicalEdge.VERTICAL.ordinal] - ?: edgeColors[LogicalEdge.ALL.ordinal] - ?: Color.BLACK, - ) - } + ColorEdges( + edgeColors[LogicalEdge.END.ordinal] + ?: edgeColors[LogicalEdge.LEFT.ordinal] + ?: edgeColors[LogicalEdge.HORIZONTAL.ordinal] + ?: edgeColors[LogicalEdge.ALL.ordinal] + ?: Color.BLACK, + edgeColors[LogicalEdge.BLOCK_START.ordinal] + ?: edgeColors[LogicalEdge.TOP.ordinal] + ?: edgeColors[LogicalEdge.BLOCK.ordinal] + ?: edgeColors[LogicalEdge.VERTICAL.ordinal] + ?: edgeColors[LogicalEdge.ALL.ordinal] + ?: Color.BLACK, + edgeColors[LogicalEdge.START.ordinal] + ?: edgeColors[LogicalEdge.RIGHT.ordinal] + ?: edgeColors[LogicalEdge.HORIZONTAL.ordinal] + ?: edgeColors[LogicalEdge.ALL.ordinal] + ?: Color.BLACK, + edgeColors[LogicalEdge.BLOCK_END.ordinal] + ?: edgeColors[LogicalEdge.BOTTOM.ordinal] + ?: edgeColors[LogicalEdge.BLOCK.ordinal] + ?: edgeColors[LogicalEdge.VERTICAL.ordinal] + ?: edgeColors[LogicalEdge.ALL.ordinal] + ?: Color.BLACK, + ) else -> throw IllegalArgumentException("Expected resolved layout direction") } } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderInsets.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderInsets.kt index 26ed8034f97f..7723d0c8b5bc 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderInsets.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderInsets.kt @@ -7,10 +7,8 @@ package com.facebook.react.uimanager.style -import android.content.Context import android.graphics.RectF import android.util.LayoutDirection -import com.facebook.react.modules.i18nmanager.I18nUtil /** * Represents the insets from border box to padding box (i.e., border widths). @@ -36,17 +34,15 @@ internal class BorderInsets { /** * Resolves logical edge insets to physical edge insets based on layout direction. * - * This method handles LTR/RTL layout direction and the doLeftAndRightSwapInRTL setting to - * correctly map logical properties to physical edges. + * This method handles LTR/RTL layout direction to correctly map logical properties to physical + * edges. * * @param layoutDirection The resolved layout direction (LTR or RTL) - * @param context Android context for RTL swap preference * @return RectF with left, top, right, bottom insets * @throws IllegalArgumentException if layoutDirection is not LTR or RTL */ fun resolve( layoutDirection: Int, - context: Context, ): RectF { return when (layoutDirection) { LayoutDirection.LTR -> @@ -75,57 +71,30 @@ internal class BorderInsets { ?: 0f, ) LayoutDirection.RTL -> - if (I18nUtil.instance.doLeftAndRightSwapInRTL(context)) { - RectF( - edgeInsets[LogicalEdge.END.ordinal] - ?: edgeInsets[LogicalEdge.RIGHT.ordinal] - ?: edgeInsets[LogicalEdge.HORIZONTAL.ordinal] - ?: edgeInsets[LogicalEdge.ALL.ordinal] - ?: 0f, - edgeInsets[LogicalEdge.BLOCK_START.ordinal] - ?: edgeInsets[LogicalEdge.TOP.ordinal] - ?: edgeInsets[LogicalEdge.BLOCK.ordinal] - ?: edgeInsets[LogicalEdge.VERTICAL.ordinal] - ?: edgeInsets[LogicalEdge.ALL.ordinal] - ?: 0f, - edgeInsets[LogicalEdge.START.ordinal] - ?: edgeInsets[LogicalEdge.LEFT.ordinal] - ?: edgeInsets[LogicalEdge.HORIZONTAL.ordinal] - ?: edgeInsets[LogicalEdge.ALL.ordinal] - ?: 0f, - edgeInsets[LogicalEdge.BLOCK_END.ordinal] - ?: edgeInsets[LogicalEdge.BOTTOM.ordinal] - ?: edgeInsets[LogicalEdge.BLOCK.ordinal] - ?: edgeInsets[LogicalEdge.VERTICAL.ordinal] - ?: edgeInsets[LogicalEdge.ALL.ordinal] - ?: 0f, - ) - } else { - RectF( - edgeInsets[LogicalEdge.END.ordinal] - ?: edgeInsets[LogicalEdge.LEFT.ordinal] - ?: edgeInsets[LogicalEdge.HORIZONTAL.ordinal] - ?: edgeInsets[LogicalEdge.ALL.ordinal] - ?: 0f, - edgeInsets[LogicalEdge.BLOCK_START.ordinal] - ?: edgeInsets[LogicalEdge.TOP.ordinal] - ?: edgeInsets[LogicalEdge.BLOCK.ordinal] - ?: edgeInsets[LogicalEdge.VERTICAL.ordinal] - ?: edgeInsets[LogicalEdge.ALL.ordinal] - ?: 0f, - edgeInsets[LogicalEdge.START.ordinal] - ?: edgeInsets[LogicalEdge.RIGHT.ordinal] - ?: edgeInsets[LogicalEdge.HORIZONTAL.ordinal] - ?: edgeInsets[LogicalEdge.ALL.ordinal] - ?: 0f, - edgeInsets[LogicalEdge.BLOCK_END.ordinal] - ?: edgeInsets[LogicalEdge.BOTTOM.ordinal] - ?: edgeInsets[LogicalEdge.BLOCK.ordinal] - ?: edgeInsets[LogicalEdge.VERTICAL.ordinal] - ?: edgeInsets[LogicalEdge.ALL.ordinal] - ?: 0f, - ) - } + RectF( + edgeInsets[LogicalEdge.END.ordinal] + ?: edgeInsets[LogicalEdge.LEFT.ordinal] + ?: edgeInsets[LogicalEdge.HORIZONTAL.ordinal] + ?: edgeInsets[LogicalEdge.ALL.ordinal] + ?: 0f, + edgeInsets[LogicalEdge.BLOCK_START.ordinal] + ?: edgeInsets[LogicalEdge.TOP.ordinal] + ?: edgeInsets[LogicalEdge.BLOCK.ordinal] + ?: edgeInsets[LogicalEdge.VERTICAL.ordinal] + ?: edgeInsets[LogicalEdge.ALL.ordinal] + ?: 0f, + edgeInsets[LogicalEdge.START.ordinal] + ?: edgeInsets[LogicalEdge.RIGHT.ordinal] + ?: edgeInsets[LogicalEdge.HORIZONTAL.ordinal] + ?: edgeInsets[LogicalEdge.ALL.ordinal] + ?: 0f, + edgeInsets[LogicalEdge.BLOCK_END.ordinal] + ?: edgeInsets[LogicalEdge.BOTTOM.ordinal] + ?: edgeInsets[LogicalEdge.BLOCK.ordinal] + ?: edgeInsets[LogicalEdge.VERTICAL.ordinal] + ?: edgeInsets[LogicalEdge.ALL.ordinal] + ?: 0f, + ) else -> throw IllegalArgumentException("Expected resolved layout direction") } } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderRadiusStyle.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderRadiusStyle.kt index 17cdbdb099fb..f9796ec4ee61 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderRadiusStyle.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/BorderRadiusStyle.kt @@ -7,9 +7,7 @@ package com.facebook.react.uimanager.style -import android.content.Context import android.util.LayoutDirection -import com.facebook.react.modules.i18nmanager.I18nUtil import com.facebook.react.uimanager.LengthPercentage /** @@ -140,14 +138,12 @@ internal data class BorderRadiusStyle( * corner radii do not overlap per the CSS specification. * * @param layoutDirection The resolved layout direction (LTR or RTL) - * @param context Android context for RTL configuration * @param width The width of the element for percentage resolution * @param height The height of the element for percentage resolution * @return ComputedBorderRadius with resolved physical corner radii */ fun resolve( layoutDirection: Int, - context: Context, width: Float, height: Float, ): ComputedBorderRadius { @@ -176,49 +172,25 @@ internal data class BorderRadiusStyle( height = height, ) LayoutDirection.RTL -> - if (I18nUtil.instance.doLeftAndRightSwapInRTL(context)) { - ensureNoOverlap( - topLeft = - (startEnd ?: topEnd ?: topRight ?: uniform)?.let { - CornerRadii(it, width, height) - } ?: zeroRadii, - topRight = - (startStart ?: topStart ?: topLeft ?: uniform)?.let { - CornerRadii(it, width, height) - } ?: zeroRadii, - bottomLeft = - (endEnd ?: bottomEnd ?: bottomRight ?: uniform)?.let { - CornerRadii(it, width, height) - } ?: zeroRadii, - bottomRight = - (endStart ?: bottomStart ?: bottomLeft ?: uniform)?.let { - CornerRadii(it, width, height) - } ?: zeroRadii, - width = width, - height = height, - ) - } else { - ensureNoOverlap( - topLeft = - (startEnd ?: topEnd ?: topLeft ?: uniform)?.let { - CornerRadii(it, width, height) - } ?: zeroRadii, - topRight = - (startStart ?: topStart ?: topRight ?: uniform)?.let { - CornerRadii(it, width, height) - } ?: zeroRadii, - bottomLeft = - (endEnd ?: bottomEnd ?: bottomLeft ?: uniform)?.let { - CornerRadii(it, width, height) - } ?: zeroRadii, - bottomRight = - (endStart ?: bottomStart ?: bottomRight ?: uniform)?.let { - CornerRadii(it, width, height) - } ?: zeroRadii, - width = width, - height = height, - ) - } + ensureNoOverlap( + topLeft = + (startEnd ?: topEnd ?: topLeft ?: uniform)?.let { CornerRadii(it, width, height) } + ?: zeroRadii, + topRight = + (startStart ?: topStart ?: topRight ?: uniform)?.let { + CornerRadii(it, width, height) + } ?: zeroRadii, + bottomLeft = + (endEnd ?: bottomEnd ?: bottomLeft ?: uniform)?.let { + CornerRadii(it, width, height) + } ?: zeroRadii, + bottomRight = + (endStart ?: bottomStart ?: bottomRight ?: uniform)?.let { + CornerRadii(it, width, height) + } ?: zeroRadii, + width = width, + height = height, + ) else -> throw IllegalArgumentException("Expected?.resolved layout direction") } } diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp index 8cff9f825b58..23fcf83d4f71 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp @@ -360,8 +360,7 @@ void FabricUIManagerBinding::startSurfaceWithConstraints( jfloat maxHeight, jfloat offsetX, jfloat offsetY, - jboolean isRTL, - jboolean doLeftAndRightSwapInRTL) { + jboolean isRTL) { TraceSection s("FabricUIManagerBinding::startSurfaceWithConstraints"); if (enableFabricLogs_) { @@ -388,7 +387,6 @@ void FabricUIManagerBinding::startSurfaceWithConstraints( context.viewportOffset = Point{.x = offsetX / pointScaleFactor_, .y = offsetY / pointScaleFactor_}; context.pointScaleFactor = {pointScaleFactor_}; - context.swapLeftAndRightInRTL = doLeftAndRightSwapInRTL != 0; LayoutConstraints constraints = {}; constraints.minimumSize = minimumSize; constraints.maximumSize = maximumSize; @@ -514,8 +512,7 @@ void FabricUIManagerBinding::setConstraints( jfloat maxHeight, jfloat offsetX, jfloat offsetY, - jboolean isRTL, - jboolean doLeftAndRightSwapInRTL) { + jboolean isRTL) { TraceSection s("FabricUIManagerBinding::setConstraints"); auto scheduler = getScheduler(); @@ -536,7 +533,6 @@ void FabricUIManagerBinding::setConstraints( context.viewportOffset = Point{.x = offsetX / pointScaleFactor_, .y = offsetY / pointScaleFactor_}; context.pointScaleFactor = {pointScaleFactor_}; - context.swapLeftAndRightInRTL = doLeftAndRightSwapInRTL != 0; LayoutConstraints constraints = {}; constraints.minimumSize = minimumSize; constraints.maximumSize = maximumSize; diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h index 68c47706ba7b..8d0f7197b7a2 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h @@ -56,8 +56,7 @@ class FabricUIManagerBinding : public jni::HybridClass, jfloat maxHeight, jfloat offsetX, jfloat offsetY, - jboolean isRTL, - jboolean doLeftAndRightSwapInRTL); + jboolean isRTL); static void initHybrid(jni::alias_ref jobj); @@ -80,8 +79,7 @@ class FabricUIManagerBinding : public jni::HybridClass, jfloat maxHeight, jfloat offsetX, jfloat offsetY, - jboolean isRTL, - jboolean doLeftAndRightSwapInRTL); + jboolean isRTL); void stopSurface(jint surfaceId); diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.cpp index 3264f113963d..0d0788e0d404 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.cpp @@ -46,7 +46,6 @@ void SurfaceHandlerBinding::setLayoutConstraints( jfloat maxHeight, jfloat offsetX, jfloat offsetY, - jboolean doLeftAndRightSwapInRTL, jboolean isRTL, jfloat pixelDensity, jfloat fontScale) { @@ -57,7 +56,6 @@ void SurfaceHandlerBinding::setLayoutConstraints( : LayoutDirection::LeftToRight; LayoutContext context = {}; - context.swapLeftAndRightInRTL = (doLeftAndRightSwapInRTL != 0u); context.pointScaleFactor = pixelDensity; context.viewportOffset = {.x = offsetX, .y = offsetY}; context.viewportSize = {.width = maxWidth, .height = maxHeight}; diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.h index fe687d148abc..8b064e99805c 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.h @@ -37,7 +37,6 @@ class SurfaceHandlerBinding : public jni::HybridClass { jfloat maxHeight, jfloat offsetX, jfloat offsetY, - jboolean doLeftAndRightSwapInRTL, jboolean isRTL, jfloat pixelDensity, jfloat fontScale); diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/test/SurfaceHandlerBindingTest.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/test/SurfaceHandlerBindingTest.cpp index 889753a55668..9b9755382efb 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/test/SurfaceHandlerBindingTest.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/test/SurfaceHandlerBindingTest.cpp @@ -33,7 +33,6 @@ TEST_F( /*maxHeight=*/640.0f, /*offsetX=*/3.0f, /*offsetY=*/4.0f, - /*doLeftAndRightSwapInRTL=*/1, /*isRTL=*/1, /*pixelDensity=*/2.0f, /*fontScale=*/1.25f); @@ -52,7 +51,6 @@ TEST_F( EXPECT_FLOAT_EQ(4.0f, layoutContext.viewportOffset.y); EXPECT_FLOAT_EQ(320.0f, layoutContext.viewportSize.width); EXPECT_FLOAT_EQ(640.0f, layoutContext.viewportSize.height); - EXPECT_TRUE(layoutContext.swapLeftAndRightInRTL); EXPECT_FLOAT_EQ(2.0f, layoutContext.pointScaleFactor); EXPECT_FLOAT_EQ(1.25f, layoutContext.fontSizeMultiplier); } @@ -69,7 +67,6 @@ TEST_F( /*maxHeight=*/400.0f, /*offsetX=*/0.0f, /*offsetY=*/0.0f, - /*doLeftAndRightSwapInRTL=*/0, /*isRTL=*/0, /*pixelDensity=*/1.0f, /*fontScale=*/1.0f); @@ -79,7 +76,6 @@ TEST_F( EXPECT_EQ( LayoutDirection::LeftToRight, surfaceHandler.getLayoutConstraints().layoutDirection); - EXPECT_FALSE(surfaceHandler.getLayoutContext().swapLeftAndRightInRTL); } TEST_F( diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/FabricMountingManagerInstrumentationTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/FabricMountingManagerInstrumentationTest.kt index 01f8a3e5b386..68adc824294a 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/FabricMountingManagerInstrumentationTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/FabricMountingManagerInstrumentationTest.kt @@ -605,7 +605,6 @@ class FabricMountingManagerInstrumentationTest { 0, 0, false, - false, 1f, 1f, ) diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/runtime/ReactSurfaceTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/runtime/ReactSurfaceTest.kt index d2914c8f4336..3b31ae170081 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/runtime/ReactSurfaceTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/runtime/ReactSurfaceTest.kt @@ -128,7 +128,7 @@ class ReactSurfaceTest { reactSurface.attach(reactHost) reactSurface.updateLayoutSpecs(measureSpecWidth, measureSpecHeight, 2, 3) verify(surfaceHandler) - .setLayoutConstraints(measureSpecWidth, measureSpecHeight, 2, 3, true, false, 1.0f, 1.0f) + .setLayoutConstraints(measureSpecWidth, measureSpecHeight, 2, 3, false, 1.0f, 1.0f) } @Test diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BorderRadiusStyleTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BorderRadiusStyleTest.kt index f28972f3c1c7..e1274b92760d 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BorderRadiusStyleTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BorderRadiusStyleTest.kt @@ -7,7 +7,6 @@ package com.facebook.react.uimanager -import android.content.Context import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests import com.facebook.react.uimanager.style.BorderRadiusProp import com.facebook.react.uimanager.style.BorderRadiusStyle @@ -18,14 +17,11 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner -import org.robolectric.RuntimeEnvironment /** Tests for [BorderRadiusStyle] */ @RunWith(RobolectricTestRunner::class) class BorderRadiusStyleTest { - private val ctx: Context = RuntimeEnvironment.getApplication() - @Test fun testCorrectPriorityLTR() { val propertyOrderMap = @@ -66,7 +62,7 @@ class BorderRadiusStyleTest { var count = 3f for (prop in order.value) { borderRadiusStyle.set(prop, LengthPercentage(count, LengthPercentageType.POINT)) - val resolved = borderRadiusStyle.resolve(0, context = ctx, width = 100f, height = 100f) + val resolved = borderRadiusStyle.resolve(0, width = 100f, height = 100f) assertThat(resolved.get(order.key)).isEqualTo(CornerRadii(count, count)) count -= 1f } @@ -80,55 +76,6 @@ class BorderRadiusStyleTest { @Test fun testCorrectPriorityRTL() { - setContextLeftAndRightSwap(ctx, true) - val propertyOrderMap = - mapOf( - ComputedBorderRadiusProp.COMPUTED_BORDER_TOP_LEFT_RADIUS to - arrayOf( - BorderRadiusProp.BORDER_RADIUS, - BorderRadiusProp.BORDER_TOP_RIGHT_RADIUS, - BorderRadiusProp.BORDER_TOP_END_RADIUS, - BorderRadiusProp.BORDER_START_END_RADIUS, - ), - ComputedBorderRadiusProp.COMPUTED_BORDER_TOP_RIGHT_RADIUS to - arrayOf( - BorderRadiusProp.BORDER_RADIUS, - BorderRadiusProp.BORDER_TOP_LEFT_RADIUS, - BorderRadiusProp.BORDER_TOP_START_RADIUS, - BorderRadiusProp.BORDER_START_START_RADIUS, - ), - ComputedBorderRadiusProp.COMPUTED_BORDER_BOTTOM_LEFT_RADIUS to - arrayOf( - BorderRadiusProp.BORDER_RADIUS, - BorderRadiusProp.BORDER_BOTTOM_RIGHT_RADIUS, - BorderRadiusProp.BORDER_BOTTOM_END_RADIUS, - BorderRadiusProp.BORDER_END_END_RADIUS, - ), - ComputedBorderRadiusProp.COMPUTED_BORDER_BOTTOM_RIGHT_RADIUS to - arrayOf( - BorderRadiusProp.BORDER_RADIUS, - BorderRadiusProp.BORDER_BOTTOM_LEFT_RADIUS, - BorderRadiusProp.BORDER_BOTTOM_START_RADIUS, - BorderRadiusProp.BORDER_END_START_RADIUS, - ), - ) - - propertyOrderMap.forEach { order -> - val borderRadiusStyle = BorderRadiusStyle() - // Starting count on 3 to test 0 override - var count = 3f - for (prop in order.value) { - borderRadiusStyle.set(prop, LengthPercentage(count, LengthPercentageType.POINT)) - val resolved = borderRadiusStyle.resolve(1, context = ctx, width = 100f, height = 100f) - assertThat(resolved.get(order.key)).isEqualTo(CornerRadii(count, count)) - count -= 1f - } - } - } - - @Test - fun testCorrectPriorityRTLNoSwap() { - setContextLeftAndRightSwap(ctx, false) val propertyOrderMap = mapOf( ComputedBorderRadiusProp.COMPUTED_BORDER_TOP_LEFT_RADIUS to @@ -167,7 +114,7 @@ class BorderRadiusStyleTest { var count = 3f for (prop in order.value) { borderRadiusStyle.set(prop, LengthPercentage(count, LengthPercentageType.POINT)) - val resolved = borderRadiusStyle.resolve(1, context = ctx, width = 100f, height = 100f) + val resolved = borderRadiusStyle.resolve(1, width = 100f, height = 100f) assertThat(resolved.get(order.key)).isEqualTo(CornerRadii(count, count)) count -= 1f } @@ -175,20 +122,17 @@ class BorderRadiusStyleTest { } @Test - fun testBottomLogicalCornersRTLRegardlessOfSwap() { + fun testBottomLogicalCornersRTL() { val borderRadiusStyle = BorderRadiusStyle( bottomStart = LengthPercentage(10f, LengthPercentageType.POINT), bottomEnd = LengthPercentage(20f, LengthPercentageType.POINT), ) - for (swap in listOf(false, true)) { - setContextLeftAndRightSwap(ctx, swap) - val resolved = borderRadiusStyle.resolve(1, context = ctx, width = 100f, height = 100f) + val resolved = borderRadiusStyle.resolve(1, width = 100f, height = 100f) - assertThat(resolved.bottomLeft).isEqualTo(CornerRadii(20f, 20f)) - assertThat(resolved.bottomRight).isEqualTo(CornerRadii(10f, 10f)) - } + assertThat(resolved.bottomLeft).isEqualTo(CornerRadii(20f, 20f)) + assertThat(resolved.bottomRight).isEqualTo(CornerRadii(10f, 10f)) } @Test @@ -200,26 +144,11 @@ class BorderRadiusStyleTest { bottomLeft = LengthPercentage(20f, LengthPercentageType.PERCENT), bottomRight = LengthPercentage(30f, LengthPercentageType.PERCENT), ) - val resolved = borderRadiusStyle.resolve(0, context = ctx, width = 1000f, height = 1000f) + val resolved = borderRadiusStyle.resolve(0, width = 1000f, height = 1000f) assertThat(resolved.topLeft).isEqualTo(CornerRadii(0f, 0f)) assertThat(resolved.topRight).isEqualTo(CornerRadii(100f, 100f)) assertThat(resolved.bottomLeft).isEqualTo(CornerRadii(200f, 200f)) assertThat(resolved.bottomRight).isEqualTo(CornerRadii(300f, 300f)) } - - /* - * Make I18nUtil.instance.doLeftAndRightSwapInRTL(context) return false - * by setting context preference - */ - private fun setContextLeftAndRightSwap(context: Context, leftAndRightSwap: Boolean) { - val sharedPrefs = - context.getSharedPreferences( - "com.facebook.react.modules.i18nmanager.I18nUtil", - Context.MODE_PRIVATE, - ) - val editor = sharedPrefs.edit() - editor.putBoolean("RCTI18nUtil_makeRTLFlipLeftAndRightStyles", leftAndRightSwap) - editor.apply() - } } diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/style/BorderInsetsTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/style/BorderInsetsTest.kt index 2dccb5ee9e9f..7670b106cc3f 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/style/BorderInsetsTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/style/BorderInsetsTest.kt @@ -7,12 +7,10 @@ package com.facebook.react.uimanager.style -import android.content.Context import android.util.LayoutDirection import org.assertj.core.api.Assertions.assertThat import org.junit.Test import org.junit.runner.RunWith -import org.mockito.kotlin.mock import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) @@ -23,7 +21,7 @@ class BorderInsetsTest { borderInsets.setBorderWidth(LogicalEdge.ALL, 4f) borderInsets.setBorderWidth(LogicalEdge.LEFT, Float.NaN) - val resolved = borderInsets.resolve(LayoutDirection.LTR, mock()) + val resolved = borderInsets.resolve(LayoutDirection.LTR) assertThat(resolved.left).isEqualTo(4f) assertThat(resolved.top).isEqualTo(4f) diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp index c7d04022fe2e..e34b0441c9aa 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp @@ -490,8 +490,7 @@ void YogaLayoutableShadowNode::updateYogaProps() { void YogaLayoutableShadowNode::configureYogaTree( float pointScaleFactor, Float fontSizeMultiplier, - YGErrata defaultErrata, - bool swapLeftAndRight) { + YGErrata defaultErrata) { ensureUnsealed(); // Set state on our own Yoga node @@ -511,11 +510,6 @@ void YogaLayoutableShadowNode::configureYogaTree( yogaNode_.markDirtyAndPropagate(); } - // TODO: `swapLeftAndRight` modified backing props and cannot be undone - if (swapLeftAndRight) { - swapStyleLeftAndRight(); - } - yogaTreeHasBeenConfigured_ = true; // Recursively propagate the configuration to child nodes. If a child was @@ -531,7 +525,6 @@ void YogaLayoutableShadowNode::configureYogaTree( childLayoutMetrics.pointScaleFactor == pointScaleFactor && floatEquality( childLayoutMetrics.fontSizeMultiplier, fontSizeMultiplier) && - childLayoutMetrics.wasLeftAndRightSwapped == swapLeftAndRight && childErrata == child.resolveErrata(errata)) { continue; } @@ -539,13 +532,10 @@ void YogaLayoutableShadowNode::configureYogaTree( if (doesOwn(child)) { auto& mutableChild = const_cast(child); mutableChild.configureYogaTree( - pointScaleFactor, - fontSizeMultiplier, - child.resolveErrata(errata), - swapLeftAndRight); + pointScaleFactor, fontSizeMultiplier, child.resolveErrata(errata)); } else { cloneChildInPlace(i).configureYogaTree( - pointScaleFactor, fontSizeMultiplier, errata, swapLeftAndRight); + pointScaleFactor, fontSizeMultiplier, errata); } // An in-place clone can come back dirty without dirtying this node, from @@ -662,16 +652,12 @@ void YogaLayoutableShadowNode::layoutTree( TraceSection s1("YogaLayoutableShadowNode::layoutTree"); - bool swapLeftAndRight = layoutContext.swapLeftAndRightInRTL && - layoutConstraints.layoutDirection == LayoutDirection::RightToLeft; - { TraceSection s2("YogaLayoutableShadowNode::configureYogaTree"); configureYogaTree( layoutContext.pointScaleFactor, layoutContext.fontSizeMultiplier, - YGErrataAll /*defaultErrata*/, - swapLeftAndRight); + YGErrataAll /*defaultErrata*/); } auto minimumSize = layoutConstraints.minimumSize; @@ -736,7 +722,6 @@ void YogaLayoutableShadowNode::layoutTree( auto layoutMetrics = layoutMetricsFromYogaNode(yogaNode_); layoutMetrics.pointScaleFactor = layoutContext.pointScaleFactor; layoutMetrics.fontSizeMultiplier = layoutContext.fontSizeMultiplier; - layoutMetrics.wasLeftAndRightSwapped = swapLeftAndRight; setLayoutMetrics(layoutMetrics); yogaNode_.setHasNewLayout(false); } @@ -784,11 +769,6 @@ void YogaLayoutableShadowNode::layout(LayoutContext layoutContext) { auto newLayoutMetrics = layoutMetricsFromYogaNode(*childYogaNode); newLayoutMetrics.pointScaleFactor = layoutContext.pointScaleFactor; newLayoutMetrics.fontSizeMultiplier = layoutContext.fontSizeMultiplier; - // Store the swap that `configureYogaTree` applied, which comes from the - // root, not this node's direction. Otherwise a `direction` override never - // matches the skip check there and is configured again on every pass. - newLayoutMetrics.wasLeftAndRightSwapped = - layoutMetrics_.wasLeftAndRightSwapped; // Child node's layout has changed. When a node is added to // `affectedNodes`, onLayout event is called on the component. Comparing @@ -985,114 +965,6 @@ yoga::Config& YogaLayoutableShadowNode::initializeYogaConfig( return config; } -#pragma mark - RTL left and right swapping - -void YogaLayoutableShadowNode::swapStyleLeftAndRight() { - ensureUnsealed(); - - swapLeftAndRightInYogaStyleProps(); - swapLeftAndRightInViewProps(); -} - -void YogaLayoutableShadowNode::swapLeftAndRightInYogaStyleProps() { - auto yogaStyle = yogaNode_.style(); - - // Swap Yoga node values, position, padding and margin. - - if (yogaStyle.position(yoga::Edge::Left).isDefined()) { - yogaStyle.setPosition( - yoga::Edge::Start, yogaStyle.position(yoga::Edge::Left)); - yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::undefined()); - } - - if (yogaStyle.position(yoga::Edge::Right).isDefined()) { - yogaStyle.setPosition( - yoga::Edge::End, yogaStyle.position(yoga::Edge::Right)); - yogaStyle.setPosition(yoga::Edge::Right, yoga::StyleLength::undefined()); - } - - if (yogaStyle.padding(yoga::Edge::Left).isDefined()) { - yogaStyle.setPadding( - yoga::Edge::Start, yogaStyle.padding(yoga::Edge::Left)); - yogaStyle.setPadding(yoga::Edge::Left, yoga::StyleLength::undefined()); - } - - if (yogaStyle.padding(yoga::Edge::Right).isDefined()) { - yogaStyle.setPadding(yoga::Edge::End, yogaStyle.padding(yoga::Edge::Right)); - yogaStyle.setPadding(yoga::Edge::Right, yoga::StyleLength::undefined()); - } - - if (yogaStyle.margin(yoga::Edge::Left).isDefined()) { - yogaStyle.setMargin(yoga::Edge::Start, yogaStyle.margin(yoga::Edge::Left)); - yogaStyle.setMargin(yoga::Edge::Left, yoga::StyleLength::undefined()); - } - - if (yogaStyle.margin(yoga::Edge::Right).isDefined()) { - yogaStyle.setMargin(yoga::Edge::End, yogaStyle.margin(yoga::Edge::Right)); - yogaStyle.setMargin(yoga::Edge::Right, yoga::StyleLength::undefined()); - } - - if (yogaStyle.border(yoga::Edge::Left).isDefined()) { - yogaStyle.setBorder(yoga::Edge::Start, yogaStyle.border(yoga::Edge::Left)); - yogaStyle.setBorder(yoga::Edge::Left, yoga::StyleLength::undefined()); - } - - if (yogaStyle.border(yoga::Edge::Right).isDefined()) { - yogaStyle.setBorder(yoga::Edge::End, yogaStyle.border(yoga::Edge::Right)); - yogaStyle.setBorder(yoga::Edge::Right, yoga::StyleLength::undefined()); - } - - yogaNode_.setStyle(yogaStyle); -} - -void YogaLayoutableShadowNode::swapLeftAndRightInViewProps() { - if (auto viewShadowNode = dynamic_cast(this)) { - // TODO: Do not mutate props directly. - auto& props = const_cast(viewShadowNode->getConcreteProps()); - - // Swap border node values, borderRadii, borderColors and borderStyles. - if (props.borderRadii.topLeft.has_value()) { - props.borderRadii.topStart = props.borderRadii.topLeft; - props.borderRadii.topLeft.reset(); - } - - if (props.borderRadii.bottomLeft.has_value()) { - props.borderRadii.bottomStart = props.borderRadii.bottomLeft; - props.borderRadii.bottomLeft.reset(); - } - - if (props.borderRadii.topRight.has_value()) { - props.borderRadii.topEnd = props.borderRadii.topRight; - props.borderRadii.topRight.reset(); - } - - if (props.borderRadii.bottomRight.has_value()) { - props.borderRadii.bottomEnd = props.borderRadii.bottomRight; - props.borderRadii.bottomRight.reset(); - } - - if (props.borderColors.left.has_value()) { - props.borderColors.start = props.borderColors.left; - props.borderColors.left.reset(); - } - - if (props.borderColors.right.has_value()) { - props.borderColors.end = props.borderColors.right; - props.borderColors.right.reset(); - } - - if (props.borderStyles.left.has_value()) { - props.borderStyles.start = props.borderStyles.left; - props.borderStyles.left.reset(); - } - - if (props.borderStyles.right.has_value()) { - props.borderStyles.end = props.borderStyles.right; - props.borderStyles.right.reset(); - } - } -} - #pragma mark - Consistency Ensuring Helpers void YogaLayoutableShadowNode::ensureConsistency() const { diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h index 47edf4e9e4ad..fc658b7ae905 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h @@ -136,8 +136,7 @@ class YogaLayoutableShadowNode : public LayoutableShadowNode { * ShadowTree has been constructed, but before it has been is laid out or * committed. */ - void - configureYogaTree(float pointScaleFactor, Float fontSizeMultiplier, YGErrata defaultErrata, bool swapLeftAndRight); + void configureYogaTree(float pointScaleFactor, Float fontSizeMultiplier, YGErrata defaultErrata); /** * Return an errata based on a `layoutConformance` prop if given, otherwise @@ -162,37 +161,6 @@ class YogaLayoutableShadowNode : public LayoutableShadowNode { static float yogaNodeBaselineCallbackConnector(YGNodeConstRef yogaNode, float width, float height); static YogaLayoutableShadowNode &shadowNodeFromContext(YGNodeConstRef yogaNode); -#pragma mark - RTL Legacy Autoflip - - /* - * Reassigns the following values: - * - (left|right) → (start|end) - * - margin(Left|Right) → margin(Start|End) - * - padding(Left|Right) → padding(Start|End) - * - borderTop(Left|Right)Radius → borderTop(Start|End)Radius - * - borderBottom(Left|Right)Radius → borderBottom(Start|End)Radius - * - border(Left|Right)Width → border(Start|End)Width - * - border(Left|Right)Color → border(Start|End)Color - * This is neccesarry to be backwards compatible with old renderer, it swaps - * the values as well in https://fburl.com/diffusion/kl7bjr3h - */ - void swapStyleLeftAndRight(); - /* - * In shadow node passed as argument, reassigns following values - * - borderTop(Left|Right)Radius → borderTop(Start|End)Radius - * - borderBottom(Left|Right)Radius → borderBottom(Start|End)Radius - * - border(Left|Right)Width → border(Start|End)Width - * - border(Left|Right)Color → border(Start|End)Color - */ - void swapLeftAndRightInViewProps(); - /* - * In yoga node passed as argument, reassigns following values - * - (left|right) → (start|end) - * - margin(Left|Right) → margin(Start|End) - * - padding(Left|Right) → padding(Start|End) - */ - void swapLeftAndRightInYogaStyleProps(); - /* * Combine a base yoga::Style with aliased properties which should be * flattened into it. E.g. reconciling "marginInlineStart" and "marginStart". diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp index b5aa3bddb8d4..f7b818cb9ca1 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp @@ -972,117 +972,6 @@ TEST_F(FontScaleLayoutTest, fontScaleChangeSkipsHiddenSubtreeUntilShown) { EXPECT_EQ(leaf.getLayoutMetrics().fontSizeMultiplier, 1.5); EXPECT_EQ(leaf.getLayoutMetrics().frame.size.height, 15); } - -// A `direction: ltr` subtree under an RTL root that swaps left and right must -// be configured again only when the swap passed down changes. Configuring it -// again clones the input-like leaf in place, which dirties it, so Yoga would -// lay it out again on every commit. -TEST_F( - FontScaleLayoutTest, - rtlDirectionOverrideIsConfiguredOnlyWhenTheSwapChanges) { - auto rootShadowNode = std::shared_ptr{}; - auto siblingShadowNode = std::shared_ptr{}; - - // clang-format off - auto element = - Element() - .reference(rootShadowNode) - .tag(1) - .children({ - Element() - .tag(2) - .children({ - Element() - .tag(3) - .reference(siblingShadowNode) - .props([] { - auto sharedProps = std::make_shared(); - sharedProps->yogaStyle.setDimension( - yoga::Dimension::Width, yoga::StyleSizeLength::points(10)); - sharedProps->yogaStyle.setDimension( - yoga::Dimension::Height, yoga::StyleSizeLength::points(10)); - return sharedProps; - }), - Element() - .tag(4) - .props([] { - auto sharedProps = std::make_shared(); - sharedProps->yogaStyle.setDirection(yoga::Direction::LTR); - return sharedProps; - }) - .children({Element().tag(5)}) - }) - }); - // clang-format on - - builder_.build(element); - - auto layOutWithDirection = - [this]( - const RootShadowNode& root, - LayoutDirection layoutDirection, - std::vector* affectedNodes) { - auto layoutConstraints = root.getConcreteProps().layoutConstraints; - layoutConstraints.layoutDirection = layoutDirection; - layoutConstraints.minimumSize = {.width = 100, .height = 100}; - layoutConstraints.maximumSize = {.width = 100, .height = 100}; - auto layoutContext = root.getConcreteProps().layoutContext; - layoutContext.swapLeftAndRightInRTL = true; - auto newRoot = - root.clone(parserContext_, layoutConstraints, layoutContext); - EXPECT_TRUE(newRoot->layoutIfNeeded(affectedNodes)); - return newRoot; - }; - auto tagsOf = [](const std::vector& nodes) { - auto tags = std::vector{}; - for (const auto* node : nodes) { - tags.push_back(node->getTag()); - } - return tags; - }; - auto leafOf = [](const RootShadowNode& root) { - return root.getChildren().at(0)->getChildren().at(1)->getChildren().at(0); - }; - auto overrideSubtreeFrames = [&](const RootShadowNode& root) { - const auto& overrideNode = root.getChildren().at(0)->getChildren().at(1); - return std::pair{ - static_cast(*overrideNode) - .getLayoutMetrics() - .frame, - static_cast(*leafOf(root)) - .getLayoutMetrics() - .frame}; - }; - - auto ltrRootShadowNode = layOutWithDirection( - *rootShadowNode, LayoutDirection::LeftToRight, nullptr); - - // Turning the root RTL changes the swap passed down, so the subtree is - // configured again and the leaf is laid out again. - auto affectedNodes = std::vector{}; - auto rtlRootShadowNode = layOutWithDirection( - *ltrRootShadowNode, LayoutDirection::RightToLeft, &affectedNodes); - EXPECT_EQ(tagsOf(affectedNodes), (std::vector{2, 3, 4, 5})); - auto framesBeforeCommit = overrideSubtreeFrames(*rtlRootShadowNode); - - auto committedRootShadowNode = - std::static_pointer_cast(rtlRootShadowNode->cloneTree( - siblingShadowNode->getFamily(), [](const ShadowNode& oldShadowNode) { - auto viewProps = std::make_shared(); - viewProps->yogaStyle.setDimension( - yoga::Dimension::Width, yoga::StyleSizeLength::points(20)); - viewProps->yogaStyle.setDimension( - yoga::Dimension::Height, yoga::StyleSizeLength::points(10)); - return oldShadowNode.clone(ShadowNodeFragment{.props = viewProps}); - })); - affectedNodes.clear(); - EXPECT_TRUE(committedRootShadowNode->layoutIfNeeded(&affectedNodes)); - - EXPECT_EQ( - overrideSubtreeFrames(*committedRootShadowNode), framesBeforeCommit); - EXPECT_EQ(tagsOf(affectedNodes), (std::vector{2, 3, 4})); - EXPECT_EQ(leafOf(*committedRootShadowNode), leafOf(*rtlRootShadowNode)); -} #endif } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/core/LayoutContext.h b/packages/react-native/ReactCommon/react/renderer/core/LayoutContext.h index 6cf388e00d51..32197419d2e7 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/LayoutContext.h +++ b/packages/react-native/ReactCommon/react/renderer/core/LayoutContext.h @@ -37,20 +37,6 @@ struct LayoutContext { */ std::vector *affectedNodes{}; - /* - * Flag indicating whether in reassignment of direction - * aware properties should take place. If yes, following - * reassignment will occur in RTL context. - * - (left|right) → (start|end) - * - margin(Left|Right) → margin(Start|End) - * - padding(Left|Right) → padding(Start|End) - * - borderTop(Left|Right)Radius → borderTop(Start|End)Radius - * - borderBottom(Left|Right)Radius → borderBottom(Start|End)Radius - * - border(Left|Right)Width → border(Start|End)Width - * - border(Left|Right)Color → border(Start|End)Color - */ - bool swapLeftAndRightInRTL{false}; - /* * Multiplier used to change size of the font in surface. */ @@ -71,19 +57,8 @@ struct LayoutContext { inline bool operator==(const LayoutContext &lhs, const LayoutContext &rhs) { return std::tie( - lhs.pointScaleFactor, - lhs.affectedNodes, - lhs.swapLeftAndRightInRTL, - lhs.fontSizeMultiplier, - lhs.viewportOffset, - lhs.viewportSize) == - std::tie( - rhs.pointScaleFactor, - rhs.affectedNodes, - rhs.swapLeftAndRightInRTL, - rhs.fontSizeMultiplier, - rhs.viewportOffset, - rhs.viewportSize); + lhs.pointScaleFactor, lhs.affectedNodes, lhs.fontSizeMultiplier, lhs.viewportOffset, lhs.viewportSize) == + std::tie(rhs.pointScaleFactor, rhs.affectedNodes, rhs.fontSizeMultiplier, rhs.viewportOffset, rhs.viewportSize); } } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/core/LayoutMetrics.h b/packages/react-native/ReactCommon/react/renderer/core/LayoutMetrics.h index 1287da4feec8..bd6f893e2280 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/LayoutMetrics.h +++ b/packages/react-native/ReactCommon/react/renderer/core/LayoutMetrics.h @@ -34,10 +34,6 @@ struct LayoutMetrics { PositionType positionType{PositionType::Relative}; // See `LayoutDirection` for all possible options. LayoutDirection layoutDirection{LayoutDirection::Undefined}; - // Whether React Native treated cardinal directions as flow-relative - // directions due to being laid out in RTL with `doLeftAndRightSwapInRTL` - // enabled. - bool wasLeftAndRightSwapped{false}; // Pixel density. Number of device pixels per density-independent pixel. Float pointScaleFactor{1.0}; // Surface font scale this node was last laid out with. diff --git a/packages/react-native/ReactNativeApi.d.ts b/packages/react-native/ReactNativeApi.d.ts index 11a5302585ba..babddf1360d7 100644 --- a/packages/react-native/ReactNativeApi.d.ts +++ b/packages/react-native/ReactNativeApi.d.ts @@ -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<<59570f49ad456d1306656541407d4293>> + * @generated SignedSource<<64046854044674598553afea3372472a>> * * This file was generated by scripts/js-api/build-types/index.js. */ @@ -232,12 +232,12 @@ declare const flatten: typeof $$flattenStyle declare const forkEvent: typeof $$AnimatedImplementation.forkEvent declare const hairlineWidth: number declare const I18nManager: { - doLeftAndRightSwapInRTL: I18nManagerConstants["doLeftAndRightSwapInRTL"] - isRTL: I18nManagerConstants["isRTL"] allowRTL: (shouldAllow: boolean) => void forceRTL: (shouldForce: boolean) => void getConstants: () => I18nManagerConstants swapLeftAndRightInRTL: (flipStyles: boolean) => void + get doLeftAndRightSwapInRTL(): I18nManagerConstants["doLeftAndRightSwapInRTL"] + get isRTL(): I18nManagerConstants["isRTL"] } declare const Image: ImageType declare const InputAccessoryView: typeof InputAccessoryView_default @@ -2377,7 +2377,7 @@ declare type I18nManager = typeof I18nManager declare type I18nManagerConstants = { doLeftAndRightSwapInRTL: boolean isRTL: boolean - localeIdentifier?: string + localeIdentifier: string } declare interface IEventEmitter< TEventToArgsMap extends Readonly< @@ -5849,7 +5849,7 @@ export { GestureResponderHandlers, // c67c25e0 HostComponent, // 22c9ea3d HostInstance, // 17bb0a55 - I18nManager, // f9870e00 + I18nManager, // 2432113d IEventEmitter, // fbef6131 IOSKeyboardEvent, // e67bfe3a IgnorePattern, // ec6f6ece diff --git a/packages/react-native/src/private/components/safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE.js b/packages/react-native/src/private/components/safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE.js index 0ea40f01bbf6..5b29b8ed207f 100644 --- a/packages/react-native/src/private/components/safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE.js +++ b/packages/react-native/src/private/components/safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE.js @@ -16,7 +16,6 @@ import type { import type {HostInstance} from '../../types/HostInstance'; import View from '../../../../Libraries/Components/View/View'; -import I18nManager from '../../../../Libraries/ReactNative/I18nManager'; import * as React from 'react'; import {useCallback, useMemo, useState} from 'react'; @@ -43,17 +42,11 @@ component SafeAreaView( if (insets == null) { return null; } - // Insets are physical edges, but Yoga remaps paddingLeft/paddingRight to - // start/end when I18nManager's swapLeftAndRightInRTL is on, which would - // pad the mirror-image edge in RTL. Swap the values so the physical edge - // keeps its inset. - const {isRTL, doLeftAndRightSwapInRTL} = I18nManager.getConstants(); - const swap = isRTL && doLeftAndRightSwapInRTL; return { paddingTop: insets.top, - paddingRight: swap ? insets.left : insets.right, + paddingRight: insets.right, paddingBottom: insets.bottom, - paddingLeft: swap ? insets.right : insets.left, + paddingLeft: insets.left, }; }, [insets]); diff --git a/packages/react-native/src/private/devsupport/devmenu/elementinspector/resolveBoxStyle.js b/packages/react-native/src/private/devsupport/devmenu/elementinspector/resolveBoxStyle.js index 4f62e92fbaa9..d29ac98e09b5 100644 --- a/packages/react-native/src/private/devsupport/devmenu/elementinspector/resolveBoxStyle.js +++ b/packages/react-native/src/private/devsupport/devmenu/elementinspector/resolveBoxStyle.js @@ -92,8 +92,7 @@ function resolveBoxStyle( const styleForEnd = getStyleValue(prefix + 'End'); if (styleForEnd != null) { - const constants = I18nManager.getConstants(); - if (constants.isRTL && constants.doLeftAndRightSwapInRTL) { + if (I18nManager.isRTL) { result.left = styleForEnd; } else { result.right = styleForEnd; @@ -102,8 +101,7 @@ function resolveBoxStyle( } const styleForStart = getStyleValue(prefix + 'Start'); if (styleForStart != null) { - const constants = I18nManager.getConstants(); - if (constants.isRTL && constants.doLeftAndRightSwapInRTL) { + if (I18nManager.isRTL) { result.right = styleForStart; } else { result.left = styleForStart; diff --git a/packages/react-native/src/private/specs_DEPRECATED/modules/NativeI18nManager.js b/packages/react-native/src/private/specs_DEPRECATED/modules/NativeI18nManager.js index 467cedb3d4b2..a26297fb0fde 100644 --- a/packages/react-native/src/private/specs_DEPRECATED/modules/NativeI18nManager.js +++ b/packages/react-native/src/private/specs_DEPRECATED/modules/NativeI18nManager.js @@ -13,16 +13,13 @@ import type {TurboModule} from '../../../../Libraries/TurboModule/RCTExport'; import * as TurboModuleRegistry from '../../../../Libraries/TurboModule/TurboModuleRegistry'; export type I18nManagerConstants = { - doLeftAndRightSwapInRTL: boolean, isRTL: boolean, - localeIdentifier?: ?string, + localeIdentifier: string, }; export interface Spec extends TurboModule { readonly getConstants: () => I18nManagerConstants; - allowRTL: (allowRTL: boolean) => void; - forceRTL: (forceRTL: boolean) => void; - swapLeftAndRightInRTL: (flipStyles: boolean) => void; + forceRTL: (forceRTL: boolean) => boolean; } export default TurboModuleRegistry.get('I18nManager') as ?Spec; diff --git a/packages/react-native/types_DEPRECATED/Libraries/ReactNative/I18nManager.d.ts b/packages/react-native/types_DEPRECATED/Libraries/ReactNative/I18nManager.d.ts index 39679aa6cdd7..15e40eec0690 100644 --- a/packages/react-native/types_DEPRECATED/Libraries/ReactNative/I18nManager.d.ts +++ b/packages/react-native/types_DEPRECATED/Libraries/ReactNative/I18nManager.d.ts @@ -9,14 +9,31 @@ export interface I18nManagerStatic { getConstants: () => { - isRTL: boolean; + /** + * @deprecated Has no effect, and is always `false`. Use `start` and `end` + * style properties, such as `marginStart`, instead. + */ doLeftAndRightSwapInRTL: boolean; - localeIdentifier?: string | null | undefined; + isRTL: boolean; + localeIdentifier: string; }; + /** + * @deprecated Has no effect. Set `RCTSupportsRTL` to `true` in Info.plist on + * iOS, or `android:supportsRtl="true"` in AndroidManifest.xml on Android, + * instead. + */ allowRTL: (allowRTL: boolean) => void; forceRTL: (forceRTL: boolean) => void; + /** + * @deprecated Has no effect. Use `start` and `end` style properties, such as + * `marginStart`, instead. + */ swapLeftAndRightInRTL: (swapLeftAndRight: boolean) => void; isRTL: boolean; + /** + * @deprecated Has no effect, and is always `false`. Use `start` and `end` + * style properties, such as `marginStart`, instead. + */ doLeftAndRightSwapInRTL: boolean; } diff --git a/packages/rn-tester/RNTester/Info.plist b/packages/rn-tester/RNTester/Info.plist index ce09c212a744..387b1a01cf62 100644 --- a/packages/rn-tester/RNTester/Info.plist +++ b/packages/rn-tester/RNTester/Info.plist @@ -48,6 +48,8 @@ You need to add NSPhotoLibraryUsageDescription key in Info.plist to enable photo library usage, otherwise it is going to *fail silently*! RCTNewArchEnabled + RCTSupportsRTL + UIApplicationSceneManifest UIApplicationSupportsMultipleScenes diff --git a/packages/rn-tester/js/examples/RTL/RTLExample.js b/packages/rn-tester/js/examples/RTL/RTLExample.js index c418820d0ae7..abaf6b5aedd1 100644 --- a/packages/rn-tester/js/examples/RTL/RTLExample.js +++ b/packages/rn-tester/js/examples/RTL/RTLExample.js @@ -15,7 +15,6 @@ import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; import RNTexterText from '../../components/RNTesterText'; import * as React from 'react'; import { - Alert, Animated, Button, I18nManager, @@ -43,8 +42,6 @@ const SCALE = PixelRatio.get(); const IMAGE_DIMENSION = 100 * SCALE; const IMAGE_SIZE = [IMAGE_DIMENSION, IMAGE_DIMENSION]; -const IS_RTL = I18nManager.isRTL; - function ListItem(props: {imageSource: number}) { return ( @@ -121,10 +118,10 @@ const IconsExample = withRTLState(({isRTL, setRTL}) => { Without directional meaning - + With directional meaning @@ -171,7 +168,7 @@ function withRTLState( constructor(...args) { super(...args); this.state = { - isRTL: IS_RTL, + isRTL: I18nManager.isRTL, }; } @@ -211,7 +208,7 @@ class RTLToggleExample extends React.Component { super(props); this.state = { - isRTL: IS_RTL, + isRTL: I18nManager.isRTL, }; } @@ -228,7 +225,7 @@ class RTLToggleExample extends React.Component { @@ -240,12 +237,6 @@ class RTLToggleExample extends React.Component { _onDirectionChange = () => { I18nManager.forceRTL(!this.state.isRTL); this.setState({isRTL: !this.state.isRTL}); - Alert.alert( - 'Reload this page', - 'Please reload this page to change the UI direction! ' + - 'All examples in this app will be affected. ' + - 'Check them out to see what they look like in RTL layout.', - ); }; } @@ -346,8 +337,8 @@ const PaddingExample = withRTLState(({isRTL, setRTL}) => { backgroundColor: 'white', paddingTop: 5, paddingBottom: 5, - borderLeftWidth: 1, - borderRightWidth: 1, + borderStartWidth: 1, + borderEndWidth: 1, borderColor: 'gray', }}> @@ -380,8 +371,8 @@ const MarginExample = withRTLState(({isRTL, setRTL}) => { paddingBottom: 5, marginStart: 50, marginEnd: 10, - borderLeftWidth: 1, - borderRightWidth: 1, + borderStartWidth: 1, + borderEndWidth: 1, borderColor: 'gray', }}> @@ -481,8 +472,8 @@ const BorderColorExample = withRTLState(({isRTL, setRTL}) => { style={{ borderStartColor: 'red', borderEndColor: 'green', - borderLeftWidth: 20, - borderRightWidth: 20, + borderStartWidth: 20, + borderEndWidth: 20, padding: 10, }}> @@ -624,16 +615,16 @@ const styles = StyleSheet.create({ switchRowSwitchView: { flex: 3, }, - rightAlignStyle: { - right: 10, + endAlignStyle: { + end: 10, position: 'absolute', }, list: { height: 120, marginBottom: 5, borderTopWidth: 0.5, - borderLeftWidth: 0.5, - borderRightWidth: 0.5, + borderStartWidth: 0.5, + borderEndWidth: 0.5, borderColor: '#e5e5e5', }, row: { @@ -659,11 +650,11 @@ const styles = StyleSheet.create({ borderWidth: 0.5, borderColor: '#e5e5e5', }, - withRTLStyle: { - transform: [{scaleX: IS_RTL ? -1 : 1}], + flipped: { + transform: [{scaleX: -1}], }, image: { - left: 30, + start: 30, width: 48, height: 48, }, @@ -693,11 +684,11 @@ const styles = StyleSheet.create({ fontSizeExtraSmall: { fontSize: 8, }, - textAlignLeft: { - textAlign: 'left', + textAlignStart: { + textAlign: 'start', }, - textAlignRight: { - textAlign: 'right', + textAlignEnd: { + textAlign: 'end', }, textBox: { width: 28, @@ -741,34 +732,34 @@ exports.examples = [ }, }, { - title: "Using textAlign: 'left'", + title: "Using textAlign: 'start'", description: ('In iOS/Android, text alignment flips regardless of ' + 'languages or text content.') as string, render: function (): React.MixedElement { return ( ); }, }, { - title: "Using textAlign: 'right'", + title: "Using textAlign: 'end'", description: ('In iOS/Android, text alignment flips regardless of ' + 'languages or text content.') as string, render: function (): React.MixedElement { return ( ); }, }, { - title: "Using textAlign: 'right' for TextInput", + title: "Using textAlign: 'end' for TextInput", description: 'Flip TextInput direction to RTL' as string, render: function (): React.MixedElement { - return ; + return ; }, }, { diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api index 713d93c11407..7892b54fb495 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api @@ -2385,7 +2385,7 @@ class facebook::react::SurfaceHandlerBinding : public jni::HybridClass -struct facebook::react::NativeI18nManagerI18nManagerConstants { - public P0 doLeftAndRightSwapInRTL; - public P1 isRTL; - public P2 localeIdentifier; - public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; -} - template struct facebook::react::NativeMutationObserverNativeMutationObserverObserveOptions { public P0 mutationObserverId; @@ -4097,6 +4087,13 @@ struct facebook::react::NativeBlobModuleConstants { public bool operator==(const facebook::react::NativeBlobModuleConstants& other) const; } +template +struct facebook::react::NativeI18nManagerI18nManagerConstants { + public P0 isRTL; + public P1 localeIdentifier; + public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; +} + template struct facebook::react::NativeIdleCallbacksIdleDeadline { public P0 didTimeout; @@ -4748,10 +4745,9 @@ template struct facebook::react::NativeI18nManagerI18nManagerConstantsBridging { public static T fromJs(facebook::jsi::Runtime& rt, const facebook::jsi::Object& value, const std::shared_ptr& jsInvoker); public static T types; - public static bool doLeftAndRightSwapInRTLToJs(facebook::jsi::Runtime& rt, decltype(types.doLeftAndRightSwapInRTL) value); public static bool isRTLToJs(facebook::jsi::Runtime& rt, decltype(types.isRTL) value); public static facebook::jsi::Object toJs(facebook::jsi::Runtime& rt, const T& value, const std::shared_ptr& jsInvoker); - public static std::optional localeIdentifierToJs(facebook::jsi::Runtime& rt, decltype(types.localeIdentifier) value); + public static facebook::jsi::String localeIdentifierToJs(facebook::jsi::Runtime& rt, decltype(types.localeIdentifier) value); } template diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api index 3d66f8cfcea7..521e4d7cd844 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api @@ -3857,7 +3857,7 @@ class facebook::react::SurfaceHandlerBinding : public jni::HybridClass -struct facebook::react::NativeI18nManagerI18nManagerConstants { - public P0 doLeftAndRightSwapInRTL; - public P1 isRTL; - public P2 localeIdentifier; - public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; -} - template struct facebook::react::NativeMutationObserverNativeMutationObserverObserveOptions { public P0 mutationObserverId; @@ -7220,6 +7210,13 @@ struct facebook::react::NativeBlobModuleConstants { public bool operator==(const facebook::react::NativeBlobModuleConstants& other) const; } +template +struct facebook::react::NativeI18nManagerI18nManagerConstants { + public P0 isRTL; + public P1 localeIdentifier; + public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; +} + template struct facebook::react::NativeIdleCallbacksIdleDeadline { public P0 didTimeout; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api index 2bec0e454b9d..da1234de1784 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api @@ -2378,7 +2378,7 @@ class facebook::react::SurfaceHandlerBinding : public jni::HybridClass -struct facebook::react::NativeI18nManagerI18nManagerConstants { - public P0 doLeftAndRightSwapInRTL; - public P1 isRTL; - public P2 localeIdentifier; - public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; -} - template struct facebook::react::NativeMutationObserverNativeMutationObserverObserveOptions { public P0 mutationObserverId; @@ -4090,6 +4080,13 @@ struct facebook::react::NativeBlobModuleConstants { public bool operator==(const facebook::react::NativeBlobModuleConstants& other) const; } +template +struct facebook::react::NativeI18nManagerI18nManagerConstants { + public P0 isRTL; + public P1 localeIdentifier; + public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; +} + template struct facebook::react::NativeIdleCallbacksIdleDeadline { public P0 didTimeout; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api index 2bec0e454b9d..da1234de1784 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api @@ -2378,7 +2378,7 @@ class facebook::react::SurfaceHandlerBinding : public jni::HybridClass -struct facebook::react::NativeI18nManagerI18nManagerConstants { - public P0 doLeftAndRightSwapInRTL; - public P1 isRTL; - public P2 localeIdentifier; - public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; -} - template struct facebook::react::NativeMutationObserverNativeMutationObserverObserveOptions { public P0 mutationObserverId; @@ -4090,6 +4080,13 @@ struct facebook::react::NativeBlobModuleConstants { public bool operator==(const facebook::react::NativeBlobModuleConstants& other) const; } +template +struct facebook::react::NativeI18nManagerI18nManagerConstants { + public P0 isRTL; + public P1 localeIdentifier; + public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; +} + template struct facebook::react::NativeIdleCallbacksIdleDeadline { public P0 didTimeout; diff --git a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api index 11a5a26746a3..68865001e926 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api @@ -215,6 +215,7 @@ category RCTSurfacePresenter(Surface) { public virtual void setupAnimationDriverWithSurfaceHandler:(const facebook::react::SurfaceHandler& surfaceHandler); public virtual void synchronouslyUpdateViewOnUIThread:props:(NSNumber* reactTag, NSDictionary* props); public virtual void unregisterSurface:(RCTFabricSurface* surface); + public virtual void updateLayoutDirectionOfSurfaces(); } category UIImage(React) { @@ -1105,14 +1106,10 @@ interface RCTI18nManager : public NSObject { } interface RCTI18nUtil : public NSObject { - public virtual BOOL doLeftAndRightSwapInRTL(); public virtual BOOL isRTL(); - public virtual BOOL isRTLAllowed(); public virtual BOOL isRTLForced(); public virtual static instancetype sharedInstance(); - public virtual void allowRTL:(BOOL value); public virtual void forceRTL:(BOOL value); - public virtual void swapLeftAndRightInRTL:(BOOL value); } interface RCTImageCache : public NSObject { @@ -2267,11 +2264,9 @@ protocol NativeHeadlessJsTaskSupportSpec : public NSObjectRCTBridgeModule, publi } protocol NativeI18nManagerSpec : public NSObjectRCTBridgeModule, public RCTTurboModule { + public virtual NSNumber* forceRTL:(BOOL forceRTL); public virtual facebook::react::ModuleConstants constantsToExport(); public virtual facebook::react::ModuleConstants getConstants(); - public virtual void allowRTL:(BOOL allowRTL); - public virtual void forceRTL:(BOOL forceRTL); - public virtual void swapLeftAndRightInRTL:(BOOL flipStyles); } protocol NativeImageEditorSpec : public NSObjectRCTBridgeModule, public RCTTurboModule { @@ -2834,6 +2829,7 @@ protocol RCTSurfacePresenterStub : public NSObject { public virtual void addObserver:(id observer); public virtual void removeObserver:(id observer); public virtual void synchronouslyUpdateViewOnUIThread:props:(NSNumber* reactTag, NSDictionary* props); + public virtual void updateLayoutDirectionOfSurfaces(); } protocol RCTSurfaceProtocol : public NSObject { @@ -5339,7 +5335,6 @@ struct facebook::react::LayoutConstraints { } struct facebook::react::LayoutContext { - public bool swapLeftAndRightInRTL; public facebook::react::Float fontSizeMultiplier; public facebook::react::Float pointScaleFactor; public facebook::react::Point viewportOffset; @@ -5349,7 +5344,6 @@ struct facebook::react::LayoutContext { struct facebook::react::LayoutMetrics { public bool operator==(const facebook::react::LayoutMetrics& rhs) const = default; - public bool wasLeftAndRightSwapped; public facebook::react::DisplayType displayType; public facebook::react::EdgeInsets borderWidth; public facebook::react::EdgeInsets contentInsets; @@ -5912,14 +5906,6 @@ struct facebook::react::NativeDeviceInfoDeviceInfoConstants { public bool operator==(const facebook::react::NativeDeviceInfoDeviceInfoConstants& other) const; } -template -struct facebook::react::NativeI18nManagerI18nManagerConstants { - public P0 doLeftAndRightSwapInRTL; - public P1 isRTL; - public P2 localeIdentifier; - public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; -} - template struct facebook::react::NativeMutationObserverNativeMutationObserverObserveOptions { public P0 mutationObserverId; @@ -5965,6 +5951,13 @@ struct facebook::react::NativeBlobModuleConstants { public bool operator==(const facebook::react::NativeBlobModuleConstants& other) const; } +template +struct facebook::react::NativeI18nManagerI18nManagerConstants { + public P0 isRTL; + public P1 localeIdentifier; + public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; +} + template struct facebook::react::NativeIdleCallbacksIdleDeadline { public P0 didTimeout; @@ -6547,10 +6540,9 @@ template struct facebook::react::NativeI18nManagerI18nManagerConstantsBridging { public static T fromJs(facebook::jsi::Runtime& rt, const facebook::jsi::Object& value, const std::shared_ptr& jsInvoker); public static T types; - public static bool doLeftAndRightSwapInRTLToJs(facebook::jsi::Runtime& rt, decltype(types.doLeftAndRightSwapInRTL) value); public static bool isRTLToJs(facebook::jsi::Runtime& rt, decltype(types.isRTL) value); public static facebook::jsi::Object toJs(facebook::jsi::Runtime& rt, const T& value, const std::shared_ptr& jsInvoker); - public static std::optional localeIdentifierToJs(facebook::jsi::Runtime& rt, decltype(types.localeIdentifier) value); + public static facebook::jsi::String localeIdentifierToJs(facebook::jsi::Runtime& rt, decltype(types.localeIdentifier) value); } template @@ -9196,8 +9188,7 @@ struct JS::NativeI18nManager::Constants::Builder { } struct JS::NativeI18nManager::Constants::Builder::Input { - protected NSString* localeIdentifier; - protected RCTRequired doLeftAndRightSwapInRTL; + protected RCTRequired localeIdentifier; protected RCTRequired isRTL; } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api index 77b89e35c66c..bcc772fb107c 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api @@ -215,6 +215,7 @@ category RCTSurfacePresenter(Surface) { public virtual void setupAnimationDriverWithSurfaceHandler:(const facebook::react::SurfaceHandler& surfaceHandler); public virtual void synchronouslyUpdateViewOnUIThread:props:(NSNumber* reactTag, NSDictionary* props); public virtual void unregisterSurface:(RCTFabricSurface* surface); + public virtual void updateLayoutDirectionOfSurfaces(); } category UIImage(React) { @@ -1128,14 +1129,10 @@ interface RCTI18nManager : public NSObject { } interface RCTI18nUtil : public NSObject { - public virtual BOOL doLeftAndRightSwapInRTL(); public virtual BOOL isRTL(); - public virtual BOOL isRTLAllowed(); public virtual BOOL isRTLForced(); public virtual static instancetype sharedInstance(); - public virtual void allowRTL:(BOOL value); public virtual void forceRTL:(BOOL value); - public virtual void swapLeftAndRightInRTL:(BOOL value); } interface RCTImageCache : public NSObject { @@ -2325,11 +2322,9 @@ protocol NativeHeadlessJsTaskSupportSpec : public NSObjectRCTBridgeModule, publi } protocol NativeI18nManagerSpec : public NSObjectRCTBridgeModule, public RCTTurboModule { + public virtual NSNumber* forceRTL:(BOOL forceRTL); public virtual facebook::react::ModuleConstants constantsToExport(); public virtual facebook::react::ModuleConstants getConstants(); - public virtual void allowRTL:(BOOL allowRTL); - public virtual void forceRTL:(BOOL forceRTL); - public virtual void swapLeftAndRightInRTL:(BOOL flipStyles); } protocol NativeImageEditorSpec : public NSObjectRCTBridgeModule, public RCTTurboModule { @@ -2915,6 +2910,7 @@ protocol RCTSurfacePresenterStub : public NSObject { public virtual void addObserver:(id observer); public virtual void removeObserver:(id observer); public virtual void synchronouslyUpdateViewOnUIThread:props:(NSNumber* reactTag, NSDictionary* props); + public virtual void updateLayoutDirectionOfSurfaces(); } protocol RCTSurfaceProtocol : public NSObject { @@ -8244,7 +8240,6 @@ struct facebook::react::LayoutConstraints { } struct facebook::react::LayoutContext { - public bool swapLeftAndRightInRTL; public facebook::react::Float fontSizeMultiplier; public facebook::react::Float pointScaleFactor; public facebook::react::Point viewportOffset; @@ -8254,7 +8249,6 @@ struct facebook::react::LayoutContext { struct facebook::react::LayoutMetrics { public bool operator==(const facebook::react::LayoutMetrics& rhs) const = default; - public bool wasLeftAndRightSwapped; public facebook::react::DisplayType displayType; public facebook::react::EdgeInsets borderWidth; public facebook::react::EdgeInsets contentInsets; @@ -9050,14 +9044,6 @@ struct facebook::react::NativeDeviceInfoDeviceInfoConstants { public bool operator==(const facebook::react::NativeDeviceInfoDeviceInfoConstants& other) const; } -template -struct facebook::react::NativeI18nManagerI18nManagerConstants { - public P0 doLeftAndRightSwapInRTL; - public P1 isRTL; - public P2 localeIdentifier; - public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; -} - template struct facebook::react::NativeMutationObserverNativeMutationObserverObserveOptions { public P0 mutationObserverId; @@ -9103,6 +9089,13 @@ struct facebook::react::NativeBlobModuleConstants { public bool operator==(const facebook::react::NativeBlobModuleConstants& other) const; } +template +struct facebook::react::NativeI18nManagerI18nManagerConstants { + public P0 isRTL; + public P1 localeIdentifier; + public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; +} + template struct facebook::react::NativeIdleCallbacksIdleDeadline { public P0 didTimeout; @@ -13681,8 +13674,7 @@ struct JS::NativeI18nManager::Constants::Builder { } struct JS::NativeI18nManager::Constants::Builder::Input { - protected NSString* localeIdentifier; - protected RCTRequired doLeftAndRightSwapInRTL; + protected RCTRequired localeIdentifier; protected RCTRequired isRTL; } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api index 7afd10b7a53d..7f247cda8c68 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api @@ -215,6 +215,7 @@ category RCTSurfacePresenter(Surface) { public virtual void setupAnimationDriverWithSurfaceHandler:(const facebook::react::SurfaceHandler& surfaceHandler); public virtual void synchronouslyUpdateViewOnUIThread:props:(NSNumber* reactTag, NSDictionary* props); public virtual void unregisterSurface:(RCTFabricSurface* surface); + public virtual void updateLayoutDirectionOfSurfaces(); } category UIImage(React) { @@ -1105,14 +1106,10 @@ interface RCTI18nManager : public NSObject { } interface RCTI18nUtil : public NSObject { - public virtual BOOL doLeftAndRightSwapInRTL(); public virtual BOOL isRTL(); - public virtual BOOL isRTLAllowed(); public virtual BOOL isRTLForced(); public virtual static instancetype sharedInstance(); - public virtual void allowRTL:(BOOL value); public virtual void forceRTL:(BOOL value); - public virtual void swapLeftAndRightInRTL:(BOOL value); } interface RCTImageCache : public NSObject { @@ -2260,11 +2257,9 @@ protocol NativeHeadlessJsTaskSupportSpec : public NSObjectRCTBridgeModule, publi } protocol NativeI18nManagerSpec : public NSObjectRCTBridgeModule, public RCTTurboModule { + public virtual NSNumber* forceRTL:(BOOL forceRTL); public virtual facebook::react::ModuleConstants constantsToExport(); public virtual facebook::react::ModuleConstants getConstants(); - public virtual void allowRTL:(BOOL allowRTL); - public virtual void forceRTL:(BOOL forceRTL); - public virtual void swapLeftAndRightInRTL:(BOOL flipStyles); } protocol NativeImageEditorSpec : public NSObjectRCTBridgeModule, public RCTTurboModule { @@ -2827,6 +2822,7 @@ protocol RCTSurfacePresenterStub : public NSObject { public virtual void addObserver:(id observer); public virtual void removeObserver:(id observer); public virtual void synchronouslyUpdateViewOnUIThread:props:(NSNumber* reactTag, NSDictionary* props); + public virtual void updateLayoutDirectionOfSurfaces(); } protocol RCTSurfaceProtocol : public NSObject { @@ -5325,7 +5321,6 @@ struct facebook::react::LayoutConstraints { } struct facebook::react::LayoutContext { - public bool swapLeftAndRightInRTL; public facebook::react::Float fontSizeMultiplier; public facebook::react::Float pointScaleFactor; public facebook::react::Point viewportOffset; @@ -5335,7 +5330,6 @@ struct facebook::react::LayoutContext { struct facebook::react::LayoutMetrics { public bool operator==(const facebook::react::LayoutMetrics& rhs) const = default; - public bool wasLeftAndRightSwapped; public facebook::react::DisplayType displayType; public facebook::react::EdgeInsets borderWidth; public facebook::react::EdgeInsets contentInsets; @@ -5898,14 +5892,6 @@ struct facebook::react::NativeDeviceInfoDeviceInfoConstants { public bool operator==(const facebook::react::NativeDeviceInfoDeviceInfoConstants& other) const; } -template -struct facebook::react::NativeI18nManagerI18nManagerConstants { - public P0 doLeftAndRightSwapInRTL; - public P1 isRTL; - public P2 localeIdentifier; - public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; -} - template struct facebook::react::NativeMutationObserverNativeMutationObserverObserveOptions { public P0 mutationObserverId; @@ -5951,6 +5937,13 @@ struct facebook::react::NativeBlobModuleConstants { public bool operator==(const facebook::react::NativeBlobModuleConstants& other) const; } +template +struct facebook::react::NativeI18nManagerI18nManagerConstants { + public P0 isRTL; + public P1 localeIdentifier; + public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; +} + template struct facebook::react::NativeIdleCallbacksIdleDeadline { public P0 didTimeout; @@ -9048,8 +9041,7 @@ struct JS::NativeI18nManager::Constants::Builder { } struct JS::NativeI18nManager::Constants::Builder::Input { - protected NSString* localeIdentifier; - protected RCTRequired doLeftAndRightSwapInRTL; + protected RCTRequired localeIdentifier; protected RCTRequired isRTL; } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api index 69ae34b4ecf9..8ffce3f9df16 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api @@ -215,6 +215,7 @@ category RCTSurfacePresenter(Surface) { public virtual void setupAnimationDriverWithSurfaceHandler:(const facebook::react::SurfaceHandler& surfaceHandler); public virtual void synchronouslyUpdateViewOnUIThread:props:(NSNumber* reactTag, NSDictionary* props); public virtual void unregisterSurface:(RCTFabricSurface* surface); + public virtual void updateLayoutDirectionOfSurfaces(); } category UIImage(React) { @@ -1105,14 +1106,10 @@ interface RCTI18nManager : public NSObject { } interface RCTI18nUtil : public NSObject { - public virtual BOOL doLeftAndRightSwapInRTL(); public virtual BOOL isRTL(); - public virtual BOOL isRTLAllowed(); public virtual BOOL isRTLForced(); public virtual static instancetype sharedInstance(); - public virtual void allowRTL:(BOOL value); public virtual void forceRTL:(BOOL value); - public virtual void swapLeftAndRightInRTL:(BOOL value); } interface RCTImageCache : public NSObject { @@ -2267,11 +2264,9 @@ protocol NativeHeadlessJsTaskSupportSpec : public NSObjectRCTBridgeModule, publi } protocol NativeI18nManagerSpec : public NSObjectRCTBridgeModule, public RCTTurboModule { + public virtual NSNumber* forceRTL:(BOOL forceRTL); public virtual facebook::react::ModuleConstants constantsToExport(); public virtual facebook::react::ModuleConstants getConstants(); - public virtual void allowRTL:(BOOL allowRTL); - public virtual void forceRTL:(BOOL forceRTL); - public virtual void swapLeftAndRightInRTL:(BOOL flipStyles); } protocol NativeImageEditorSpec : public NSObjectRCTBridgeModule, public RCTTurboModule { @@ -2834,6 +2829,7 @@ protocol RCTSurfacePresenterStub : public NSObject { public virtual void addObserver:(id observer); public virtual void removeObserver:(id observer); public virtual void synchronouslyUpdateViewOnUIThread:props:(NSNumber* reactTag, NSDictionary* props); + public virtual void updateLayoutDirectionOfSurfaces(); } protocol RCTSurfaceProtocol : public NSObject { @@ -5332,7 +5328,6 @@ struct facebook::react::LayoutConstraints { } struct facebook::react::LayoutContext { - public bool swapLeftAndRightInRTL; public facebook::react::Float fontSizeMultiplier; public facebook::react::Float pointScaleFactor; public facebook::react::Point viewportOffset; @@ -5342,7 +5337,6 @@ struct facebook::react::LayoutContext { struct facebook::react::LayoutMetrics { public bool operator==(const facebook::react::LayoutMetrics& rhs) const = default; - public bool wasLeftAndRightSwapped; public facebook::react::DisplayType displayType; public facebook::react::EdgeInsets borderWidth; public facebook::react::EdgeInsets contentInsets; @@ -5905,14 +5899,6 @@ struct facebook::react::NativeDeviceInfoDeviceInfoConstants { public bool operator==(const facebook::react::NativeDeviceInfoDeviceInfoConstants& other) const; } -template -struct facebook::react::NativeI18nManagerI18nManagerConstants { - public P0 doLeftAndRightSwapInRTL; - public P1 isRTL; - public P2 localeIdentifier; - public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; -} - template struct facebook::react::NativeMutationObserverNativeMutationObserverObserveOptions { public P0 mutationObserverId; @@ -5958,6 +5944,13 @@ struct facebook::react::NativeBlobModuleConstants { public bool operator==(const facebook::react::NativeBlobModuleConstants& other) const; } +template +struct facebook::react::NativeI18nManagerI18nManagerConstants { + public P0 isRTL; + public P1 localeIdentifier; + public bool operator==(const facebook::react::NativeI18nManagerI18nManagerConstants& other) const; +} + template struct facebook::react::NativeIdleCallbacksIdleDeadline { public P0 didTimeout; @@ -9055,8 +9048,7 @@ struct JS::NativeI18nManager::Constants::Builder { } struct JS::NativeI18nManager::Constants::Builder::Input { - protected NSString* localeIdentifier; - protected RCTRequired doLeftAndRightSwapInRTL; + protected RCTRequired localeIdentifier; protected RCTRequired isRTL; } diff --git a/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api index e5147f2de315..ea2095f79fcc 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api @@ -1822,7 +1822,6 @@ struct facebook::react::LayoutConstraints { struct facebook::react::LayoutContext { public Float fontSizeMultiplier; public Float pointScaleFactor; - public bool swapLeftAndRightInRTL; public facebook::react::Point viewportOffset; public facebook::react::Size viewportSize; public std::vector* affectedNodes; @@ -1832,7 +1831,6 @@ struct facebook::react::LayoutMetrics { public Float fontSizeMultiplier; public Float pointScaleFactor; public bool operator==(const facebook::react::LayoutMetrics& rhs) const = default; - public bool wasLeftAndRightSwapped; public facebook::react::DisplayType displayType; public facebook::react::EdgeInsets borderWidth; public facebook::react::EdgeInsets contentInsets; diff --git a/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api index 412104d071ea..77075e5ae777 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api @@ -4461,7 +4461,6 @@ struct facebook::react::LayoutConstraints { struct facebook::react::LayoutContext { public Float fontSizeMultiplier; public Float pointScaleFactor; - public bool swapLeftAndRightInRTL; public facebook::react::Point viewportOffset; public facebook::react::Size viewportSize; public std::vector* affectedNodes; @@ -4471,7 +4470,6 @@ struct facebook::react::LayoutMetrics { public Float fontSizeMultiplier; public Float pointScaleFactor; public bool operator==(const facebook::react::LayoutMetrics& rhs) const = default; - public bool wasLeftAndRightSwapped; public facebook::react::DisplayType displayType; public facebook::react::EdgeInsets borderWidth; public facebook::react::EdgeInsets contentInsets; diff --git a/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api index 00a90ccf293d..473e5d75c892 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api @@ -1815,7 +1815,6 @@ struct facebook::react::LayoutConstraints { struct facebook::react::LayoutContext { public Float fontSizeMultiplier; public Float pointScaleFactor; - public bool swapLeftAndRightInRTL; public facebook::react::Point viewportOffset; public facebook::react::Size viewportSize; public std::vector* affectedNodes; @@ -1825,7 +1824,6 @@ struct facebook::react::LayoutMetrics { public Float fontSizeMultiplier; public Float pointScaleFactor; public bool operator==(const facebook::react::LayoutMetrics& rhs) const = default; - public bool wasLeftAndRightSwapped; public facebook::react::DisplayType displayType; public facebook::react::EdgeInsets borderWidth; public facebook::react::EdgeInsets contentInsets; diff --git a/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api index 00a90ccf293d..473e5d75c892 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api @@ -1815,7 +1815,6 @@ struct facebook::react::LayoutConstraints { struct facebook::react::LayoutContext { public Float fontSizeMultiplier; public Float pointScaleFactor; - public bool swapLeftAndRightInRTL; public facebook::react::Point viewportOffset; public facebook::react::Size viewportSize; public std::vector* affectedNodes; @@ -1825,7 +1824,6 @@ struct facebook::react::LayoutMetrics { public Float fontSizeMultiplier; public Float pointScaleFactor; public bool operator==(const facebook::react::LayoutMetrics& rhs) const = default; - public bool wasLeftAndRightSwapped; public facebook::react::DisplayType displayType; public facebook::react::EdgeInsets borderWidth; public facebook::react::EdgeInsets contentInsets;