Skip to content

Conversation

@doochik
Copy link
Contributor

@doochik doochik commented Nov 29, 2015

Image from CameraRoll haven't UIImagePickerControllerReferenceURL. So we need to save it to PhotoAlbums first.

To save image I've used the same method from RCTCameraRollManager.

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @nicklockwood, @dvcrn and @yusefnapora to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Nov 29, 2015
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this method already called on the main thread?

@javache
Copy link
Member

javache commented Nov 30, 2015

I'm not sure if this is a good default behaviour. In internal projects, we've used RCTImageStoreManager to (temporarily) store images taken this way.

@doochik
Copy link
Contributor Author

doochik commented Nov 30, 2015

Yes, this is good point. I'll rewrite my PR to use temporary storage

@doochik doochik force-pushed the imagepicker-cameroll branch from 7e90dca to 6761e12 Compare November 30, 2015 18:24
@facebook-github-bot
Copy link
Contributor

@doochik updated the pull request.

@doochik
Copy link
Contributor Author

doochik commented Nov 30, 2015

I've updated my PR. Images from CameraRoll now save to the temporary storage.

And about errors. I've fixed this bug #4411. So now i can pass args something like this. Do you like it?

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info
{

  NSString *imageUri = [info[UIImagePickerControllerReferenceURL] absoluteString];

  // Image from PhotoLibrary
  if (imageUri) {
    [self _dismissPicker:picker args:@[imageUri] error:nil];

  } else {
    // Image from CameraRoll hasn't uri.
    // We need to save it to the store first.
    UIImage *originalImage = (UIImage *) [info objectForKey: UIImagePickerControllerOriginalImage];
    [_bridge.imageStoreManager storeImage:originalImage withBlock:^(NSString *tempImageTag) {
      if (!tempImageTag) {
        NSString *errorMessage = @"Error storing image in RCTImageStoreManager";
        RCTLogWarn(@"%@", errorMessage);
        [self _dismissPicker:picker args:nil error:RCTErrorWithMessage(errorMessage)];
        return;
      }
      [self _dismissPicker:picker args:@[tempImageTag] error:nil];
    }];
  }
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
  [self _dismissPicker:picker args:nil error:RCTErrorWithMessage(@"Cancel")];
}

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you use [...] syntax for accessing keys? Also, no need to cast here:

 UIImage *originalImage = info[UIImagePickerControllerOriginalImage];

@nicklockwood
Copy link
Contributor

One minor style issue, but otherwise this is good to go.

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a warning here that this will cause a memory-leak as-is? You need to remove the image from the imageStoreManager once you're done using it. We're looking into providing automatic solutions for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@javache do you mean a console warning? Or a warning in the documentation?

Copy link
Member

Choose a reason for hiding this comment

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

Just documentation. A warning in the console that you can't fix doesn't sound very useful :)

@javache
Copy link
Member

javache commented Nov 30, 2015

The error API looks good, but I don't think it's necessary in this case since imageStoreManager doesn't explicitly generate errors. (Any error would/should be a fatal runtime error).

Image from CameraRoll haven't UIImagePickerControllerReferenceURL.
So we need to save it to PhotoAlbums first
@doochik doochik force-pushed the imagepicker-cameroll branch from 6761e12 to 0b5fb69 Compare December 1, 2015 08:52
@doochik
Copy link
Contributor Author

doochik commented Dec 1, 2015

I've fixed your comments, squash commits and rebase to master

@facebook-github-bot
Copy link
Contributor

@doochik updated the pull request.

@nicklockwood
Copy link
Contributor

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/197772487225713/int_phab to review.

2 similar comments
@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/197772487225713/int_phab to review.

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/197772487225713/int_phab to review.

@ghost ghost closed this in d08727d Dec 1, 2015
sunnylqm pushed a commit to sunnylqm/react-native that referenced this pull request Dec 2, 2015
Summary: Image from CameraRoll haven't UIImagePickerControllerReferenceURL. So we need to save it to PhotoAlbums first.

To save image I've used the same method from RCTCameraRollManager.
Closes facebook#4412

Reviewed By: svcscm

Differential Revision: D2707249

Pulled By: nicklockwood

fb-gh-sync-id: eee683bd4179700bed46ebf45e569197f3ad2077
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants