Created
December 28, 2020 21:23
-
-
Save magdamiu/6b94fca92d65c0c159923d25b65fc99c to your computer and use it in GitHub Desktop.
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