【问题标题】:How change only specific child styles property in react native?如何在本机反应中仅更改特定的子样式属性?
【发布时间】:2020-04-24 05:17:26
【问题描述】:

代码:

<View style={mainContainerStyle}>
    <View style={style1}>
      {View1}
    </View>
    <View style={style2}>
      {View2}
    </View>
    <View style={style3}>
      {View3}
    </View>
    <View style={style4}>
      {View4}
    </View>
</View>

在这种情况下,我想检查:style1、style2、style3、style 4。这些是子样式属性。

如果我找到任何样式{ flexDirection: 'row' },我应该让它'row-reverse'。如何做到这一点?请帮帮我。

【问题讨论】:

    标签: javascript reactjs stylesheet


    【解决方案1】:

    我认为您可以使用函数来执行特定逻辑

    function format(style) {
      if (style.flexDirection === 'row') {
        return Object.assign({}, style, { flexDirection: 'row-reverse' });
      }
      return style;
    }
    
    

    把它包起来:

    
    <View style={mainContainerStyle}>
        <View style={format(style1)}>
          {View1}
        </View>
        <View style={format(style2)}>
          {View2}
        </View>
        <View style={format(style3)}>
          {View3}
        </View>
        <View style={format(style4)}>
          {View4}
        </View>
    </View>
    

    【讨论】:

      猜你喜欢
      • 2019-05-14
      • 1970-01-01
      • 2020-08-07
      • 2021-04-10
      • 2021-10-21
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 2021-01-07
      相关资源
      最近更新 更多