【问题标题】:how to change layout direction in react native?如何在本机反应中改变布局方向?
【发布时间】:2020-08-01 18:40:09
【问题描述】:

我正在使用 i18next 和 react-i18library 来更改我的 react 本机应用程序中的语言,但我需要将方向从 ltr 更改为 rtl,反之亦然,而与设备语言无关并保存方向。

我已经配置了 i18n,我正在更改语言,但我不知道如何更改方向

changeLanguage = lnName => {
  i18n.changeLanguage(lnName);
  // change direrction persian -> rtl / english -> ltr
};
"i18next": "^19.4.2",
"native-base": "^2.13.12",
"react": "16.11.0",
"react-i18next": "^11.3.4",
"react-native": "0.62.2",
"react-native-restart": "^0.0.14",

【问题讨论】:

    标签: android react-native react-navigation i18next react-i18next


    【解决方案1】:

    I18next 有一个 dir 方法,给定 lang 将返回 lrt / rtl 值。

    import React from 'react';
    import { useTranslation } from 'react-i18next';
    
    const Layout = () => {
      const {
        i18n: { dir, language },
      } = useTranslation();
      const changeLanguage = lnName => {
        i18n.changeLanguage(lnName);
      };
    
      return <View style={{ direction: dir(language) }} />;
    };
    

    【讨论】:

    • 我试过这个,但没有任何区别。我正在使用 I18Manager.forceRTL( true ),但我不确定它是否正常工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多