0

我想做一个网上商店,我需要一个反应原生的水平部分列表,包含我的产品。这是我的代码。请帮我从右到左滚动。clothes 是一个包含我产品详细信息的对象数组。

    export default class MySectionList extends Component{
        render(){
            return(
               <SectionList
                   sections={Clothes} 
                   horizontal={true}
                   showsHorizontalScrollIndicator={false}
                   renderItem={({item})=>(
                       <View>
                           <Image source={{uri:"item.image",width:'65%',height:200}}/>
                           <Text>{item.name}</Text>
                           <Text>{item.price}</Text>
                       </View>
                  )}
                  renderSectionHeader={({section})=>(
                       <Text>{section.title}</Text>)}
              />
       )
    }
}

这个sectionList从左到右滚动,我需要另一个从左到右滚动。

4

2 回答 2

3

我通过添加一些样式来解决这个问题。不幸的是,I18NManager 无法解决我的问题,所以我使用transform了样式,并且对于我应用的所有部分列表,transform: [{ scaleX: -1 }]并且由于部分列表中的项目将被反转,我再次将这种样式应用于项目包装器。像这样的东西:

    render(){
            return(
               <SectionList
                   sections={Clothes} 
                   horizontal={true}
                   style={{ transform: [{ scaleX: -1 }] }}
                   showsHorizontalScrollIndicator={false}
                   renderItem={({item})=>(
                       <View style={{ transform: [{ scaleX: -1 }] }}>
                           <Image source={{uri:"item.image",width:'65%',height:200}}/>
                           <Text>{item.name}</Text>
                           <Text>{item.price}</Text>
                       </View>
                  )}
                  renderSectionHeader={({section})=>(
                       <Text>{section.title}</Text>)}
              />
           )
       }
    }

这是一种hacky方式,但我没有找到解决我问题的另一种方法。

我希望这可以帮助你

于 2019-08-04T03:46:11.483 回答
1

如果您的应用程序语言是从右到左,请将应用程序支持设置为使用 rtl

I18NManager.allowRTL(true) 
I18NManager.forceRTL(true)  

使部分列表或平面列表从右向左滚动,否则不会发生这种情况。还有另一种方法可以解决这个问题,但它不是系统的!喜欢使用inverted道具或direction风格。

于 2019-08-03T13:06:23.853 回答