Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/Camera.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ import NativeCameraKitModule from './specs/NativeCameraKitModule';
const Camera = React.forwardRef<CameraApi, CameraProps>((props, ref) => {
const nativeRef = React.useRef(null);

// RN doesn't support optional view props yet (sigh)
// so we have to use -1 to indicate 'undefined'
// All int/float/double props from src/specs/CameraNativeComponent.ts need be mentioned here
props.zoom = props.zoom ?? -1;
props.maxZoom = props.maxZoom ?? -1;
props.scanThrottleDelay = props.scanThrottleDelay ?? -1;
props.faceDetectionThrottleMs = props.faceDetectionThrottleMs ?? -1;

props.allowedBarcodeTypes = props.allowedBarcodeTypes ?? supportedCodeFormats;

React.useImperativeHandle(ref, () => ({
capture: async (options = {}) => {
return await NativeCameraKitModule.capture(options, findNodeHandle(nativeRef.current) ?? undefined);
Expand All @@ -30,10 +20,22 @@ const Camera = React.forwardRef<CameraApi, CameraProps>((props, ref) => {
},
}));

const transformedProps: CameraProps = { ...props };
transformedProps.ratioOverlayColor = processColor(props.ratioOverlayColor) as any;
transformedProps.frameColor = processColor(props.frameColor) as any;
transformedProps.laserColor = processColor(props.laserColor) as any;
// RN can't express optional int/float view props yet, so we default
// undefined -> -1 (and other sentinels). Build a NEW object instead of
// mutating `props`: React freezes element props in dev, so writing to them
// throws "Cannot add new property" once the module runs in strict mode
// (ES modules are always strict).
const transformedProps: CameraProps = {
...props,
zoom: props.zoom ?? -1,
maxZoom: props.maxZoom ?? -1,
scanThrottleDelay: props.scanThrottleDelay ?? -1,
faceDetectionThrottleMs: props.faceDetectionThrottleMs ?? -1,
allowedBarcodeTypes: props.allowedBarcodeTypes ?? supportedCodeFormats,
ratioOverlayColor: processColor(props.ratioOverlayColor) as any,
frameColor: processColor(props.frameColor) as any,
laserColor: processColor(props.laserColor) as any,
};

// @ts-expect-error props for codegen differ a bit from the user-facing ones
return <NativeCamera style={{ minWidth: 100, minHeight: 100 }} ref={nativeRef} {...transformedProps} />;
Expand Down
37 changes: 23 additions & 14 deletions src/Camera.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ import NativeCameraKitModule from './specs/NativeCameraKitModule';
const Camera = React.forwardRef<CameraApi, CameraProps>((props, ref) => {
const nativeRef = React.useRef(null);

// RN doesn't support optional view props yet (sigh)
// so we have to use -1 to indicate 'undefined'
// All int/float/double props from src/specs/CameraNativeComponent.ts need be mentioned here
props.zoom = props.zoom ?? -1;
props.maxZoom = props.maxZoom ?? -1;
props.scanThrottleDelay = props.scanThrottleDelay ?? -1;
props.faceDetectionThrottleMs = props.faceDetectionThrottleMs ?? -1;
props.iOsDeferredStart = props.iOsDeferredStart ?? true;

props.allowedBarcodeTypes = props.allowedBarcodeTypes ?? supportedCodeFormats;

props.resetFocusTimeout = props.resetFocusTimeout ?? 0;
props.resetFocusWhenMotionDetected = props.resetFocusWhenMotionDetected ?? true;
// RN can't express optional int/float view props yet, so we default
// undefined -> -1 (and other sentinels). Build a NEW object instead of
// mutating `props`: React freezes element props in dev, so writing to them
// throws "Cannot add new property" once the module runs in strict mode
// (ES modules are always strict).
const transformedProps: CameraProps = {
...props,
zoom: props.zoom ?? -1,
maxZoom: props.maxZoom ?? -1,
scanThrottleDelay: props.scanThrottleDelay ?? -1,
faceDetectionThrottleMs: props.faceDetectionThrottleMs ?? -1,
iOsDeferredStart: props.iOsDeferredStart ?? true,
allowedBarcodeTypes: props.allowedBarcodeTypes ?? supportedCodeFormats,
resetFocusTimeout: props.resetFocusTimeout ?? 0,
resetFocusWhenMotionDetected: props.resetFocusWhenMotionDetected ?? true,
};

React.useImperativeHandle(ref, () => ({
capture: async () => {
Expand All @@ -35,7 +38,13 @@ const Camera = React.forwardRef<CameraApi, CameraProps>((props, ref) => {
}));

// @ts-expect-error props for codegen differ a bit from the user-facing ones
return <NativeCamera style={{ minWidth: 100, minHeight: 100 }} ref={nativeRef} {...props} />;
return (
<NativeCamera
style={{ minWidth: 100, minHeight: 100 }}
ref={nativeRef}
{...transformedProps}
/>
);
});

export default Camera;