【问题标题】:React native - rtl in iosReact native - ios 中的 rtl
【发布时间】:2017-09-04 10:24:48
【问题描述】:

首先我在 android 上工作并且 RTL 工作良好, 我添加了以下代码:

   I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
   sharedI18nUtilInstance.setAllowRTL(context, true);

到 MainActivity.java 和

android:supportsRtl="true"

到 AndroidManifest.xml

在js代码中:

I18nManager.forceRTL(true);

现在的问题是: 我试图在 ios 上设置 rtl 但它不起作用 我加了

 // in AppDelegate.m
   [[RCTI18nUtil sharedInstance] allowRTL:YES];

I18nManager.forceRTL(true);

在js代码中 但所有的文本和 flex 仍然是 ltr ...... 我该怎么办?

【问题讨论】:

标签: ios react-native right-to-left


【解决方案1】:

无需向您的项目添加 RTL 语言。只需打开您的AppDelegate.m 文件in yourProject/ios/YourProject/AppDelegate.m

注意不要打开另一个类似.h扩展名的文件

现在,将#import <React/RCTI18nUtil.h> 添加到代码顶部,如下所示:

#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTI18nUtil.h>      <-- added here

现在重新启动并重建您的应用程序。

现在您可以使用I18nManager 轻松更改整个应用的 RTL 方向。

import {I18nManager} from "react-native"


I18nManager.forceRTL(true) // false for LTR direction

【讨论】:

  • 我认为这是最好的解决方案。适用于 ios 和 android
【解决方案2】:

即使添加新的 RTL 语言,我的问题也没有解决。最后,我通过在didFinishLaunchingWithOptions 函数内的AppDelegate.m 文件中添加以下行来解决这个问题,在allow RTL[[RCTI18nUtil sharedInstance] allowRTL:YES]; 下:

[[RCTI18nUtil sharedInstance] forceRTL:YES];

【讨论】:

  • 不错的解决方案老兄!
  • 但是在尝试设置 forceRTL(false); 时,它仍然是 RTL..有什么帮助吗?
【解决方案3】:

您必须在默认语言旁边添加一种 RTL 语言,它才能工作,更多信息可以找到here

【讨论】:

  • 能否请您描述一下步骤。
猜你喜欢
  • 1970-01-01
  • 2019-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-11
  • 1970-01-01
  • 1970-01-01
  • 2023-01-28
相关资源
最近更新 更多