Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fix some syntax error #323

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ public void captureSample(PluginCall call) {
fragment.takeSnapshot(quality);
}

@PluginMethod
public void focusPoint(PluginCall call){
if (this.hasCamera(call) == false) {
call.reject("Camera is not running");
return;
}
Logger.debug("x:"+call.getInt("x"));
Logger.debug("y:"+call.getInt("y"));
fragment.setFocusArea(call.getInt("x"), call.getInt("y"), new Camera.AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
if (success) {
Logger.debug("onTouch:" + " setFocusArea() succeeded");
} else {
Logger.debug("onTouch:" + " setFocusArea() did not suceed");
}
}
});
}

@PluginMethod
public void stop(final PluginCall call) {
bridge
Expand Down
16 changes: 16 additions & 0 deletions ios/Plugin/CameraController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ extension CameraController {
self.sampleBufferCaptureCompletionBlock = completion
}

func focusPoint(x: Int, y: Int) throws{
guard let device = self.currentCameraPosition == .rear ? rearCamera : frontCamera else { return }
do {
try device.lockForConfiguration()
let focusMode = AVCaptureDevice.FocusMode.continuousAutoFocus
if device.isFocusPointOfInterestSupported && device.isFocusModeSupported(focusMode) {
device.focusMode = AVCaptureDevice.FocusMode.locked;
device.focusPointOfInterest = CGPoint(x: CGFloat(x), y: CGFloat(y))
device.focusMode = AVCaptureDevice.FocusMode.continuousAutoFocus;
}
device.unlockForConfiguration()
} catch {
debugPrint(error)
}
}

func getSupportedFlashModes() throws -> [String] {
var currentCamera: AVCaptureDevice?
switch currentCameraPosition {
Expand Down
1 change: 1 addition & 0 deletions ios/Plugin/Plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
CAP_PLUGIN_METHOD(setFlashMode, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(startRecordVideo, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(stopRecordVideo, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(focusPoint, CAPPluginReturnPromise);
)
18 changes: 18 additions & 0 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,22 @@ public class CameraPreview: CAPPlugin {
}
}

@objc func focusPoint(_ call: CAPPluginCall){
guard let x = call.getInt("x") else{
call.reject("failed to set focuspoint, x is missing")
return
}

guard let y = call.getInt("y") else{
call.reject("failed to set focuspoint, x is missing")
return
}
do {
try self.cameraController.focusPoint(x: x, y: y)
call.resolve()
} catch {
call.reject("failed to set focus")
}
}

}
6 changes: 6 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ export interface CameraPreviewPlugin {
setFlashMode(options: { flashMode: CameraPreviewFlashMode | string }): Promise<void>;
flip(): Promise<void>;
setOpacity(options: CameraOpacityOptions): Promise<{}>;
focusPoint(options: CameraPreviewXY): void;
}

export interface CameraPreviewXY {
x?: number,
y?: number,
}
3 changes: 3 additions & 0 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
platforms: ['web'],
});
}
focusPoint(): void {
throw new Error('Method not implemented.');
}

async start(options: CameraPreviewOptions): Promise<{}> {
return new Promise(async (resolve, reject) => {
Expand Down