react-native: RTL Layout Direction Not Updating after app reload with New React Native Architecture

Description

When using I18nManager to switch the layout direction between RTL (Right-to-Left) and LTR (Left-to-Right), the changes do not reflect after reload on the UI(doesn’t force styles), but apply for animations. This issue appears specifically with the new React Native architecture. The styles and layout directions are only applied correctly after the app is fully restarted.

Steps to reproduce

  1. Set up a React Native project with the new architecture enabled.
  2. Use I18nManager.forceRTL(true/false) to change the layout direction and use react-native-restart. to restart the app.
  3. Observe that the UI does not update immediately(styles not forced to be like text-align: right).

React Native Version

0.74.0

Affected Platforms

Runtime - iOS, Build - MacOS

Areas

Fabric - The New Renderer, TurboModule - The New Native Module System, JSI - Javascript Interface, Bridgeless - The New Initialization Flow, Codegen

Output of npx react-native info

System:
  OS: macOS 14.5
  CPU: (10) arm64 Apple M1 Max
  Memory: 272.36 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.10.0
    path: ~/.nvm/versions/node/v20.10.0/bin/node
  Yarn:
    version: 4.3.1
    path: ~/.nvm/versions/node/v20.10.0/bin/yarn
  npm:
    version: 10.2.3
    path: ~/.nvm/versions/node/v20.10.0/bin/npm
  Watchman:
    version: 2024.07.15.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12071903
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.0
    wanted: 0.74.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

info React Native v0.74.3 is now available (your project is running on v0.74.0).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.74.3
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.74.0
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".



### Stacktrace or Logs

```text
No crush or failure

Reproducer

Screenshots and Videos

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 11
  • Comments: 59 (11 by maintainers)

Commits related to this issue

Most upvoted comments

We spent a little time looking into this. One of the things that came up was what’s the real world use case for dynamically being able to change this when the application is running? Clearly it’s useful for testing, but how is this affecting users of your React Native application?

We’re just trying to colour the impact of this.

People use to change the language say from English to Arabic and need to see those interfaces actually switch from ltr to rtl. Basically you need to “restart” app for that to happen and we’ve been actively using react-native-restrat until now. However with new arch it’s no longer possible and this means people are going to have different app behvaiours and that’s not ideal at all. Especially that closing and opening the app will give yet another view to the user (the actual expected one: say for the bottom tabs for examples that will be shown from right-to-left in rtl languages) which means it can be a really confusing UX

@serhii-yalla great thanks for the info. Could you add a couple of videos of OldArch/NewArch? It would make it easier for me to find an owner for this one.

@cortinico Here it is.

https://github.com/user-attachments/assets/4068afb8-2edb-4342-94a2-91f588adfc19

https://github.com/user-attachments/assets/3ee9aa01-6d7f-4b94-ad63-11eda6da5d24

I guess we have to leave an undeclared variable after the language change to let tha app crash… and hope that user will open it again.

I would advice against it, that will make your crash metrics go down hill and might trigger an alert in your google play console.

I guess we have to leave an undeclared variable after the language change to let tha app crash… and hope that user will open it again.

We spent a little time looking into this. One of the things that came up was what’s the real world use case for dynamically being able to change this when the application is running? Clearly it’s useful for testing, but how is this affecting users of your React Native application?

We’re just trying to colour the impact of this.

I fixed the problem by adding this line of style for my reusable view component and it’s good the direction of the app is changed after reload the app using react-native-restart <View style={{ direction: I18nManager.isRTL ? "rtl" : "ltr" }} {...otherProps} />

The same goes for iOS and the version “react-native”: “0.75.4” with the new architecture. . // Enable RTL support [[RCTI18nUtil sharedInstance] allowRTL:YES]; [[RCTI18nUtil sharedInstance] forceRTL:YES];

Adding these lines to the AppDelegate, or removing them doesn’t make a difference at all.

@cipolleschi any news on this topic ? we’re still getting the issue of RTL not being applied properly. Reloading the app manually does nothing (checking rtl using something like ‘rtl:bg-indigo-500’ shows clearly that rtl is being set to the app) using 0.79.4 and expo 53

Fixed after remove expo-localization

removing expo-localization doesn’t fix the issue, plus we need expo-localization in our app

EDIT: removing expo-localization did fix it at the end, moving things around (when to reload and how) plus removing the expo-localization seems to fix the issue. thanks @Karemhz appreciate it

@asgarPeerbits ah I didn’t get your question correctly, I don’t think there is a proper way to use mmkv v2 on ios & v3 on android. just downgrade back to mmkv v2 until this is fixed.

I am also facing the same issue in version 0.76.1. However, it works perfectly on Android; the issue only occurs on iOS.