gpt4 book ai didi

react-native - 如何在水平 `FlatList` 上显示垂直分隔符?

转载 作者:行者123 更新时间:2023-12-02 15:07:53 25 4
gpt4 key购买 nike

enter image description here

我正在使用 React Native 的新 FlatList 组件。我用它来呈现一个水平列表,但是当使用内置的ItemRenderComponent时,它会在每个项目下方呈现分隔符,而不是介于两者之间。

有办法改变吗?

 interface State {
dataSource: WhosOutByPolicy[];
}

interface Props {
data: WhosOutByPolicy[];
}

class WhosOutParentCell extends Component<Props, State> {
constructor(props: Props) {
super(props);

this.state = { dataSource: props.data };
}

renderSeparator = () => {
return (
<View
style={{
height: 100,
width: 3,
backgroundColor: "#D81458"
}}
/>
);
};

render() {
return (
<View style={styles.container}>
<FlatList
data={this.state.dataSource}
horizontal={true}
renderItem={({ item }) => (
<WhosOutUsersInPolicyCell data={item} />
)}
keyExtractor={item => item.policyDispalyName}
ItemSeparatorComponent={this.renderSeparator}
/>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#EFEFEF"
}
});

export default WhosOutParentCell;

最佳答案

这是一个尚未修复的 react-native 错误。你可以重写你的代码来解决这个问题:

renderSeparator = () => {
return (
<View
style = {{
height: 100,
width: 3,
backgroundColor: '#D81458'
}}
/>
)
}

_renderItem = ({item, index}) => (
<View style={{flexDirection: 'row'}}>
<WhosOutUsersInPolicyCell data = { item } />
{(index !== this.state.dataSource.length - 1) && this.renderSeparator()}
</View>
)

render() {
return (
<View style = { styles.container } >
<FlatList
data = { this.state.dataSource }
horizontal = { true }
renderItem = {this._renderItem}
keyExtractor = { item => item.policyDispalyName }
/>
</View>
)
}

关于react-native - 如何在水平 `FlatList` 上显示垂直分隔符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46103396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com