This commit is contained in:
Radu Popovici 2016-04-03 10:06:28 +03:00
commit 98bd7a853a
5 changed files with 28 additions and 13 deletions

View File

@ -2,6 +2,7 @@ import React, {
Component,
NativeAppEventEmitter,
NativeModules,
Platform,
PropTypes,
StyleSheet,
requireNativeComponent,
@ -183,6 +184,12 @@ export default class Camera extends Component {
}
hasFlash() {
if (Platform.OS === 'android') {
const props = convertStringProps(this.props);
return CameraManager.hasFlash({
type: props.type
});
}
return CameraManager.hasFlash();
}
}

View File

@ -249,7 +249,7 @@ Supported options:
Returns the camera's current field of view.
#### `iOS` `hasFlash(): Promise`
#### `hasFlash(): Promise`
Returns whether or not the camera has flash capabilities.

View File

@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
public class RCTCameraModule extends ReactContextBaseJavaModule {
private static final String TAG = "RCTCameraModule";
@ -250,6 +251,17 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
// TODO: implement video capture
}
@ReactMethod
public void hasFlash(ReadableMap options, final Promise promise) {
Camera camera = RCTCamera.getInstance().acquireCameraInstance(options.getInt("type"));
if (null == camera) {
promise.reject("No camera found.");
return;
}
List<String> flashModes = camera.getParameters().getSupportedFlashModes();
promise.resolve(null != flashModes && !flashModes.isEmpty());
}
private File getOutputMediaFile(int type) {
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "RCTCameraModule");

View File

@ -59,6 +59,7 @@ typedef NS_ENUM(NSInteger, RCTCameraTorchMode) {
@property (nonatomic, assign) NSInteger presetCamera;
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer;
@property (nonatomic, assign) NSInteger videoTarget;
@property (nonatomic, assign) NSInteger orientation;
@property (nonatomic, assign) BOOL mirrorImage;
@property (nonatomic, strong) RCTPromiseResolveBlock videoResolve;
@property (nonatomic, strong) RCTPromiseRejectBlock videoReject;

View File

@ -243,18 +243,12 @@ RCT_EXPORT_METHOD(changeFlashMode:(NSInteger)flashMode) {
}
RCT_EXPORT_METHOD(changeOrientation:(NSInteger)orientation) {
[self setOrientation:orientation];
if (self.previewLayer.connection.isVideoOrientationSupported) {
self.previewLayer.connection.videoOrientation = orientation;
}
else {
// Setting videoOrientation isn't yet supported, so we have to wait until
// startSession has finished to set it. Put this in the queue behind.
dispatch_async(self.sessionQueue, ^{
self.previewLayer.connection.videoOrientation = orientation;
});
}
}
RCT_EXPORT_METHOD(changeMirrorImage:(BOOL)mirrorImage) {
self.mirrorImage = mirrorImage;
}
@ -372,6 +366,7 @@ RCT_EXPORT_METHOD(hasFlash:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRej
});
}]];
[self.previewLayer.connection setVideoOrientation:self.orientation];
[self.session startRunning];
});
}
@ -698,8 +693,8 @@ didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
NSFileManager * fileManager = [NSFileManager defaultManager];
NSError * error = nil;
//copying destination
if (!([fileManager copyItemAtPath:[outputFileURL path] toPath:fullPath error:&error])) {
//moving to destination
if (!([fileManager moveItemAtPath:[outputFileURL path] toPath:fullPath error:&error])) {
self.videoReject(RCTErrorUnspecified, nil, RCTErrorWithMessage(error.description));
return;
}
@ -712,8 +707,8 @@ didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
NSFileManager * fileManager = [NSFileManager defaultManager];
NSError * error = nil;
//copying destination
if (!([fileManager copyItemAtPath:[outputFileURL path] toPath:fullPath error:&error])) {
//moving to destination
if (!([fileManager moveItemAtPath:[outputFileURL path] toPath:fullPath error:&error])) {
self.videoReject(RCTErrorUnspecified, nil, RCTErrorWithMessage(error.description));
return;
}