Merge pull request #158 from wix/last_frame

Wait for camera to load
This commit is contained in:
Ran Greenberg 2018-04-03 11:16:11 +03:00 committed by GitHub
commit b17a6017d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 14 deletions

View File

@ -2,7 +2,6 @@ package com.wix.RNCameraKit.camera;
import android.graphics.Color;
import android.graphics.Rect;
import android.hardware.Camera;
import android.support.annotation.ColorInt;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
@ -18,6 +17,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
public class CameraView extends FrameLayout implements SurfaceHolder.Callback {
private SurfaceView surface;
private boolean showFrame;
private Rect frameRect;
private BarcodeFrame barcodeFrame;
@ColorInt private int frameColor = Color.GREEN;
@ -78,12 +78,18 @@ public class CameraView extends FrameLayout implements SurfaceHolder.Callback {
post(measureAndLayout);
}
public void setShowFrame(boolean showFrame) {
this.showFrame = showFrame;
}
public void showFrame() {
barcodeFrame = new BarcodeFrame(getContext());
barcodeFrame.setFrameColor(frameColor);
barcodeFrame.setLaserColor(laserColor);
addView(barcodeFrame);
requestLayout();
if (showFrame) {
barcodeFrame = new BarcodeFrame(getContext());
barcodeFrame.setFrameColor(frameColor);
barcodeFrame.setLaserColor(laserColor);
addView(barcodeFrame);
requestLayout();
}
}
public Rect getFramingRectInPreview(int previewWidth, int previewHeight) {
@ -123,4 +129,13 @@ public class CameraView extends FrameLayout implements SurfaceHolder.Callback {
barcodeFrame.setLaserColor(laserColor);
}
}
/**
* Set background color for Surface view on the period, while camera is not loaded yet.
* Provides opportunity for user to hide period while camera is loading
* @param color - color of the surfaceview
*/
public void setSurfaceBgColor(@ColorInt int color) {
surface.setBackgroundColor(color);
}
}

View File

@ -48,6 +48,7 @@ public class CameraViewManager extends SimpleViewManager<CameraView> {
private static AtomicBoolean cameraReleased = new AtomicBoolean(false);
private static boolean shouldScan = false;
private static BarcodeScanner scanner;
private static Camera.PreviewCallback previewCallback = new Camera.PreviewCallback() {
@Override
@ -171,6 +172,8 @@ public class CameraViewManager extends SimpleViewManager<CameraView> {
if (shouldScan) {
camera.setOneShotPreviewCallback(previewCallback);
}
cameraViews.peek().setSurfaceBgColor(Color.TRANSPARENT);
cameraViews.peek().showFrame();
} catch (IOException | RuntimeException e) {
e.printStackTrace();
}
@ -309,11 +312,9 @@ public class CameraViewManager extends SimpleViewManager<CameraView> {
}
}
@ReactProp(name = "showFrame")
@ReactProp(name = "showFrame", defaultBoolean = false)
public void setFrame(CameraView view, boolean show) {
if (show) {
view.showFrame();
}
view.setShowFrame(show);
}
@ReactProp(name = "frameColor", defaultInt = Color.GREEN)
@ -326,6 +327,11 @@ public class CameraViewManager extends SimpleViewManager<CameraView> {
view.setLaserColor(color);
}
@ReactProp(name = "surfaceColor")
public void setSurfaceBackground(CameraView view, @ColorInt int color) {
view.setSurfaceBgColor(color);
}
public static synchronized Rect getFramingRectInPreview(int previewWidth, int previewHeight) {
return cameraViews.peek().getFramingRectInPreview(previewWidth, previewHeight);
}

View File

@ -44,12 +44,13 @@ export default class CameraScreen extends Component {
showFrame={true}
scanBarcode={true}
laserColor={"blue"}
surfaceColor={"black"}
frameColor={"yellow"}
onReadCode = {((event) => this.setState({ example: CheckingScreen}))}
hideControls={true}
onReadCode={((event) => this.setState({ example: CheckingScreen }))}
hideControls={true}
// offsetForScannerFrame = {10}
// heightForScannerFrame = {300}
colorForScannerFrame = {'blue'}
colorForScannerFrame={'blue'}
/>
);
}

View File

@ -16,6 +16,7 @@ export default class CameraKitCamera extends React.Component {
_.update(transformedProps, 'cameraOptions.ratioOverlayColor', (c) => processColor(c));
_.update(transformedProps, 'frameColor', (c) => processColor(c));
_.update(transformedProps, 'laserColor', (c) => processColor(c));
_.update(transformedProps, 'surfaceColor', (c) => processColor(c));
return <NativeCamera {...transformedProps}/>
}

View File

@ -161,7 +161,7 @@ export default class CameraScreenBase extends Component {
scanBarcode={this.props.scanBarcode}
laserColor={this.props.laserColor}
frameColor={this.props.frameColor}
surfaceColor={this.props.surfaceColor}
onReadCode = {this.props.onReadCode}
scannerOptions = {this.state.scannerOptions}
/>