Skip to content
This repository was archived by the owner on Jun 16, 2023. It is now read-only.

Commit ad87c8e

Browse files
committed
fix(picture-size): create None default value
1 parent 92e8ece commit ad87c8e

File tree

7 files changed

+39
-13
lines changed

7 files changed

+39
-13
lines changed

android/src/main/java/com/google/android/cameraview/Camera1.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,16 @@ SortedSet<Size> getAvailablePictureSizes(AspectRatio ratio) {
242242

243243
@Override
244244
void setPictureSize(Size size) {
245-
mPictureSize = size;
245+
if (size == null) {
246+
if (mAspectRatio == null) {
247+
return;
248+
}
249+
mPictureSize = mPictureSizes.sizes(mAspectRatio).last();
250+
} else {
251+
mPictureSize = size;
252+
}
246253
if (mCameraParameters != null && mCamera != null) {
247-
mCameraParameters.setPictureSize(size.getWidth(), size.getHeight());
254+
mCameraParameters.setPictureSize(mPictureSize.getWidth(), mPictureSize.getHeight());
248255
mCamera.setParameters(mCameraParameters);
249256
}
250257
}

android/src/main/java/com/google/android/cameraview/Camera2.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,14 @@ void setPictureSize(Size size) {
366366
if (mStillImageReader != null) {
367367
mStillImageReader.close();
368368
}
369-
mPictureSize = size;
369+
if (size == null) {
370+
if (mAspectRatio == null) {
371+
return;
372+
}
373+
mPictureSizes.sizes(mAspectRatio).last();
374+
} else {
375+
mPictureSize = size;
376+
}
370377
prepareStillImageReader();
371378
startCaptureSession();
372379
}

android/src/main/java/org/reactnative/camera/CameraViewManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void setWhiteBalance(RNCameraView view, int whiteBalance) {
103103

104104
@ReactProp(name = "pictureSize")
105105
public void setPictureSize(RNCameraView view, String size) {
106-
view.setPictureSize(Size.parse(size));
106+
view.setPictureSize(size.equals("None") ? null : Size.parse(size));
107107
}
108108

109109
@ReactProp(name = "barCodeTypes")

android/src/main/java/org/reactnative/camera/RNCameraView.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -127,30 +127,38 @@ public void onFramePreview(CameraView cameraView, byte[] data, int width, int he
127127
int correctWidth = width;
128128
int correctHeight = height;
129129
byte[] correctData = data;
130+
boolean willCallBarCodeTask = mShouldScanBarCodes && !barCodeScannerTaskLock && cameraView instanceof BarCodeScannerAsyncTaskDelegate;
131+
boolean willCallFaceTask = mShouldDetectFaces && !faceDetectorTaskLock && cameraView instanceof FaceDetectorAsyncTaskDelegate;
132+
boolean willCallGoogleBarcodeTask = mShouldGoogleDetectBarcodes && !googleBarcodeDetectorTaskLock && cameraView instanceof BarcodeDetectorAsyncTaskDelegate;
133+
boolean willCallTextTask = mShouldRecognizeText && !textRecognizerTaskLock && cameraView instanceof TextRecognizerAsyncTaskDelegate;
134+
if (!willCallBarCodeTask && !willCallFaceTask && !willCallGoogleBarcodeTask && !willCallTextTask) {
135+
return;
136+
}
137+
130138
if (correctRotation == 90) {
131-
correctWidth = height;
132-
correctHeight = width;
133-
correctData = rotateImage(data, correctHeight, correctWidth);
139+
correctWidth = height;
140+
correctHeight = width;
141+
correctData = rotateImage(data, correctHeight, correctWidth);
134142
}
135-
if (mShouldScanBarCodes && !barCodeScannerTaskLock && cameraView instanceof BarCodeScannerAsyncTaskDelegate) {
143+
if (willCallBarCodeTask) {
136144
barCodeScannerTaskLock = true;
137145
BarCodeScannerAsyncTaskDelegate delegate = (BarCodeScannerAsyncTaskDelegate) cameraView;
138146
new BarCodeScannerAsyncTask(delegate, mMultiFormatReader, correctData, correctWidth, correctHeight).execute();
139147
}
140148

141-
if (mShouldDetectFaces && !faceDetectorTaskLock && cameraView instanceof FaceDetectorAsyncTaskDelegate) {
149+
if (willCallFaceTask) {
142150
faceDetectorTaskLock = true;
143151
FaceDetectorAsyncTaskDelegate delegate = (FaceDetectorAsyncTaskDelegate) cameraView;
144152
new FaceDetectorAsyncTask(delegate, mFaceDetector, correctData, correctWidth, correctHeight, correctRotation).execute();
145153
}
146154

147-
if (mShouldGoogleDetectBarcodes && !googleBarcodeDetectorTaskLock && cameraView instanceof BarcodeDetectorAsyncTaskDelegate) {
155+
if (willCallGoogleBarcodeTask) {
148156
googleBarcodeDetectorTaskLock = true;
149157
BarcodeDetectorAsyncTaskDelegate delegate = (BarcodeDetectorAsyncTaskDelegate) cameraView;
150158
new BarcodeDetectorAsyncTask(delegate, mGoogleBarcodeDetector, correctData, correctWidth, correctHeight, correctRotation).execute();
151159
}
152160

153-
if (mShouldRecognizeText && !textRecognizerTaskLock && cameraView instanceof TextRecognizerAsyncTaskDelegate) {
161+
if (willCallTextTask) {
154162
textRecognizerTaskLock = true;
155163
TextRecognizerAsyncTaskDelegate delegate = (TextRecognizerAsyncTaskDelegate) cameraView;
156164
new TextRecognizerAsyncTask(delegate, mTextRecognizer, correctData, correctWidth, correctHeight, correctRotation).execute();

ios/RN/RNCamera.m

+3
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ - (void)initializeCaptureSessionInput
616616
- (void)updateSessionPreset:(AVCaptureSessionPreset)preset
617617
{
618618
#if !(TARGET_IPHONE_SIMULATOR)
619+
if ([preset integerValue] < 0) {
620+
return;
621+
}
619622
if (preset) {
620623
if (self.isDetectingFaces && [preset isEqual:AVCaptureSessionPresetPhoto]) {
621624
RCTLog(@"AVCaptureSessionPresetPhoto not supported during face detection. Falling back to AVCaptureSessionPresetHigh");

ios/RN/RNCameraManager.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ + (NSDictionary *)pictureSizes
134134
@"Photo" : AVCaptureSessionPresetPhoto,
135135
@"High" : AVCaptureSessionPresetHigh,
136136
@"Medium" : AVCaptureSessionPresetMedium,
137-
@"Low" : AVCaptureSessionPresetLow
137+
@"Low" : AVCaptureSessionPresetLow,
138+
@"None": @(-1),
138139
};
139140
}
140141

src/RNCamera.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
234234
captureAudio: false,
235235
useCamera2Api: false,
236236
playSoundOnCapture: false,
237-
pictureSize: '1920x1080',
237+
pictureSize: 'None',
238238
videoStabilizationMode: 0,
239239
};
240240

0 commit comments

Comments
 (0)