TextStorage in RCTText is now only set when it differs from old value.

Summary:**Motivation**
Multiple instances of `Text` inside a `ListView` is a bad idea for the performance of the app.
When you create 1000 elements and you scroll through the list it is really slow and laggy because the `NSTextStorage`, which is the backbone of the `RCTText` element, will set more than 1,000 times and also the method `setNeedsDisplay` is called multiple times. This will causes huge memory problems and the app crashes.

With this commit I check in `RCTText` if the `NSTextStorage` differs from the old value. If yes then set it otherwise don't set the `NSTextStorage`. This will prevent to call `setNeedsDisplay` when not really needed.

Gist with sample app to show behavior can be found here: https://gist.github.com/bpoetzschke/28a17969c6aa54219e18
Closes https://github.com/facebook/react-native/pull/6341

Differential Revision: D3035485

Pulled By: nicklockwood

fb-gh-sync-id: 181f01b7f87f765dbb01a4ad3196fc40f9d50694
shipit-source-id: 181f01b7f87f765dbb01a4ad3196fc40f9d50694
This commit is contained in:
Björn Pötzschke 2016-03-10 07:45:17 -08:00 committed by Facebook Github Bot 7
parent 13c49e2006
commit 1832d79bd1
1 changed files with 4 additions and 2 deletions

View File

@ -74,8 +74,10 @@
- (void)setTextStorage:(NSTextStorage *)textStorage
{
_textStorage = textStorage;
[self setNeedsDisplay];
if (_textStorage != textStorage) {
_textStorage = textStorage;
[self setNeedsDisplay];
}
}
- (void)drawRect:(CGRect)rect