diff --git a/Libraries/Image/RCTUIImageViewAnimated.h b/Libraries/Image/RCTUIImageViewAnimated.h index 8b19147b24..1c894a849d 100644 --- a/Libraries/Image/RCTUIImageViewAnimated.h +++ b/Libraries/Image/RCTUIImageViewAnimated.h @@ -8,8 +8,6 @@ #import #import -RCT_EXTERN void RCTUIImageViewEnableWeakProxy(BOOL enabled); - @interface RCTUIImageViewAnimated : UIImageView @end diff --git a/Libraries/Image/RCTUIImageViewAnimated.m b/Libraries/Image/RCTUIImageViewAnimated.m index 6985bbfa74..ce7aae8370 100644 --- a/Libraries/Image/RCTUIImageViewAnimated.m +++ b/Libraries/Image/RCTUIImageViewAnimated.m @@ -11,11 +11,6 @@ #import #import -static BOOL weakProxyEnabled = YES; -void RCTUIImageViewEnableWeakProxy(BOOL enabled) { - weakProxyEnabled = enabled; -} - static NSUInteger RCTDeviceTotalMemory() { return (NSUInteger)[[NSProcessInfo processInfo] physicalMemory]; } @@ -26,7 +21,7 @@ static NSUInteger RCTDeviceFreeMemory() { vm_size_t page_size; vm_statistics_data_t vm_stat; kern_return_t kern; - + kern = host_page_size(host_port, &page_size); if (kern != KERN_SUCCESS) return 0; kern = host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size); @@ -61,7 +56,7 @@ static NSUInteger RCTDeviceFreeMemory() { if (self = [super initWithFrame:frame]) { self.lock = dispatch_semaphore_create(1); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; - + } return self; } @@ -91,28 +86,28 @@ static NSUInteger RCTDeviceFreeMemory() { if (self.image == image) { return; } - + [self stop]; [self resetAnimatedImage]; if ([image respondsToSelector:@selector(animatedImageFrameAtIndex:)]) { NSUInteger animatedImageFrameCount = ((UIImage *)image).animatedImageFrameCount; - + // In case frame count is 0, there is no reason to continue. if (animatedImageFrameCount == 0) { return; } - + self.animatedImage = (UIImage *)image; self.totalFrameCount = animatedImageFrameCount; - + // Get the current frame and loop count. self.totalLoopCount = self.animatedImage.animatedImageLoopCount; - + self.animatedImageScale = image.scale; - + self.currentFrame = image; - + dispatch_semaphore_wait(self.lock, DISPATCH_TIME_FOREVER); self.frameBuffer[@(self.currentFrameIndex)] = self.currentFrame; dispatch_semaphore_signal(self.lock); @@ -123,7 +118,7 @@ static NSUInteger RCTDeviceFreeMemory() { if ([self paused]) { [self start]; } - + [self.layer setNeedsDisplay]; } else { super.image = image; @@ -151,20 +146,14 @@ static NSUInteger RCTDeviceFreeMemory() { - (CADisplayLink *)displayLink { - // TODO (T53783620): This logic should always be enabled. - if (weakProxyEnabled) { - // We only need a displayLink in the case of animated images, so short-circuit this code and don't create one for most of the use cases. - // Since this class is used for all RCTImageView's, this is especially important. - if (!_animatedImage) { - return nil; - } + // We only need a displayLink in the case of animated images, so short-circuit this code and don't create one for most of the use cases. + // Since this class is used for all RCTImageView's, this is especially important. + if (!_animatedImage) { + return nil; } if (!_displayLink) { - __weak typeof(self) weakSelf = self; - // TODO (T53783620): This logic should always be enabled. - id target = weakProxyEnabled ? [RCTWeakProxy weakProxyWithTarget:self] : weakSelf; - _displayLink = [CADisplayLink displayLinkWithTarget:target selector:@selector(displayDidRefresh:)]; + _displayLink = [CADisplayLink displayLinkWithTarget:[RCTWeakProxy weakProxyWithTarget:self] selector:@selector(displayDidRefresh:)]; NSString *runLoopMode = [NSProcessInfo processInfo].activeProcessorCount > 1 ? NSRunLoopCommonModes : NSDefaultRunLoopMode; [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:runLoopMode]; } @@ -199,7 +188,7 @@ static NSUInteger RCTDeviceFreeMemory() { NSUInteger totalFrameCount = self.totalFrameCount; NSUInteger currentFrameIndex = self.currentFrameIndex; NSUInteger nextFrameIndex = (currentFrameIndex + 1) % totalFrameCount; - + // Check if we have the frame buffer firstly to improve performance if (!self.bufferMiss) { // Then check if timestamp is reached @@ -216,7 +205,7 @@ static NSUInteger RCTDeviceFreeMemory() { self.currentTime = nextDuration; } } - + // Update the current frame UIImage *currentFrame; UIImage *fetchFrame; @@ -243,7 +232,7 @@ static NSUInteger RCTDeviceFreeMemory() { } else { self.bufferMiss = YES; } - + // Update the loop count when last frame rendered if (nextFrameIndex == 0 && !self.bufferMiss) { // Update the loop count @@ -255,7 +244,7 @@ static NSUInteger RCTDeviceFreeMemory() { return; } } - + // Check if we should prefetch next frame or current frame NSUInteger fetchFrameIndex; if (self.bufferMiss) { @@ -265,7 +254,7 @@ static NSUInteger RCTDeviceFreeMemory() { // Or, most cases, the decode speed is faster than render speed, we fetch next frame fetchFrameIndex = nextFrameIndex; } - + if (!fetchFrame && !bufferFull && self.fetchQueue.operationCount == 0) { // Prefetch next frame in background queue UIImage *animatedImage = self.animatedImage; @@ -295,7 +284,7 @@ static NSUInteger RCTDeviceFreeMemory() { { NSUInteger bytes = CGImageGetBytesPerRow(self.currentFrame.CGImage) * CGImageGetHeight(self.currentFrame.CGImage); if (bytes == 0) bytes = 1024; - + NSUInteger max = 0; if (self.maxBufferSize > 0) { max = self.maxBufferSize; @@ -305,13 +294,13 @@ static NSUInteger RCTDeviceFreeMemory() { NSUInteger free = RCTDeviceFreeMemory(); max = MIN(total * 0.2, free * 0.6); } - + NSUInteger maxBufferCount = (double)max / (double)bytes; if (!maxBufferCount) { // At least 1 frame maxBufferCount = 1; } - + self.maxBufferCount = maxBufferCount; }