mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 22:37:14 +08:00
Add border properties to RCTImageView
Summary: Second attempt at adding border properties to `RCTImageView`. Previous attempt can be found at D14875673 which was reverted. 1. `UIImageView` is no longer laid out in in `layoutSubviews`. 2. `updateWithImage` was not being called, I instead of calling `self.image = image` I was calling `_imageView.image = image` directly which skips calling `updateWithImage`. This meant that image's rendering mode was not changed to `template`. Reviewed By: shergin Differential Revision: D14934103 fbshipit-source-id: b74c692f9f8ad520ef1f9c70ec4b4aa68b868cd4
This commit is contained in:
committed by
Facebook Github Bot
parent
129aeacf48
commit
51990014eb
@@ -6,13 +6,13 @@
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import <React/RCTView.h>
|
||||
#import <React/RCTResizeMode.h>
|
||||
|
||||
@class RCTBridge;
|
||||
@class RCTImageSource;
|
||||
|
||||
@interface RCTImageView : UIImageView
|
||||
@interface RCTImageView : RCTView
|
||||
|
||||
- (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
|
||||
@@ -78,11 +78,13 @@ 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 init])) {
|
||||
if ((self = [super initWithFrame:CGRectZero])) {
|
||||
_bridge = bridge;
|
||||
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
@@ -94,6 +96,9 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source)
|
||||
selector:@selector(clearImageIfDetached)
|
||||
name:UIApplicationDidEnterBackgroundNotification
|
||||
object:nil];
|
||||
_imageView = [[UIImageView alloc] init];
|
||||
_imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
[self addSubview:_imageView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -105,10 +110,14 @@ 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) {
|
||||
super.image = nil;
|
||||
_imageView.image = nil;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -125,10 +134,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
}
|
||||
|
||||
// Apply trilinear filtering to smooth out mis-sized images
|
||||
self.layer.minificationFilter = kCAFilterTrilinear;
|
||||
self.layer.magnificationFilter = kCAFilterTrilinear;
|
||||
_imageView.layer.minificationFilter = kCAFilterTrilinear;
|
||||
_imageView.layer.magnificationFilter = kCAFilterTrilinear;
|
||||
|
||||
super.image = image;
|
||||
_imageView.image = image;
|
||||
}
|
||||
|
||||
- (void)setImage:(UIImage *)image
|
||||
@@ -139,6 +148,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
}
|
||||
}
|
||||
|
||||
- (UIImage *)image {
|
||||
return _imageView.image;
|
||||
}
|
||||
|
||||
- (void)setBlurRadius:(CGFloat)blurRadius
|
||||
{
|
||||
if (blurRadius != _blurRadius) {
|
||||
@@ -186,9 +199,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
if (_resizeMode == RCTResizeModeRepeat) {
|
||||
// Repeat resize mode is handled by the UIImage. Use scale to fill
|
||||
// so the repeated image fills the UIImageView.
|
||||
self.contentMode = UIViewContentModeScaleToFill;
|
||||
_imageView.contentMode = UIViewContentModeScaleToFill;
|
||||
} else {
|
||||
self.contentMode = (UIViewContentMode)resizeMode;
|
||||
_imageView.contentMode = (UIViewContentMode)resizeMode;
|
||||
}
|
||||
|
||||
if ([self shouldReloadImageSourceAfterResize]) {
|
||||
@@ -211,7 +224,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
- (void)clearImage
|
||||
{
|
||||
[self cancelImageLoad];
|
||||
[self.layer removeAnimationForKey:@"contents"];
|
||||
[_imageView.layer removeAnimationForKey:@"contents"];
|
||||
self.image = nil;
|
||||
_imageSource = nil;
|
||||
}
|
||||
@@ -351,9 +364,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
}
|
||||
|
||||
if (image.reactKeyframeAnimation) {
|
||||
[self.layer addAnimation:image.reactKeyframeAnimation forKey:@"contents"];
|
||||
[self->_imageView.layer addAnimation:image.reactKeyframeAnimation forKey:@"contents"];
|
||||
} else {
|
||||
[self.layer removeAnimationForKey:@"contents"];
|
||||
[self->_imageView.layer removeAnimationForKey:@"contents"];
|
||||
self.image = image;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user