【问题标题】:react native is there a way disable rtl in a specific view or maintain the same lookreact native 有没有办法在特定视图中禁用 rtl 或保持相同的外观
【发布时间】:2019-09-28 07:41:12
【问题描述】:

我有一个平面列表呈现如下视图

    <TouchableOpacity style= {styles.AdRow}   onPress={() => this.Navigatioe(item.id)}>
          <View style = {styles.LeftItems}>
          <Image source={{uri:item.url}} style={styles.ImagePRosa} />
          </View>
          <View style = {styles.RightItems}>

          <Text style = {styles.TitleText}>{item.title}</Text>
          <Text style = {styles.TitlePrice}>{item.price}</Text>

<Image source={require('../Svg/Location.png')} style={styles.ImagePRosing} />


          <Text style = {styles.TitleCity}>{item.city}</Text>

          <Text style = {styles.TitleNeib}>{item.neib}</Text>


  </View>

</TouchableOpacity>

样式是

  LeftItems:{
  width:"40%",
  height:"100%",
},
RightItems:{
  width:"60%",
position:"relative",
  height:"100%",
},
TitleText:{
  position:"absolute",
  top:4,
  width:"100%",
  height:65,
  left:0,
  right:0,

},
TitlePrice:{
  position:"absolute",
  bottom:0,
  width:"40%",
  height:25,
  left:5,

},
TitleCity:{
  position:"absolute",
  bottom:23,
  width:130,
  height:18,
  right:40,
},
TitleNeib:{
  position:"absolute",
  bottom:2,
  width:130,
  height:18,
  right:40,

},

这对于 rtl 和 ltr 都是需要的,但是因为文档说

没有“真正的”左/右

如前所述,我们将 JS 端的左/右样式映射到 开始/结束,所有留在 RTL 布局的代码在屏幕上变成“右边”, 代码中的右侧在屏幕上变为“左侧”。这很方便,因为 您不需要过多更改产品代码,但这意味着 无法在代码中指定“真左”或“真右”。在 未来,允许组件控制其方向,无论 可能需要语言。

所以在 rtl 和 ltr 期间是否可以保持相同的视图,因为其中的数据是多语言的

【问题讨论】:

  • 您找到解决方案了吗?
  • 你找到解决办法了吗?
  • 不,我只是为 ltr 和 rtl 创建了两种样式,用于 ltr 右为左,左为右,并检查语言是否为 rtl,如果是,我选择了另一种样式,您也可以在 react 中禁用 rtl 支持如果需要,原生

标签: react-native


【解决方案1】:

像这样导入:

import { I18nManager } from 'react-native'

强制使用 RTL:

I18nManager.forceRTL(true);

并使用 textAlign : "right" 表示 RTL OR textAlign : "left" 表示你的 textInput 上的 LTR。

如果您不想要 RTL,请使用:

I18nManager.allowRTL(false);

这里是RN Official Blog Link,您将获得详细的用例。

【讨论】:

  • @Abd BTW 我注意到代码的第一行有一个小语法错误this.Navigatioe 应该是this.Navigation,以防万一出现错误
猜你喜欢
  • 1970-01-01
  • 2016-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-18
  • 1970-01-01
  • 2010-11-24
  • 2019-06-03
相关资源
最近更新 更多