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
Binary file modified package/harmony/vision_camera.har
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class VisionCameraViewJSIBinder : public ViewComponentJSIBinder {
object.setProperty(rt, "enableZoomGesture", true);
object.setProperty(rt, "exposure", true);
object.setProperty(rt, "zoom", true);
object.setProperty(rt, "isMirror", true);
object.setProperty(rt, "audio", true);
object.setProperty(rt, "video", true);
object.setProperty(rt, "torch", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ export struct VisionCameraView {
})
.onLoad(() => {
this.surfaceId = this.mXComponentController.getXComponentSurfaceId();
let surfaceRotaion: SurfaceRotationOptions = {lock: true};
this.mXComponentController.setXComponentSurfaceRotation(surfaceRotaion);
})
.width(this.cameraState === cameraState.SCAN ? this.localDisplayWidth + 'px' : this.componentWidth + 'px')
.height(this.cameraState === cameraState.SCAN ? this.localDisplayHeight + 'px' :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const TAG: string = 'RNCameraSession'
type ZoomRangeType = [number, number];

export default class CameraSession {
private isMirror: boolean = false;
private position: string = 'back';
context: Context = undefined;
phAccessHelper: photoAccessHelper.PhotoAccessHelper = undefined;
private cameraManager?: camera.CameraManager;
Expand Down Expand Up @@ -71,7 +73,7 @@ export default class CameraSession {
public previewProfile: camera.Profile = {} as camera.Profile;
private photoCaptureSetting: camera.PhotoCaptureSetting = {
rotation: camera.ImageRotation.ROTATION_0,
mirror: false,
mirror: this.isMirror,
quality: camera.QualityLevel.QUALITY_LEVEL_MEDIUM,
};
private videoStartParams: RecordVideoOptions = {
Expand Down Expand Up @@ -141,6 +143,7 @@ export default class CameraSession {
}
await this.cameraRelease();
Logger.info(TAG, `changeCameraPosition: ${JSON.stringify(props.device?.position)}`);
this.position = props.device?.position;
this.cameraManager = this.getCameraManagerFn();
this.initCamera(surfaceId, props, mediaModel)
}
Expand Down Expand Up @@ -197,6 +200,10 @@ export default class CameraSession {
* 初始化props参数
*/
async initProps(props) {
this.position = props.device?.position;
if (props.isMirror !== undefined && props.device?.position !== undefined) {
this.setMirror(props.isMirror, props.device?.position);
}
if (props.exposure !== undefined) {
this.setExposure(props.exposure);
}
Expand All @@ -217,6 +224,14 @@ export default class CameraSession {
}
}

setMirror(isMirror, position) {
if ('front' === position) {
this.photoCaptureSetting.mirror = !isMirror;
} else {
this.photoCaptureSetting.mirror = isMirror;
}
}

async initVideoSession(currentDevice: camera.CameraDevice, surfaceId: string, props: VisionCameraViewSpec.RawProps) {
this.setAudio(props.audio)

Expand Down Expand Up @@ -446,7 +461,7 @@ export default class CameraSession {
videoBitRate = this.getBitRateMultiplier(options.videoBitRate)
}

let fps = props.fps || 30;
let fps = props.fps | 30;
let { min:minFps, max:maxFps } = this.videoProfile.frameRateRange;
if (fps > maxFps) {
fps = maxFps;
Expand Down
5 changes: 5 additions & 0 deletions package/harmony/vision_camera/src/main/module.json5
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"name": "ohos.permission.APPROXIMATELY_LOCATION",
"reason": "$string:location_reason",
"usedScene": {}
},
{
"name": "ohos.permission.GYROSCOPE",
"reason": "$string:location_reason",
"usedScene": {}
}
]
}
Expand Down
1 change: 1 addition & 0 deletions package/src/NativeVisionCameraView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ interface CodeScanner {
export interface NativeVisionCameraProps extends ViewProps {
codeScanner?: CodeScanner;
fps?: WithDefault<Int32, 30>;
isMirror: boolean;
videoHdr?: WithDefault<boolean, false>;
isActive: boolean;
preview?: WithDefault<boolean, true>;
Expand Down
2 changes: 2 additions & 0 deletions package/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const Camera = forwardRef<VisionCameraRef, VisionCameraProps>(
style,
device,
isActive,
isMirror,
preview,
resizeMode,
fps,
Expand Down Expand Up @@ -459,6 +460,7 @@ export const Camera = forwardRef<VisionCameraRef, VisionCameraProps>(
ref={VisionCameraRef}
style={StyleSheet.absoluteFill}
codeScanner={codeScanner}
isMirror={isMirror}
fps={fps}
videoHdr={videoHdr}
isActive={isActive}
Expand Down
1 change: 1 addition & 0 deletions package/src/types/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface VisionCameraProps extends ViewProps {
device: CameraDevice
isActive: boolean
preview?: boolean
isMirror: boolean
video?: boolean
audio?: boolean
torch?: 'off' | 'on'
Expand Down