前段时间在群里有人问我,类似天猫类目分类这种列表怎么实现,其实这个类目不算复杂,只要清楚这两个列表之间的关系,选择好相应的组件,开发起来还是挺简单的,只是在开发中也有几个需要注意的小细节处理
https://github.com/guangqiang-liu/react-native-categoryListDemo
this._flatList = flatList}
data={data}
ListHeaderComponent={() => ( )}
ListFooterComponent={() => ( )}
ItemSeparatorComponent={() => }
renderItem={this._renderItem}
onEndReachedThreshold={20}
showsVerticalScrollIndicator={false}
>
this._sectionList = ref}
renderSectionHeader={this.sectionComp}
renderItem={(data) => this.renderItem(data)}
sections={tempArr}
ItemSeparatorComponent={() => }
ListHeaderComponent={() => }
ListFooterComponent={() => }
showsVerticalScrollIndicator={false}
keyExtractor={(item, index) => 'key' + index + item}
/>
// 设置列表的偏移量
_renderItem = item => {
let index = item.index
let title = item.item.title
return (
{
(CateData.data.length - index) * 45 > height - 65 ? this._flatList.scrollToOffset({animated: true, offset: index * 45}) : null
this._sectionList.scrollToLocation({itemIndex: 0, sectionIndex: 0, animated: true, viewOffset: 20})
this.setState({selectedRootCate: index})
}}
>
{title}
)
}