[RN] Prevent reloading library photos on every animation frame

This commit is contained in:
Spencer Ahrens 2015-09-06 17:06:35 -07:00
parent 97a54b5569
commit 1f6f60582d
1 changed files with 5 additions and 6 deletions

View File

@ -31,6 +31,7 @@
@implementation RCTImageView
{
RCTBridge *_bridge;
CGSize _targetSize;
}
- (instancetype)initWithBridge:(RCTBridge *)bridge
@ -173,19 +174,17 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
{
[super reactSetFrame:frame];
if (self.image == nil) {
_targetSize = frame.size;
[self reloadImage];
} else if ([RCTImageView srcNeedsReload:_src]) {
// Get optimal image size
CGSize currentSize = self.image.size;
CGSize idealSize = RCTTargetSize(self.image.size, self.image.scale, frame.size,
RCTScreenScale(), self.contentMode, YES);
CGFloat widthChangeFraction = ABS(currentSize.width - idealSize.width) / currentSize.width;
CGFloat heightChangeFraction = ABS(currentSize.height - idealSize.height) / currentSize.height;
CGFloat widthChangeFraction = ABS(_targetSize.width - idealSize.width) / _targetSize.width;
CGFloat heightChangeFraction = ABS(_targetSize.height - idealSize.height) / _targetSize.height;
// If the combined change is more than 20%, reload the asset in case there is a better size.
if (widthChangeFraction + heightChangeFraction > 0.2) {
_targetSize = idealSize;
[self reloadImage];
}
}