所以我们想要的是这样的:
在 iOS 中,我们可以为每种单元格类型使用多个 cellIdentifier 来创建高性能的列表视图。
我现在拥有的是
render() {
const dataBlob = [
{ type: "address", data: { address, gotoEditAddress } },
{ type: "deliveryTime", data: {...} },
{ type: "cartSummary", data: {...} },
...[items.map(item => {{ type: "item", data: {...} }})],
{ type: "paymentInformation", data: {...} },
{ type: "paymentBreakdown", data: {...} },
{ type: "promoCode", data: {...} },
];
this._dataSource = this._dataSource.cloneWithRows(dataBlob);
return (
<ListView ref="ScrollView"
renderRow={this._renderRow}
dataSource={this._dataSource} />
);
)
在 renderRow 方法上
_renderRow = (rowData) => {
const { type, data } = rowData;
if (type === "address") return <AddressRow {...data} />;
if (type === "deliveryTime") return <DeliveryTimeRow {...data} />;
if (type === "menuItem") return <MenuItemRow {...data} />;
if (type === "cartSummary") return <CartSummaryRow {...data} />;
if (type === "promoCode") return <PromoCodeRow {...data} />;
if (type === "paymentInformation") return <PaymentRow {...data} />;
if (type === "paymentBreakdown") return <PaymentBreakdownRow {...data} />;
return null;
};
上面代码的问题在于它使 dataSource.rowHasChanged 方法很难正确实现。
出于某种原因,当我删除一行时,在 RN0.31 中,您将遇到一些 ui 缺陷,例如: