Open callagga opened 6 years ago
Any updates on this?
I think it's about uniqueRowKey.id, it changes in componentWillReceiveProps func, which leads to rerender because key has changed After some test and experiment, I find a way to make delete & add item without filcker possible. The basic idea is to manipulate order while the real order of data remains unchanged(reuse key).
I hope there's a better way. What I do gives me a headache :(
removeAndAdjustKey(source, deletedKey) {
let result = {}
deletedKey = parseInt(deletedKey);
for (key in source) {
key = parseInt(key);
if (key < deletedKey) {
result[key] = source[key];
} else if (key > deletedKey) {
let old = key - 1;
result[old] = source[old];
}
}
return result;
}
componentWillReceiveProps(nextProps) {
let {order: nextOrder} = nextProps;
let curOrder = this.order;
if (curOrder && nextOrder && curOrder.length != nextOrder.length) {
if (curOrder.length > nextOrder.length) {
let deletedOrder = nextProps.deletedOrder;
this._rowsLayouts = this.removeAndAdjustKey(this._rowsLayouts, deletedOrder);
this._resolveRowLayout = this.removeAndAdjustKey(this._resolveRowLayout, deletedOrder);
} else {
let key = nextOrder[curOrder.length];
this._rowsLayouts[key] = new Promise((resolve) => {
this._resolveRowLayout[key] = resolve;
});
}
LayoutAnimation.configureNext(LayoutAnimation.create(220,
LayoutAnimation.Types.easeInEaseOut,
LayoutAnimation.Properties.opacity
));
this._onUpdateLayouts();
}
this.order = [...nextOrder];
}
Any advice here regarding a "flicker" I see across the whole list when I delete just one row from the list. I have tried the same thing with the react-native "flatlist" and I don't see this flicker. The more interesting thing also is that this "flicker" doesn't occur every time. When I say flicker, whilst the 4th item is being removed, when the flicker occurs I see the "redraw" of all items including the 1st/2nd/3rd too.
Reproducing: I took the basic example and added a button at the bottom to trigger removing the 4th item in the list. I should point out my testing is on the IOS simulator. Code below.