Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Examples/UIExplorer/CameraRollExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var CameraRollExample = React.createClass({
return (
<View key={asset} style={styles.row}>
<Image
assetThumbnail={true}
source={asset.node.image}
style={imageStyle}
/>
Expand Down
12 changes: 11 additions & 1 deletion Libraries/Image/Image.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ var Image = React.createClass({
source: PropTypes.shape({
uri: PropTypes.string,
}),
/**
* Force display of the ALAsset in thumbnail format
* This property reduce the memory size and only work with ALAsset
*/
assetThumbnail: PropTypes.bool,
/**
* A static image to display while downloading the final image off the
* network.
Expand Down Expand Up @@ -163,7 +168,11 @@ var Image = React.createClass({
tintColor: style.tintColor,
});
if (isStored) {
nativeProps.imageTag = source.uri;
if (this.props.assetThumbnail === true){
nativeProps.assetThumbnail = source.uri;
}else{
nativeProps.imageTag = source.uri;
}
} else {
nativeProps.src = source.uri;
}
Expand All @@ -188,6 +197,7 @@ var nativeOnlyProps = {
defaultImageSrc: true,
imageTag: true,
contentMode: true,
assetThumbnail:true,
};
if (__DEV__) {
verifyPropTypes(Image, RCTStaticImage.viewConfig, nativeOnlyProps);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Image/RCTCameraRollManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ @implementation RCTCameraRollManager
successCallback:(RCTResponseSenderBlock)successCallback
errorCallback:(RCTResponseSenderBlock)errorCallback)
{
[RCTImageLoader loadImageWithTag:imageTag callback:^(NSError *loadError, UIImage *loadedImage) {
[RCTImageLoader loadImageWithTag:imageTag thumb:NO callback:^(NSError *loadError, UIImage *loadedImage) {
if (loadError) {
errorCallback(@[[loadError localizedDescription]]);
return;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Image/RCTImageLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
* Will always call callback on main thread.
*/
+ (void)loadImageWithTag:(NSString *)tag
thumb:(BOOL)thumb
callback:(void (^)(NSError *error, id /* UIImage or CAAnimation */ image))callback;

@end
11 changes: 9 additions & 2 deletions Libraries/Image/RCTImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ + (ALAssetsLibrary *)assetsLibrary
* Can be called from any thread.
* Will always call callback on main thread.
*/
+ (void)loadImageWithTag:(NSString *)imageTag callback:(void (^)(NSError *error, id image))callback
+ (void)loadImageWithTag:(NSString *)imageTag thumb:(BOOL)thumb callback:(void (^)(NSError *error, id image))callback
{
if ([imageTag hasPrefix:@"assets-library"]) {
[[RCTImageLoader assetsLibrary] assetForURL:[NSURL URLWithString:imageTag] resultBlock:^(ALAsset *asset) {
Expand All @@ -77,10 +77,17 @@ + (void)loadImageWithTag:(NSString *)imageTag callback:(void (^)(NSError *error,
dispatch_async(RCTImageLoaderQueue(), ^{
// Also make sure the image is released immediately after it's used so it
// doesn't spike the memory up during the process.

@autoreleasepool {
UIImage *image = nil;
ALAssetRepresentation *representation = [asset defaultRepresentation];
ALAssetOrientation orientation = [representation orientation];
UIImage *image = [UIImage imageWithCGImage:[representation fullResolutionImage] scale:1.0f orientation:(UIImageOrientation)orientation];
if (!thumb){
image = [UIImage imageWithCGImage:[representation fullResolutionImage] scale:1.0f orientation:(UIImageOrientation)orientation];
}else{
image = [UIImage imageWithCGImage:[asset thumbnail] scale:1.0f orientation:(UIImageOrientation)orientation];
}

RCTDispatchCallbackOnMainQueue(callback, nil, image);
}
});
Expand Down
23 changes: 22 additions & 1 deletion Libraries/Image/RCTStaticImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ - (UIView *)view
RCT_CUSTOM_VIEW_PROPERTY(imageTag, NSString, RCTStaticImage)
{
if (json) {
[RCTImageLoader loadImageWithTag:[RCTConvert NSString:json] callback:^(NSError *error, id image) {
[RCTImageLoader loadImageWithTag:[RCTConvert NSString:json] thumb:NO callback:^(NSError *error, id image) {
if (error) {
RCTLogWarn(@"%@", error.localizedDescription);
}
Expand All @@ -70,5 +70,26 @@ - (UIView *)view
view.image = defaultView.image;
}
}
RCT_CUSTOM_VIEW_PROPERTY(assetThumbnail, NSString, RCTStaticImage)
{
if (json) {
[RCTImageLoader loadImageWithTag:[RCTConvert NSString:json] thumb:YES callback:^(NSError *error, id image) {
if (error) {
RCTLogWarn(@"%@", error.localizedDescription);
}
if ([image isKindOfClass:[CAAnimation class]]) {
[view.layer addAnimation:image forKey:@"contents"];
} else {
[view.layer removeAnimationForKey:@"contents"];
view.image = image;
}
}];
} else {
[view.layer removeAnimationForKey:@"contents"];
view.image = defaultView.image;
}
}



@end