Created
December 28, 2020 21:23
Slow rendering best practices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOT OK | |
void onNewEmailsArrivedNotRecommended(List<Email> newEmails) { | |
emailAdapter.setEmails(newEmails); | |
emailAdapter.notifyDataSetChanged(); | |
} | |
// OK | |
void onNewDataArrivedFastRendering(List<Email> newEmails) { | |
List<Email> oldEmails = emailAdapter.getEmails(); | |
DiffUtil.DiffResult result = DiffUtil.calculateDiff(new EmailDiffCallback(oldEmails, newEmails)); | |
emailAdapter.setEmails(newEmails); | |
result.dispatchUpdatesTo(emailAdapter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment