mirror of
https://github.com/status-im/react-native.git
synced 2025-02-25 15:45:32 +00:00
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:
parent
13c49e2006
commit
1832d79bd1
@ -74,8 +74,10 @@
|
||||
|
||||
- (void)setTextStorage:(NSTextStorage *)textStorage
|
||||
{
|
||||
_textStorage = textStorage;
|
||||
[self setNeedsDisplay];
|
||||
if (_textStorage != textStorage) {
|
||||
_textStorage = textStorage;
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)rect
|
||||
|
Loading…
x
Reference in New Issue
Block a user