Improve performance of room list re-rendering

Only re-render if the room ID has changed, this stops flickering
when new messages come in.
This commit is contained in:
Kegan Dougal 2021-12-08 10:50:27 +00:00
parent 7f653ab531
commit 7d35e861e3

View file

@ -70,13 +70,19 @@ export class LeftPanelView extends TemplateView {
vm.loadRoomRange(range); vm.loadRoomRange(range);
}, },
shouldRecreateItem: (value, oldValue) => { shouldRecreateItem: (value, oldValue) => {
return true; const oldIsPlaceholder = oldValue instanceof PlaceholderRoomTileViewModel;
// TODO: We used to just recreate the item if the underlying view model was swapped out e.g ph->room const newIsPlaceholder = value instanceof PlaceholderRoomTileViewModel;
if (oldIsPlaceholder != newIsPlaceholder) {
return true;
}
// We used to just recreate the item if the underlying view model was swapped out e.g ph->room
// but there is also a need to recreate items on room->room transitions (to re-make the // but there is also a need to recreate items on room->room transitions (to re-make the
// subviews), so just always recreate views for now. // subviews)
const isOldRoom = oldValue instanceof RoomTileViewModel; // views can be recycled so if the room ID is different then also recreate
const isNewRoom = value instanceof RoomTileViewModel; if (oldValue.id !== value.id) {
return isOldRoom != isNewRoom; return true;
}
return false;
} }
}, },
tileVM => { tileVM => {