ela*_*eee 5 react-native react-native-sectionlist
您知道如何在sectionList组件React-native中制作水平截面(特定)吗?我想水平放置第二部分,我尝试使用flex:1和flexDirection:'row'修改renderItem中的项目样式,但是不起作用。任何人都知道如何设置节的自定义样式或制作水平节?(红色圆圈)
<View>
<SectionList
renderItem={({item, index, section}) => <CellMainNews isFirst={index===0 ? true: false} data={ item } onPress = {item.onPress } />}
renderSectionHeader={({section: {title}}) => (
<Text style={{fontWeight: 'bold'}}>{title}</Text>
)}
sections={[
{title: 'Top post', data: this.props.featured.top, renderItem: overrideRenderItem },
// this section
{title: 'Featured posts', data: this.props.featured.secundary, renderItem: overrideRenderItemTwo },
{title: 'Stories', data: this.props.stories},
]}
keyExtractor={(item, index) => item + index}
/>
{this.props.loading &&
<View>
<ActivityIndicator size={100} color="red" animating={this.props.loading} />
</View>
}
</View>
Run Code Online (Sandbox Code Playgroud)
问候。
小智 7
由于SectionList
没有在其各个部分上放置容器视图,因此有点困难,但是您可以通过传递包含该元素上所有项目的单个元素数组来实现。
然后,您可以使用首选项的组件以所需的方式呈现此部分中的所有项目。
我建议使用 FlatList
<View>
<SectionList
renderItem={({item, index, section}) => <CellMainNews isFirst={index===0 ? true: false} data={ item } onPress = {item.onPress } />}
renderSectionHeader={({section: {title}}) => (
<Text style={{fontWeight: 'bold'}}>{title}</Text>
)}
sections={[
{title: 'Top post', data: this.props.featured.top, renderItem: overrideRenderItem },
{title: 'Featured posts', data: [this.props.featured.secundary], renderItem: overrideRenderItemTwo }, // Passing here the single element array
{title: 'Stories', data: this.props.stories},
]}
keyExtractor={(item, index) => String(index)}
/>
{this.props.loading &&
<View>
<ActivityIndicator size={100} color="red" animating={this.props.loading} />
</View>
}
</View>
Run Code Online (Sandbox Code Playgroud)
和你的overrideRenderItemTwo
const overrideRenderItemTwo = ({ item, index, section: { title, data } }) => {
return (
<FlatList
showsHorizontalScrollIndicator={false}
pagingEnabled={true}
horizontal={true}
data={item}
keyExtractor={(item, index) => String(index)}
renderItem={(
({item}) => (<CellMainNews isSecundary={true} isFirst={index===0 ? true: false} data={ item } onPress = {item.onPress } />)
)}
/>
);
}
Run Code Online (Sandbox Code Playgroud)
这样做的好处是,您可以将所需的样式用于特定部分的容器视图
归档时间: |
|
查看次数: |
2479 次 |
最近记录: |