fix(android): Fix image path on Android, and add iOS implementation. (#2782)

Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
This commit is contained in:
cristianoccazinsp 2020-04-08 17:51:48 -03:00 committed by GitHub
parent 85b951ced1
commit baf6f9fd52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 14 deletions

View File

@ -247,11 +247,9 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
mBgHandler.post(new Runnable() {
@Override
public void run() {
final File path = options.hasKey("path") ? new File(options.getString("path")) : cacheDirectory;
mPictureTakenPromises.add(promise);
mPictureTakenOptions.put(promise, options);
mPictureTakenDirectories.put(promise, path);
mPictureTakenDirectories.put(promise, cacheDirectory);
try {
RNCameraView.super.takePicture(options);

View File

@ -180,15 +180,10 @@ public class ResolveTakenPictureAsyncTask extends AsyncTask<Void, Void, Writable
if (!mOptions.hasKey("doNotSave") || !mOptions.getBoolean("doNotSave")) {
// Prepare file output
File imageFile;
if(mCacheDirectory.isDirectory()){
File imageFile = new File(getImagePath());
imageFile = new File(RNFileUtils.getOutputFilePath(mCacheDirectory, ".jpg"));
}
else{
imageFile=mCacheDirectory;
}
imageFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(imageFile);
// Save byte array (it is already a JPEG)
@ -318,13 +313,20 @@ public class ResolveTakenPictureAsyncTask extends AsyncTask<Void, Void, Writable
return rotationDegrees;
}
private String getImagePath() throws IOException{
if(mOptions.hasKey("path")){
return mOptions.getString("path");
}
return RNFileUtils.getOutputFilePath(mCacheDirectory, ".jpg");
}
private String writeStreamToFile(ByteArrayOutputStream inputStream) throws IOException {
String outputPath = null;
IOException exception = null;
FileOutputStream outputStream = null;
try {
outputPath = RNFileUtils.getOutputFilePath(mCacheDirectory, ".jpg");
outputPath = getImagePath();
outputStream = new FileOutputStream(outputPath);
inputStream.writeTo(outputStream);
} catch (IOException e) {

View File

@ -915,7 +915,13 @@ BOOL _sessionInterrupted = NO;
NSMutableDictionary *response = [[NSMutableDictionary alloc] init];
NSString *path = [RNFileSystem generatePathInDirectory:[[RNFileSystem cacheDirectoryPath] stringByAppendingPathComponent:@"Camera"] withExtension:@".jpg"];
NSString *path = nil;
if (options[@"path"]) {
path = options[@"path"];
}
else{
path = [RNFileSystem generatePathInDirectory:[[RNFileSystem cacheDirectoryPath] stringByAppendingPathComponent:@"Camera"] withExtension:@".jpg"];
}
if (![options[@"doNotSave"] boolValue]) {
response[@"uri"] = [RNImageUtils writeImage:destData toPath:path];
@ -1129,7 +1135,7 @@ BOOL _sessionInterrupted = NO;
device.activeVideoMinFrameDuration = CMTimeMake(1, (int32_t)desiredFPS);
device.activeVideoMaxFrameDuration = CMTimeMake(1, (int32_t)desiredFPS);
[device unlockForConfiguration];
}
}
} else {
RCTLog(@"We could not find a suitable format for this device.");
}

View File

@ -336,9 +336,19 @@ RCT_REMAP_METHOD(takePicture,
RCTLogError(@"Invalid view returned from registry, expecting RNCamera, got: %@", view);
} else {
#if TARGET_IPHONE_SIMULATOR
NSMutableDictionary *response = [[NSMutableDictionary alloc] init];
float quality = [options[@"quality"] floatValue];
NSString *path = [RNFileSystem generatePathInDirectory:[[RNFileSystem cacheDirectoryPath] stringByAppendingPathComponent:@"Camera"] withExtension:@".jpg"];
NSString *path = nil;
if (options[@"path"]) {
path = options[@"path"];
}
else{
path = [RNFileSystem generatePathInDirectory:[[RNFileSystem cacheDirectoryPath] stringByAppendingPathComponent:@"Camera"] withExtension:@".jpg"];
}
UIImage *generatedPhoto = [RNImageUtils generatePhotoOfSize:CGSizeMake(200, 200)];
BOOL useFastMode = options[@"fastMode"] && [options[@"fastMode"] boolValue];
if (useFastMode) {