Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion Examples/UIExplorer/CameraRollExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ var CameraRollExample = React.createClass({
return (
<View key={asset} style={styles.row}>
<Image
source={asset.node.image}
source={{
uri:asset.node.image.uri,
assetThumbnail:true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing spaces after : in both properties

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How i can take the "Nit" word ?

}}
style={imageStyle}
/>
<View style={styles.info}>
Expand Down
13 changes: 12 additions & 1 deletion Libraries/Image/Image.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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 works with ALAsset
*/
assetThumbnail: PropTypes.bool,
}),
/**
* A static image to display while downloading the final image off the
Expand Down Expand Up @@ -154,7 +159,11 @@ var Image = React.createClass({
tintColor: style.tintColor,
});
if (isStored) {
nativeProps.imageTag = source.uri;
if (source.assetThumbnail && source.assetThumbnail === true){
nativeProps.assetThumbnail = source.uri;
}else{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: } else {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should be } else {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

nativeProps.imageTag = source.uri;
}
} else {
nativeProps.src = source.uri;
}
Expand All @@ -178,6 +187,8 @@ var nativeOnlyProps = {
src: true,
defaultImageSrc: true,
imageTag: true,
resizeMode: true,
assetThumbnail:true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing a space

};
if (__DEV__) {
verifyPropTypes(Image, RCTStaticImage.viewConfig, nativeOnlyProps);
Expand Down
1 change: 1 addition & 0 deletions Libraries/Image/ImageSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
type ImageSource = {
uri: string;
isStatic: boolean;
assetThumbnail: boolean;
};
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 @@ -60,7 +60,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 @@ -72,10 +72,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){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing space between ) and {

image = [UIImage imageWithCGImage:[representation fullResolutionImage] scale:1.0f orientation:(UIImageOrientation)orientation];
}else{
image = [UIImage imageWithCGImage:[asset thumbnail]];
}

RCTDispatchCallbackOnMainQueue(callback, nil, image);
}
});
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Image/RCTImageRequestHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ - (id)sendRequest:(NSURLRequest *)request
{
NSNumber *requestToken = @(++_currentToken);
NSString *URLString = [request.URL absoluteString];
[RCTImageLoader loadImageWithTag:URLString callback:^(NSError *error, UIImage *image) {
[RCTImageLoader loadImageWithTag:URLString thumb:NO callback:^(NSError *error, UIImage *image) {
if (error) {
[delegate URLRequest:requestToken didCompleteWithError:error];
return;
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