Created
October 28, 2022 05:41
-
-
Save hasunpark/c1f9a466ba7286d3a12980cc10882311 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraView+EnableTorch.kt b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraView+EnableTorch.kt | |
new file mode 100644 | |
index 0000000..4057c33 | |
--- /dev/null | |
+++ b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraView+EnableTorch.kt | |
@@ -0,0 +1,9 @@ | |
+package com.mrousavy.camera | |
+ | |
+import kotlinx.coroutines.guava.await | |
+ | |
+suspend fun CameraView.enableTorch(status: Boolean){ | |
+ val cameraControl = camera?.cameraControl ?: throw CameraNotReadyError() | |
+ | |
+ cameraControl.enableTorch(status) | |
+} | |
\ No newline at end of file | |
diff --git a/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt | |
index 7672b15..e5e1a89 100644 | |
--- a/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt | |
+++ b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt | |
@@ -400,4 +400,15 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase | |
promise.reject("NO_ACTIVITY", "No PermissionAwareActivity was found! Make sure the app has launched before calling this function.") | |
} | |
} | |
+ | |
+ @ReactMethod | |
+ fun enableTorch(viewTag: Int,status:Boolean, promise: Promise){ | |
+ coroutineScope.launch{ | |
+ withPromise(promise){ | |
+ val view = findCameraView(viewTag) | |
+ view.enableTorch(status) | |
+ return@withPromise null | |
+ } | |
+ } | |
+ } | |
} | |
diff --git a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h | |
index a2ccdcb..597691c 100644 | |
--- a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h | |
+++ b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h | |
@@ -53,7 +53,7 @@ objc_name : NSObject<FrameProcessorPluginBase> | |
@end \ | |
@implementation objc_name (FrameProcessorPlugin) \ | |
\ | |
-__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() \ | |
++(void)load \ | |
{ \ | |
[FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) { \ | |
return [objc_name callback:frame withArgs:args]; \ | |
diff --git a/node_modules/react-native-vision-camera/src/Camera.tsx b/node_modules/react-native-vision-camera/src/Camera.tsx | |
index 68417ac..fbfeb64 100644 | |
--- a/node_modules/react-native-vision-camera/src/Camera.tsx | |
+++ b/node_modules/react-native-vision-camera/src/Camera.tsx | |
@@ -293,6 +293,19 @@ export class Camera extends React.PureComponent<CameraProps> { | |
throw tryParseNativeCameraError(e); | |
} | |
} | |
+ | |
+ /** | |
+ * Control the cameras torch by given status. | |
+ * @param {Boolean} status | |
+ */ | |
+ public async enableTorch(status: Boolean): Promise<void> { | |
+ try{ | |
+ return await CameraModule.enableTorch(this.handle,status) | |
+ } catch (e){ | |
+ throw tryParseNativeCameraError(e) | |
+ } | |
+ } | |
+ | |
//#endregion | |
/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment