mirror of
https://github.com/status-im/react-native.git
synced 2025-02-25 15:45:32 +00:00
[Image] Add scale support for base64-encoded image.
Summary: Fix issue #1136 Closes https://github.com/facebook/react-native/pull/1721 Github Author: =?UTF-8?q?=E9=9A=90=E9=A3=8E?= <yinfeng.fcx@alibaba-inc.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
This commit is contained in:
parent
f23c022f1b
commit
7fc86dded3
@ -635,17 +635,24 @@ RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (RCT_DEBUG && ![json isKindOfClass:[NSString class]]) {
|
||||
if (RCT_DEBUG && ![json isKindOfClass:[NSString class]] && ![json isKindOfClass:[NSDictionary class]]) {
|
||||
RCTLogConvertError(json, "an image");
|
||||
return nil;
|
||||
}
|
||||
|
||||
UIImage *image;
|
||||
NSString *path;
|
||||
CGFloat scale = 0.0;
|
||||
if ([json isKindOfClass:[NSString class]]) {
|
||||
if ([json length] == 0) {
|
||||
return nil;
|
||||
}
|
||||
path = json;
|
||||
} else {
|
||||
path = [self NSString:json[@"uri"]];
|
||||
scale = [self CGFloat:json[@"scale"]];
|
||||
}
|
||||
|
||||
UIImage *image = nil;
|
||||
NSString *path = json;
|
||||
if ([path hasPrefix:@"data:"]) {
|
||||
NSURL *url = [NSURL URLWithString:path];
|
||||
NSData *imageData = [NSData dataWithContentsOfURL:url];
|
||||
@ -658,6 +665,11 @@ RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[
|
||||
image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:path ofType:nil]];
|
||||
}
|
||||
}
|
||||
|
||||
if (scale > 0) {
|
||||
image = [UIImage imageWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation];
|
||||
}
|
||||
|
||||
// NOTE: we don't warn about nil images because there are legitimate
|
||||
// case where we find out if a string is an image by using this method
|
||||
return image;
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
@interface RCTTabBarItem : UIView
|
||||
|
||||
@property (nonatomic, copy) NSString *icon;
|
||||
@property (nonatomic, copy) id icon;
|
||||
@property (nonatomic, assign, getter=isSelected) BOOL selected;
|
||||
@property (nonatomic, readonly) UITabBarItem *barItem;
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
return _barItem;
|
||||
}
|
||||
|
||||
- (void)setIcon:(NSString *)icon
|
||||
- (void)setIcon:(id)icon
|
||||
{
|
||||
static NSDictionary *systemIcons;
|
||||
static dispatch_once_t onceToken;
|
||||
|
@ -22,7 +22,7 @@ RCT_EXPORT_MODULE()
|
||||
}
|
||||
|
||||
RCT_EXPORT_VIEW_PROPERTY(selected, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(icon, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(icon, id);
|
||||
RCT_REMAP_VIEW_PROPERTY(selectedIcon, barItem.selectedImage, UIImage);
|
||||
RCT_REMAP_VIEW_PROPERTY(badge, barItem.badgeValue, NSString);
|
||||
RCT_CUSTOM_VIEW_PROPERTY(title, NSString, RCTTabBarItem)
|
||||
|
Loading…
x
Reference in New Issue
Block a user