Skip to content

Commit

Permalink
keep a manual copy of codegen files to avoid:
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Oct 28, 2024
1 parent 9ca50be commit 9a0c029
Show file tree
Hide file tree
Showing 15 changed files with 855 additions and 29 deletions.
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,7 @@ SPEC CHECKSUMS:
RNStaticSafeAreaInsets: 055ddbf5e476321720457cdaeec0ff2ba40ec1b8
RNVectorIcons: 07792a9538e8577c1263fcad187712e90d65d8fb
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
VisionCamera: fbe4f8de9a7243d5986d12a447b16d5528eb9a90
VisionCamera: fa7ea32339d6c29bb43774e38d2d00a75075b37b
Yoga: aa3df615739504eebb91925fc9c58b4922ea9a08

PODFILE CHECKSUM: f0198d9eea1d44be2bb929d80d6bfc9ddeae8414
Expand Down
19 changes: 1 addition & 18 deletions package/VisionCamera.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Pod::Spec.new do |s|
# VisionCamera React-specific Swift codebase
react.source_files = [
"ios/React/**/*.swift",
"ios/React/**/*.{h,m,mm}",
"ios/React/**/*.{h,m,mm,cpp}",
]
react.public_header_files = [
"ios/React/CameraBridge.h"
Expand Down Expand Up @@ -121,21 +121,4 @@ Pod::Spec.new do |s|
fp.dependency "react-native-worklets-core"
end
end

if $new_arch_enabled
# There is a bug in codegen where it generates broken code, this is a workaround
# https://github.com/facebook/react-native/issues/47113
UI.puts "[VisionCamera] RCT_NEW_ARCH_ENABLED is enabled, adding workaround for EventEmitters"
root_dir = Pod::Config.instance.installation_root
target_file = Dir.glob("#{root_dir}/**/RNVisionCameraSpec/EventEmitters.cpp").first

if target_file
content = File.read(target_file)
new_content = content.gsub("codesValue,frame.", "codesValue.frame.")
File.write(target_file, new_content)
UI.puts "[VisionCamera] Modified file: #{target_file}"
else
UI.puts "[VisionCamera] Warning: EventEmitters.cpp not found in any RNVisionCameraSpec directory"
end
end
end
11 changes: 9 additions & 2 deletions package/ios/React/Fabric/CameraViewNativeComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

#import "CameraViewNativeComponent.h"

#include <react/renderer/components/RNVisionCameraSpec/ComponentDescriptors.h>
#include <react/renderer/components/RNVisionCameraSpec/RCTComponentViewHelpers.h>
#include "ComponentDescriptors.h"
#include "RCTComponentViewHelpers.h"

#import "RCTFabricComponentsPlugins.h"
#import <React/RCTConversions.h>
#import <React/RCTComponentViewFactory.h>

#import <AVFoundation/AVFoundation.h>
#if __has_include(<VisionCamera/VisionCamera-Swift.h>)
Expand All @@ -33,6 +34,12 @@ + (ComponentDescriptorProvider)componentDescriptorProvider {
return concreteComponentDescriptorProvider<CameraViewComponentDescriptor>();
}

// Load the component manually into the global fabric view registry.
// TODO: Remove once https://github.com/facebook/react-native/issues/47113 is fixed and we can rely fully on codegen
+ (void)load {
[RCTComponentViewFactory.currentComponentViewFactory registerComponentViewClass:[CameraViewNativeComponent class]];
}

- (void)initCamera {
static const auto defaultProps = std::make_shared<const CameraViewProps>();
_props = defaultProps;
Expand Down
22 changes: 22 additions & 0 deletions package/ios/React/Fabric/ComponentDescriptors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateComponentDescriptorCpp.js
*/

#include "ComponentDescriptors.h"
#include <react/renderer/core/ConcreteComponentDescriptor.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>

namespace facebook::react {

void RNVisionCameraSpec_registerComponentDescriptorsFromCodegen(
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry) {
registry->add(concreteComponentDescriptorProvider<CameraViewComponentDescriptor>());
}

} // namespace facebook::react
24 changes: 24 additions & 0 deletions package/ios/React/Fabric/ComponentDescriptors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateComponentDescriptorH.js
*/

#pragma once

#include "ShadowNodes.h"
#include <react/renderer/core/ConcreteComponentDescriptor.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>

namespace facebook::react {

using CameraViewComponentDescriptor = ConcreteComponentDescriptor<CameraViewShadowNode>;

void RNVisionCameraSpec_registerComponentDescriptorsFromCodegen(
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry);

} // namespace facebook::react
168 changes: 168 additions & 0 deletions package/ios/React/Fabric/EventEmitters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateEventEmitterCpp.js
*/

#include "EventEmitters.h"


namespace facebook::react {

void CameraViewEventEmitter::onViewReady(OnViewReady $event) const {
dispatchEvent("viewReady", [](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);

return $payload;
});
}


void CameraViewEventEmitter::onAverageFpsChanged(OnAverageFpsChanged $event) const {
dispatchEvent("averageFpsChanged", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, "averageFps", $event.averageFps);
return $payload;
});
}


