From a789ec61938561bb0daef768b724e6912e3f683c Mon Sep 17 00:00:00 2001 From: Alexander Vasyuk Date: Fri, 12 Apr 2019 12:47:02 -0700 Subject: [PATCH] Revert D14875673: Add border properties to RCTImageView Differential Revision: D14875673 Original commit changeset: 594b2cd1ddff fbshipit-source-id: a9cb74a6dea7bc61e16a146085d08754bdd4bd6e --- Libraries/Image/RCTImageView.h | 4 +-- Libraries/Image/RCTImageView.m | 47 ++++++++++++---------------------- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/Libraries/Image/RCTImageView.h b/Libraries/Image/RCTImageView.h index 24c56d448ba..38f82db455d 100644 --- a/Libraries/Image/RCTImageView.h +++ b/Libraries/Image/RCTImageView.h @@ -6,13 +6,13 @@ */ #import -#import + #import @class RCTBridge; @class RCTImageSource; -@interface RCTImageView : RCTView +@interface RCTImageView : UIImageView - (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER; diff --git a/Libraries/Image/RCTImageView.m b/Libraries/Image/RCTImageView.m index e407cb91dce..3b3d0ea709c 100644 --- a/Libraries/Image/RCTImageView.m +++ b/Libraries/Image/RCTImageView.m @@ -78,13 +78,11 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source) // Whether the latest change of props requires the image to be reloaded BOOL _needsReload; - - UIImageView *_imageView; } - (instancetype)initWithBridge:(RCTBridge *)bridge { - if ((self = [super initWithFrame:CGRectZero])) { + if ((self = [super init])) { _bridge = bridge; NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; @@ -96,8 +94,6 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source) selector:@selector(clearImageIfDetached) name:UIApplicationDidEnterBackgroundNotification object:nil]; - _imageView = [[UIImageView alloc] init]; - [self addSubview:_imageView]; } return self; } @@ -109,14 +105,10 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source) RCT_NOT_IMPLEMENTED(- (instancetype)init) -RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) - -RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) - - (void)updateWithImage:(UIImage *)image { if (!image) { - _imageView.image = nil; + super.image = nil; return; } @@ -133,16 +125,16 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) } // Apply trilinear filtering to smooth out mis-sized images - _imageView.layer.minificationFilter = kCAFilterTrilinear; - _imageView.layer.magnificationFilter = kCAFilterTrilinear; + self.layer.minificationFilter = kCAFilterTrilinear; + self.layer.magnificationFilter = kCAFilterTrilinear; - _imageView.image = image; + super.image = image; } - (void)setImage:(UIImage *)image { image = image ?: _defaultImage; - if (image != _imageView.image) { + if (image != self.image) { [self updateWithImage:image]; } } @@ -165,7 +157,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) _needsReload = YES; } else { _capInsets = capInsets; - [self updateWithImage:_imageView.image]; + [self updateWithImage:self.image]; } } } @@ -174,7 +166,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) { if (_renderingMode != renderingMode) { _renderingMode = renderingMode; - [self updateWithImage:_imageView.image]; + [self updateWithImage:self.image]; } } @@ -194,9 +186,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) if (_resizeMode == RCTResizeModeRepeat) { // Repeat resize mode is handled by the UIImage. Use scale to fill // so the repeated image fills the UIImageView. - _imageView.contentMode = UIViewContentModeScaleToFill; + self.contentMode = UIViewContentModeScaleToFill; } else { - _imageView.contentMode = (UIViewContentMode)resizeMode; + self.contentMode = (UIViewContentMode)resizeMode; } if ([self shouldReloadImageSourceAfterResize]) { @@ -219,8 +211,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) - (void)clearImage { [self cancelImageLoad]; - [_imageView.layer removeAnimationForKey:@"contents"]; - _imageView.image = nil; + [self.layer removeAnimationForKey:@"contents"]; + self.image = nil; _imageSource = nil; } @@ -359,10 +351,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) } if (image.reactKeyframeAnimation) { - [self->_imageView.layer addAnimation:image.reactKeyframeAnimation forKey:@"contents"]; + [self.layer addAnimation:image.reactKeyframeAnimation forKey:@"contents"]; } else { - [self->_imageView.layer removeAnimationForKey:@"contents"]; - self->_imageView.image = image; + [self.layer removeAnimationForKey:@"contents"]; + self.image = image; } if (isPartialLoad) { @@ -409,8 +401,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) _targetSize = frame.size; [self reloadImage]; } else if ([self shouldReloadImageSourceAfterResize]) { - CGSize imageSize = _imageView.image.size; - CGFloat imageScale = _imageView.image.scale; + CGSize imageSize = self.image.size; + CGFloat imageScale = self.image.scale; CGSize idealSize = RCTTargetSize(imageSize, imageScale, frame.size, RCTScreenScale(), (RCTResizeMode)self.contentMode, YES); @@ -458,9 +450,4 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) } } -- (void)layoutSubviews { - [super layoutSubviews]; - _imageView.frame = self.bounds; -} - @end