Skip to content

Commit 335566e

Browse files
author
farfromrefug
committed
feat: added minZoom and maxZoom readonly properties
1 parent 8d6cbe9 commit 335566e

File tree

6 files changed

+62
-9
lines changed

6 files changed

+62
-9
lines changed

packages/ui-cameraview/platforms/ios/src/NSCameraView.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
107107
}
108108
}
109109

110+
public var lensPosition: Float {
111+
get {
112+
return self.nextLevel?.lensPosition
113+
}
114+
set {
115+
self.nextLevel?.lensPosition = newValue
116+
}
117+
}
118+
110119
func commonInit() {
111120
self.autoresizingMask = [.flexibleWidth, .flexibleHeight]
112121
self.backgroundColor = UIColor.black
@@ -433,3 +442,19 @@ extension UIDeviceOrientation {
433442
}
434443
}
435444
}
445+
446+
extension NextLevel {
447+
448+
public var minVideoZoomFactor: Float {
449+
if let device = self._currentDevice {
450+
return minAvailableVideoZoomFactor
451+
}
452+
return 1.0
453+
}
454+
public var maxVideoZoomFactor: Float {
455+
if let device = self._currentDevice {
456+
return maxAvailableVideoZoomFactor
457+
}
458+
return 1.0
459+
}
460+
}

src/ui-cameraview/index.android.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,38 +60,52 @@ export class CameraView extends CameraViewBase {
6060
this.nativeViewProtected?.setAnalyserCallback(this._processor);
6161
}
6262

63+
get minZoom() {
64+
return this.nativeViewProtected?.getMinZoom();
65+
}
66+
get maxZoom() {
67+
return this.nativeViewProtected?.getMaxZoom();
68+
}
69+
6370
initNativeView() {
6471
super.initNativeView();
6572
const nativeView = this.nativeViewProtected;
6673
nativeView['refreshCameraDelay'] = this.refreshCameraDelay;
6774

75+
const that = new WeakRef(this);
6876
const listener = (this.listener = new com.nativescript.cameraview.CameraEventListener({
6977
onReady() {},
7078
onCameraOpen: () => {
71-
this.notify({ eventName: 'cameraOpen' });
79+
that?.get()?.notify({ eventName: 'cameraOpen' });
7280
},
7381
onCameraVideo(param0) {},
7482
onCameraAnalysis(param0) {},
7583
onCameraVideoStart() {},
7684
onZoom: (zoom: number) => {
77-
this.notify({ eventName: 'zoom', zoom });
85+
that?.get()?.notify({ eventName: 'zoom', zoom });
7886
},
7987
onCameraError: (param0: string, error) => {
80-
this.photoListeners?.forEach((c) => c.onCameraError(param0, error));
88+
that?.get()?.photoListeners?.forEach((c) => c.onCameraError(param0, error));
8189
},
8290
onCameraClose: () => {
83-
this.notify({ eventName: 'cameraClose' });
84-
this.photoListeners?.forEach((c) => c.onCameraClose());
91+
const owner = that?.get();
92+
if (owner) {
93+
owner.notify({ eventName: 'cameraClose' });
94+
owner.photoListeners?.forEach((c) => c.onCameraClose());
95+
}
8596
},
8697
onCameraPhoto: (file: android.net.Uri) => {
87-
const result = file.toString();
88-
this.photoListeners?.forEach((c) => c.onCameraPhoto(result));
98+
const owner = that?.get();
99+
if (owner) {
100+
const result = file.toString();
101+
this.photoListeners?.forEach((c) => c.onCameraPhoto(result));
102+
}
89103
},
90104
onCameraPhotoImage: (image, info) => {
91-
this.photoListeners?.forEach((c) => c.onCameraPhotoImage(image, info));
105+
that?.get()?.photoListeners?.forEach((c) => c.onCameraPhotoImage(image, info));
92106
},
93107
onCameraPhotoImageProxy: (image, processor) => {
94-
this.photoListeners?.forEach((c) => c.onCameraPhotoImageProxy(image, processor));
108+
that?.get()?.photoListeners?.forEach((c) => c.onCameraPhotoImageProxy(image, processor));
95109
}
96110
}));
97111
nativeView.setListener(listener);

src/ui-cameraview/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export class CameraView extends GridLayout {
2626
captureMode?: number;
2727
pictureSize?: { width: number; height: number };
2828
jpegQuality?: number;
29+
readonly minZoom: number;
30+
readonly maxZoom: number;
2931
stopPreview();
3032
startPreview();
3133
toggleCamera();

src/ui-cameraview/index.ios.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ export class CameraView extends CameraViewBase {
162162
}
163163
}
164164

165+
get minZoom() {
166+
return this.nativeViewProtected?.minVideoZoomFactor;
167+
}
168+
get maxZoom() {
169+
return this.nativeViewProtected?.maxVideoZoomFactor;
170+
}
171+
165172
public addEventListener(arg: string, callback: any, thisArg?: any) {
166173
super.addEventListener(arg, callback, thisArg);
167174

src/ui-cameraview/typings/android.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ declare namespace com {
321321
public getAmplitude(): number;
322322
public getMaxVideoFrameRate(): number;
323323
public getPictureSize(): string;
324+
public getMaxZoom(): number;
325+
public getMinZoom(): number;
324326
public getSaveToGallery(): boolean;
325327
public getMaxVideoBitrate(): number;
326328
public getAvailablePictureSizes(param0: string): androidNative.Array<Size>;

src/ui-cameraview/typings/ios.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ declare class NSCameraView extends UIView {
2020

2121
readonly canCaptureVideo: boolean;
2222

23+
readonly minVideoZoomFactor: number;
24+
readonly maxVideoZoomFactor: number;
25+
2326
flashMode: number;
2427
focusMode: number;
2528

0 commit comments

Comments
 (0)