void CameraViewEventEmitter::onInitialized(OnInitialized $event) const {
dispatchEvent("initialized", [](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);

return $payload;
});
}


void CameraViewEventEmitter::onError(OnError $event) const {
dispatchEvent("error", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, "code", $event.code);
$payload.setProperty(runtime, "message", $event.message);
{
auto cause = jsi::Object(runtime);
cause.setProperty(runtime, "code", $event.cause.code);
cause.setProperty(runtime, "domain", $event.cause.domain);
cause.setProperty(runtime, "message", $event.cause.message);
cause.setProperty(runtime, "details", $event.cause.details);
cause.setProperty(runtime, "stacktrace", $event.cause.stacktrace);
$payload.setProperty(runtime, "cause", cause);
}
return $payload;
});
}


void CameraViewEventEmitter::onCodeScanned(OnCodeScanned $event) const {
dispatchEvent("codeScanned", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);

auto codes = jsi::Array(runtime, $event.codes.size());
size_t codesIndex = 0;
for (auto codesValue : $event.codes) {
auto codesObject = jsi::Object(runtime);
codesObject.setProperty(runtime, "type", codesValue.type);
codesObject.setProperty(runtime, "value", codesValue.value);
{
auto frame = jsi::Object(runtime);
frame.setProperty(runtime, "x", codesValue.frame.x);
frame.setProperty(runtime, "y", codesValue.frame.y);
frame.setProperty(runtime, "width", codesValue.frame.width);
frame.setProperty(runtime, "height", codesValue.frame.height);
codesObject.setProperty(runtime, "frame", frame);
}

auto corners = jsi::Array(runtime, codesValue.corners.size());
size_t cornersIndex = 0;
for (auto cornersValue : codesValue.corners) {
auto cornersObject = jsi::Object(runtime);
cornersObject.setProperty(runtime, "x", cornersValue.x);
cornersObject.setProperty(runtime, "y", cornersValue.y);
corners.setValueAtIndex(runtime, cornersIndex++, cornersObject);
}
codesObject.setProperty(runtime, "corners", corners);

codes.setValueAtIndex(runtime, codesIndex++, codesObject);
}
$payload.setProperty(runtime, "codes", codes);

{
auto frame = jsi::Object(runtime);
frame.setProperty(runtime, "width", $event.frame.width);
frame.setProperty(runtime, "height", $event.frame.height);
$payload.setProperty(runtime, "frame", frame);
}
return $payload;
});
}


void CameraViewEventEmitter::onStarted(OnStarted $event) const {
dispatchEvent("started", [](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);

return $payload;
});
}


void CameraViewEventEmitter::onStopped(OnStopped $event) const {
dispatchEvent("stopped", [](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);

return $payload;
});
}


void CameraViewEventEmitter::onPreviewStarted(OnPreviewStarted $event) const {
dispatchEvent("previewStarted", [](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);

return $payload;
});
}


void CameraViewEventEmitter::onPreviewStopped(OnPreviewStopped $event) const {
dispatchEvent("previewStopped", [](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);

return $payload;
});
}


void CameraViewEventEmitter::onShutter(OnShutter $event) const {
dispatchEvent("shutter", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, "type", $event.type);
return $payload;
});
}


void CameraViewEventEmitter::onOutputOrientationChanged(OnOutputOrientationChanged $event) const {
dispatchEvent("outputOrientationChanged", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, "outputOrientation", toString($event.outputOrientation));
return $payload;
});
}


void CameraViewEventEmitter::onPreviewOrientationChanged(OnPreviewOrientationChanged $event) const {
dispatchEvent("previewOrientationChanged", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, "previewOrientation", toString($event.previewOrientation));
return $payload;
});
}

} // namespace facebook::react
Loading

0 comments on commit 9a0c029

Please sign in to comment.