mirror of
https://github.com/status-im/react-native.git
synced 2025-02-03 13:14:42 +00:00
Wait to clear RCTImageView.image until definitively removed from window
Summary: When `RCTImageView` is removed from the view hierarchy, it clears out its `image` to save memory. This makes sense, except that it gets removed from the window (view hierarchy) even when becoming the child of another view. This fixes the logic so that it only clears out the image if the view hasn't been moved somewhere else within one frame. @public Reviewed By: @javache Differential Revision: D2493849
This commit is contained in:
parent
e65cc9d679
commit
a4ef7abebb
@ -238,8 +238,22 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
[super didMoveToWindow];
|
||||
|
||||
if (!self.window) {
|
||||
[self clearImage];
|
||||
} else if (self.src) {
|
||||
// Don't keep self alive through the asynchronous dispatch, if the intention was to remove the view so it would
|
||||
// deallocate.
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
__strong typeof(self) strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we haven't been re-added to a window by this run loop iteration, clear out the image to save memory.
|
||||
if (!strongSelf.window) {
|
||||
[strongSelf clearImage];
|
||||
}
|
||||
});
|
||||
} else if (!self.image && self.src) {
|
||||
[self reloadImage];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user