react-native-photo-view icon indicating copy to clipboard operation
react-native-photo-view copied to clipboard

iOS unable to render local images

Open srameshr opened this issue 8 years ago • 30 comments

The images from asset-library and local image path returned by camera is not being rendered. Works fine with remote images though. Both http and https

srameshr avatar Aug 27 '17 08:08 srameshr

Is it working for others?

srameshr avatar Aug 28 '17 11:08 srameshr

I have same problem. downgrade to 1.3 works.

wolfg1969 avatar Aug 30 '17 05:08 wolfg1969

I want MWPPhotoBrowser its available after 1.4.0

srameshr avatar Aug 30 '17 06:08 srameshr

I guess the problem is brought by MWPPhotoBrowser since 1.3.x didn't use it.

wolfg1969 avatar Aug 30 '17 06:08 wolfg1969

Which native Image viewer does 1.3.x use? I see a lot of problem with MWPPhotoBrowser. It does not render remote images at random. https://github.com/alwx/react-native-photo-view/issues/87

srameshr avatar Aug 30 '17 06:08 srameshr

1.3.x use ScrollView from RN. See https://github.com/alwx/react-native-photo-view/commit/9489a513fbacb0e239aa4dc893601f7470363a9a

wolfg1969 avatar Aug 30 '17 07:08 wolfg1969

MWPPhotoBrowser provides pinch to zoom. I would need that.

srameshr avatar Aug 30 '17 08:08 srameshr

Does this support local images? or base64?

gitlovenotwar avatar Aug 30 '17 08:08 gitlovenotwar

Local

srameshr avatar Aug 30 '17 08:08 srameshr

@srameshr how about base64 images?

gitlovenotwar avatar Aug 30 '17 08:08 gitlovenotwar

I have not tried it.

srameshr avatar Aug 30 '17 08:08 srameshr

I've tried it just now, it's not working on base64

gitlovenotwar avatar Aug 30 '17 09:08 gitlovenotwar

Yup, right now it only works with https images. Not local or base64.

srameshr avatar Aug 30 '17 09:08 srameshr

I found the bounds (https://github.com/alwx/react-native-photo-view/blob/master/ios/RNPhotoView.m#L176) will be zero for the images with file:// uri (loaded from photo library or taken from camera). This makes the scaled image no size.

wolfg1969 avatar Sep 02 '17 06:09 wolfg1969

I created a PR (#96) for this issue.

wolfg1969 avatar Sep 02 '17 13:09 wolfg1969

@wolfg1969 Could you also look into https://github.com/npomfret/react-native-image-tools/issues/9 and https://github.com/npomfret/react-native-image-tools/issues/4 . I have no idea about objective-c. Sorry for diverging from the topic of this thread.

srameshr avatar Sep 03 '17 05:09 srameshr

@srameshr I'm afraid not. I'm not a objective-c expert too.

wolfg1969 avatar Sep 03 '17 06:09 wolfg1969

you have to add them manually in your assets in xcode

jjdp avatar Sep 29 '17 07:09 jjdp

@wolfg1969 (cc @srameshr) I still have the issue with URLs like asset-library://asset/... from Camera Roll.

ghost avatar Oct 18 '17 09:10 ghost

I ditched this library and unsubscribing from this thread.

srameshr avatar Oct 18 '17 09:10 srameshr

@kytwb I use react-native-image-picker and it's return file URI works with this library.

wolfg1969 avatar Oct 19 '17 03:10 wolfg1969

RNPhotoView.m

#import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import <AssetsLibrary/ALAssetsLibrary.h>imatgetemporal #import <AssetsLibrary/ALAsset.h> #import <AssetsLibrary/ALAssetRepresentation.h>

  • (void)setSource:(NSDictionary *)source { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if ([_source isEqualToDictionary:source]) { return; } NSString *uri = source[@"uri"]; if (!uri) { return; } _source = source; NSURL *imageURL = [NSURL URLWithString:uri];

      if([uri hasPrefix:@"assets-library://"]){
    
          NSURL *asseturl = [NSURL URLWithString:uri];
          __block ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
          [assetslibrary assetForURL:asseturl
                         resultBlock:^(ALAsset *asset) {
                             __block ALAssetRepresentation * present = [asset defaultRepresentation];
                             __block CGImageRef imgRef = [present fullResolutionImage];
                             __block UIImage *img = [UIImage imageWithCGImage:imgRef
                                                                        scale:present.scale
                                                                  orientation:(UIImageOrientation)present.orientation];
                             [self setImage:img];
                         }
                        failureBlock:^(NSError *error) {
                        }];
    
    
                          return;
    

// // UIImage *image = RCTImageFromLocalAssetURL(imageURL); // if (image) { // if local image // // [self setImage:image]; // return; // } }

    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:imageURL];

janiokq avatar Oct 24 '17 07:10 janiokq

For me local images on my device only work when I have remote js debugging switched on. If it is off I only see a black screen. None of the onLoad events is triggered then.

RN: 0.49.3 react-native-photo-view: 1.5.2

aschmi avatar Nov 22 '17 21:11 aschmi

I solved this in the iOS sim by prepending file:// to my uri, although I haven't confirmed on device yet though.

The uri returned from the image picker was

/Users/yourUser/Library/Developer/CoreSimulator/Devices/32541D85-B1FD-441F-BB2B-B09850500F6C/data/Containers/Data/Application/DF622A86-5E4B-49C5-8DB5-0141BA339314/Documents/images/E136D41D-47E0-4264-AC79-E0D2A6210F49.jpg

So I changed my source to:

uri: 'file:///Users/yourUser/Library/Developer/CoreSimulator/Devices/32541D85-B1FD-441F-BB2B-B09850500F6C/data/Containers/Data/Application/DF622A86-5E4B-49C5-8DB5-0141BA339314/Documents/images/E136D41D-47E0-4264-AC79-E0D2A6210F49.jpg'

computerjazz avatar Dec 08 '17 00:12 computerjazz

I'm still having the issue in 1.5.2, and it doesn't help to prepend file:// to the uri. Anyone with a solution?

@srameshr what library did you use instead?

tommynordli avatar Feb 08 '18 10:02 tommynordli

I built my own

srameshr avatar Feb 08 '18 10:02 srameshr

Same problem here.

scriptgb avatar Mar 05 '18 21:03 scriptgb

@srameshr Could you show your implementation or put it on GitHub? I have the same problem when getting the images using RN CameraRoll.

ManuBu avatar Apr 28 '18 19:04 ManuBu

@ManuBu This is my little implementation to fix the current issue - https://github.com/Warecorp/react-native-photo-view/commit/7a77dd5f519d1bf408111a9a2d21216a0d48e8d0

I didn't implement a common approach because I am needed to show only local images (from document dir).

gigby avatar Oct 26 '18 14:10 gigby

I have the same problem. But I have solved this issue. You may need add width and height to <Image /> style.

{ this.state.image ? <Image style={{height: 100, width: 100}} source={{uri: this.state.image}} /> : null }

tronginc avatar Jan 08 '19 16:01 tronginc