fix: Initialize Plugins in a static block of ReactPackage (#2039)

* fix: Initialize Plugins in a `static` block of ReactPackage

* fix: Also register FP Plugins in Example
This commit is contained in:
Marc Rousavy 2023-10-19 11:34:09 +02:00 committed by GitHub
parent 07027d8010
commit 3929c0ac46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -88,7 +88,7 @@ import com.mrousavy.camera.frameprocessor.FrameProcessorPluginRegistry;
public class FaceDetectorFrameProcessorPluginPackage implements ReactPackage {
// highlight-start
FaceDetectorFrameProcessorPluginPackage() {
static {
FrameProcessorPluginRegistry.addFrameProcessorPlugin("detectFaces", options -> new FaceDetectorFrameProcessorPlugin(options));
}
// highlight-end
@ -158,11 +158,13 @@ import com.mrousavy.camera.frameprocessor.FrameProcessorPlugin
class FaceDetectorFrameProcessorPluginPackage : ReactPackage {
// highlight-start
companion object {
init {
FrameProcessorPluginRegistry.addFrameProcessorPlugin("detectFaces") { options ->
FaceDetectorFrameProcessorPlugin(options)
}
}
}
// highlight-end
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {

View File

@ -18,6 +18,11 @@ import com.mrousavy.camera.frameprocessor.FrameProcessorPlugin;
import com.mrousavy.camera.frameprocessor.FrameProcessorPluginRegistry;
public class MainApplication extends Application implements ReactApplication {
// Register the Frame Processor Plugins for our app
static {
FrameProcessorPluginRegistry.addFrameProcessorPlugin("example_plugin", options -> new ExampleFrameProcessorPlugin(options));
FrameProcessorPluginRegistry.addFrameProcessorPlugin("example_kotlin_swift_plugin", options -> new ExampleKotlinFrameProcessorPlugin(options));
}
private final ReactNativeHost mReactNativeHost =
new DefaultReactNativeHost(this) {
@ -64,8 +69,5 @@ public class MainApplication extends Application implements ReactApplication {
// If you opted-in for the New Architecture, we load the native entry point for this app.
DefaultNewArchitectureEntryPoint.load();
}
FrameProcessorPluginRegistry.addFrameProcessorPlugin("example_plugin", options -> new ExampleFrameProcessorPlugin(options));
FrameProcessorPluginRegistry.addFrameProcessorPlugin("example_kotlin_swift_plugin", options -> new ExampleKotlinFrameProcessorPlugin(options));
}
}