Skip to content

Commit

Permalink
rename method to switchCameraTo
Browse files Browse the repository at this point in the history
  • Loading branch information
parveshneedhoo committed Apr 2, 2024
1 parent a2e45c5 commit 4ba0eda
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/android/CameraPreviewFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public void setLocation(Location loc) {
}


public void switchToUltraWideCamera(String device, CameraSwitchedCallback cameraSwitchedCallback) {
public void switchCameraTo(String device, CameraSwitchedCallback cameraSwitchedCallback) {
Handler mainHandler = new Handler(Looper.getMainLooper());
mainHandler.post(new Runnable() {
@SuppressLint("RestrictedApi")
Expand Down
8 changes: 4 additions & 4 deletions src/android/SimpleCameraPreview.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
case "deviceHasUltraWideCamera":
return deviceHasUltraWideCamera(callbackContext);

case "switchToUltraWideCamera":
return switchToUltraWideCamera(args.getString(0), callbackContext);
case "switchCameraTo":
return switchCameraTo(args.getString(0), callbackContext);
default:
break;
}
Expand Down Expand Up @@ -337,13 +337,13 @@ public void run() {
}
}

private boolean switchToUltraWideCamera(String device, CallbackContext callbackContext) {
private boolean switchCameraTo(String device, CallbackContext callbackContext) {
if (fragment == null) {
callbackContext.error("Camera is closed, cannot switch camera");
return true;
}

fragment.switchToUltraWideCamera(device, (boolean result) -> {
fragment.switchCameraTo(device, (boolean result) -> {
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result);
callbackContext.sendPluginResult(pluginResult);
});
Expand Down
2 changes: 1 addition & 1 deletion src/ios/CameraSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- (void) setupSession:(NSString *)defaultCamera completion:(void(^)(BOOL started))completion options:(NSDictionary *)options photoSettings:(AVCapturePhotoSettings *)photoSettings;
- (void) setFlashMode:(NSInteger)flashMode photoSettings:(AVCapturePhotoSettings *)photoSettings;
- (void) torchSwitch:(NSInteger)torchState;
- (void) switchToUltraWideCamera:(NSString *)cameraMode completion:(void (^)(BOOL success))completion;
- (void) switchCameraTo:(NSString *)cameraMode completion:(void (^)(BOOL success))completion;
- (BOOL) deviceHasUltraWideCamera;
- (void) updateOrientation:(AVCaptureVideoOrientation)orientation;
- (AVCaptureVideoOrientation) getCurrentOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
Expand Down
4 changes: 1 addition & 3 deletions src/ios/CameraSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ - (void) torchSwitch:(NSInteger)torchState{
}
}

- (void)switchToUltraWideCamera:(NSString*)cameraMode completion:(void (^)(BOOL success))completion {
- (void)switchCameraTo:(NSString*)cameraMode completion:(void (^)(BOOL success))completion {
if (![self deviceHasUltraWideCamera]) {
if (completion) {
completion(NO);
Expand Down Expand Up @@ -221,8 +221,6 @@ - (void)switchToUltraWideCamera:(NSString*)cameraMode completion:(void (^)(BOOL
} else {
NSLog(@"Ultra-wide camera not found");
}
} else {
// Fallback on earlier versions
}

completion ? completion(cameraSwitched): NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/ios/SimpleCameraPreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- (void) capture:(CDVInvokedUrlCommand*)command;
- (void) setSize:(CDVInvokedUrlCommand*)command;
- (void) torchSwitch: (CDVInvokedUrlCommand*)command;
- (void) switchToUltraWideCamera: (CDVInvokedUrlCommand*) command;
- (void) switchCameraTo: (CDVInvokedUrlCommand*) command;
- (void) deviceHasUltraWideCamera: (CDVInvokedUrlCommand*) command;
- (void) deviceHasFlash: (CDVInvokedUrlCommand*)command;
@property (nonatomic) CameraSessionManager *sessionManager;
Expand Down
4 changes: 2 additions & 2 deletions src/ios/SimpleCameraPreview.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ - (void) torchSwitch:(CDVInvokedUrlCommand*)command{
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void) switchToUltraWideCamera:(CDVInvokedUrlCommand*)command{
- (void) switchCameraTo:(CDVInvokedUrlCommand*)command{
NSString *device = [command.arguments objectAtIndex:0];
BOOL cameraSwitched = FALSE;
if (self.sessionManager != nil) {
[self.sessionManager switchToUltraWideCamera: device completion:^(BOOL success) {
[self.sessionManager switchCameraTo: device completion:^(BOOL success) {
if (success) {
NSLog(@"Camera switched successfully");
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:TRUE];
Expand Down
4 changes: 2 additions & 2 deletions www/SimpleCameraPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ SimpleCameraPreview.torchSwitch = function (options, onSuccess, onError) {
exec(onSuccess, onError, PLUGIN_NAME, "torchSwitch", [options]);
};

SimpleCameraPreview.switchToUltraWideCamera = function (options, onSuccess, onError) {
SimpleCameraPreview.switchCameraTo = function (options, onSuccess, onError) {
options = options || {};
options.captureDevice = options.captureDevice || "default";
exec(onSuccess, onError, PLUGIN_NAME, "switchToUltraWideCamera", [options.captureDevice]);
exec(onSuccess, onError, PLUGIN_NAME, "switchCameraTo", [options.captureDevice]);
};

SimpleCameraPreview.deviceHasFlash = function (onSuccess, onError) {
Expand Down

0 comments on commit 4ba0eda

Please sign in to comment.