Skip to content

Commit 9a41d1c

Browse files
committed
Fixed SafeAreaView dummy support on iOS
Fixed zoom issue Fixed Fabric (new arch) compile issues on both platforms Fixed included broken codegen lib code Fixed broken .h import paths to avoid setting custom build settings Fixed potential memory issue by disabling view recycling Added Fabric (new arch) support for camera view component Added RN 0.81 for example Added RN 0.79 for main lib Added helper for re-running codegen Added gitignore for Android codegen making a podspec Added support for scanThrottleDelay on Android Added includesGeneratedCode to package.json to indicate changes Rewrote optional int props to use -1 instead due to RN bug Moved to Obj-C with C++ support (.mm) to avoid C++ compile issues
1 parent 4f376b5 commit 9a41d1c

File tree

76 files changed

+3875
-3144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3875
-3144
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,7 @@ dist/
8989
*.xcodeproj/*
9090
!*.xcodeproj/project.pbxproj
9191
!*.xcworkspace/contents.xcworkspacedata
92+
93+
### RN Codegen bug
94+
# There's no such thing as podspecs for Android, so ignore the generated file
95+
android/generated/ReactCodegen.podspec

ReactNativeCameraKit.podspec

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,22 @@ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
55
Pod::Spec.new do |s|
66
s.name = "ReactNativeCameraKit"
77
s.version = package["version"]
8-
s.summary = "A high performance, easy to use camera API"
8+
s.summary = package["description"]
99
s.license = "MIT"
1010

1111
s.authors = "CameraKit"
1212
s.homepage = "https://github.com/teslamotors/react-native-camera-kit"
13-
s.platform = :ios, "11.0"
13+
s.platform = :ios, "15.0"
1414

1515
s.source = { :git => "https://github.com/teslamotors/react-native-camera-kit.git", :tag => "v#{s.version}" }
16-
s.source_files = "ios/**/*.{h,m,mm,swift}"
17-
s.private_header_files = 'ios/ReactNativeCameraKit/ReactNativeCameraKit-Swift.pre.h'
16+
s.source_files = [
17+
# Exclude .h files as they cause Swift compiler to treat them as C files, but they are C++
18+
# See https://github.com/facebook/react-native/issues/45424#issuecomment-2354737063
19+
"ios/ReactNativeCameraKit/*.{m,swift,mm}",
20+
"ios/generated/rncamerakit_specs/*.{m,mm,cpp}",
21+
]
1822

19-
if ENV['USE_FRAMEWORKS']
20-
exisiting_flags = s.attributes_hash["compiler_flags"]
21-
if exisiting_flags.present?
22-
s.compiler_flags = exisiting_flags + "-DCK_USE_FRAMEWORKS=1"
23-
else
24-
s.compiler_flags = "-DCK_USE_FRAMEWORKS=1"
25-
end
26-
end
23+
s.private_header_files = 'ios/ReactNativeCameraKit/ReactNativeCameraKit-Swift.pre.h'
2724

2825
if defined?(install_modules_dependencies()) != nil
2926
install_modules_dependencies(s)

android/build.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ android {
3434
warning 'InvalidPackage'
3535
}
3636

37-
if (!isNewArchitectureEnabled()) {
38-
sourceSets {
39-
main {
40-
java.srcDirs += 'src/paper/java'
41-
}
37+
sourceSets {
38+
main {
39+
java.srcDirs += 'generated'
4240
}
4341
}
4442
}

android/src/paper/java/com/rncamerakit/NativeCameraKitModuleSpec.java renamed to android/generated/java/com/facebook/fbreact/specs/NativeCameraKitModuleSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @nolint
1111
*/
1212

13-
package com.rncamerakit;
13+
package com.facebook.fbreact.specs;
1414

1515
import com.facebook.proguard.annotations.DoNotStrip;
1616
import com.facebook.react.bridge.Promise;

android/src/paper/java/com/facebook/react/viewmanagers/CKCameraManagerDelegate.java renamed to android/generated/java/com/facebook/react/viewmanagers/CKCameraManagerDelegate.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public void setProperty(T view, String propName, @Nullable Object value) {
3737
mViewManager.setZoomMode(view, value == null ? null : (String) value);
3838
break;
3939
case "zoom":
40-
mViewManager.setZoom(view, value == null ? 0f : ((Double) value).doubleValue());
40+
mViewManager.setZoom(view, value == null ? -1f : ((Double) value).doubleValue());
4141
break;
4242
case "maxZoom":
43-
mViewManager.setMaxZoom(view, value == null ? 0f : ((Double) value).doubleValue());
43+
mViewManager.setMaxZoom(view, value == null ? -1f : ((Double) value).doubleValue());
4444
break;
4545
case "torchMode":
4646
mViewManager.setTorchMode(view, value == null ? null : (String) value);
@@ -67,7 +67,7 @@ public void setProperty(T view, String propName, @Nullable Object value) {
6767
mViewManager.setRatioOverlayColor(view, ColorPropConverter.getColor(value, view.getContext()));
6868
break;
6969
case "resetFocusTimeout":
70-
mViewManager.setResetFocusTimeout(view, value == null ? 0 : ((Double) value).intValue());
70+
mViewManager.setResetFocusTimeout(view, value == null ? -1 : ((Double) value).intValue());
7171
break;
7272
case "resetFocusWhenMotionDetected":
7373
mViewManager.setResetFocusWhenMotionDetected(view, value == null ? false : (boolean) value);
@@ -76,7 +76,7 @@ public void setProperty(T view, String propName, @Nullable Object value) {
7676
mViewManager.setResizeMode(view, value == null ? null : (String) value);
7777
break;
7878
case "scanThrottleDelay":
79-
mViewManager.setScanThrottleDelay(view, value == null ? 0 : ((Double) value).intValue());
79+
mViewManager.setScanThrottleDelay(view, value == null ? -1 : ((Double) value).intValue());
8080
break;
8181
case "barcodeFrameSize":
8282
mViewManager.setBarcodeFrameSize(view, (ReadableMap) value);
@@ -85,7 +85,7 @@ public void setProperty(T view, String propName, @Nullable Object value) {
8585
mViewManager.setShutterPhotoSound(view, value == null ? false : (boolean) value);
8686
break;
8787
case "shutterAnimationDuration":
88-
mViewManager.setShutterAnimationDuration(view, value == null ? 0 : ((Double) value).intValue());
88+
mViewManager.setShutterAnimationDuration(view, value == null ? -1 : ((Double) value).intValue());
8989
break;
9090
case "outputPath":
9191
mViewManager.setOutputPath(view, value == null ? null : (String) value);

android/src/paper/java/com/facebook/react/viewmanagers/CKCameraManagerInterface.java renamed to android/generated/java/com/facebook/react/viewmanagers/CKCameraManagerInterface.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import android.view.View;
1313
import androidx.annotation.Nullable;
1414
import com.facebook.react.bridge.ReadableMap;
15+
import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface;
1516

16-
public interface CKCameraManagerInterface<T extends View> {
17+
public interface CKCameraManagerInterface<T extends View> extends ViewManagerWithGeneratedInterface {
1718
void setFlashMode(T view, @Nullable String value);
1819
void setFocusMode(T view, @Nullable String value);
1920
void setMaxPhotoQualityPrioritization(T view, @Nullable String value);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
cmake_minimum_required(VERSION 3.13)
7+
set(CMAKE_VERBOSE_MAKEFILE on)
8+
9+
file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/rncamerakit_specs/*.cpp)
10+
11+
add_library(
12+
react_codegen_rncamerakit_specs
13+
OBJECT
14+
${react_codegen_SRCS}
15+
)
16+
17+
target_include_directories(react_codegen_rncamerakit_specs PUBLIC . react/renderer/components/rncamerakit_specs)
18+
19+
target_link_libraries(
20+
react_codegen_rncamerakit_specs
21+
fbjni
22+
jsi
23+
# We need to link different libraries based on whether we are building rncore or not, that's necessary
24+
# because we want to break a circular dependency between react_codegen_rncore and reactnative
25+
reactnative
26+
)
27+
28+
# Fix crash on startup on RN 0.81 or newer due to broken codegen (it always uses target_compile_options)
29+
# Do not commit the change where the if-statement is removed unless they fix Codegen
30+
# See https://github.com/software-mansion/react-native-screens/pull/3114/commits/b4d283c8fc65e36ec60726fd7513735ccc7e1fe9
31+
# See https://github.com/react-native-maps/react-native-maps/issues/5699
32+
# (commit https://github.com/react-native-maps/react-native-maps/commit/c587f30b8499b79a2266687c641bfed10b3ecc2c)
33+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 80)
34+
target_compile_reactnative_options(react_codegen_rncamerakit_specs PRIVATE)
35+
else()
36+
target_compile_options(
37+
react_codegen_rncamerakit_specs
38+
PRIVATE
39+
-DLOG_TAG=\"ReactNative\"
40+
-fexceptions
41+
-frtti
42+
-std=c++20
43+
-Wall
44+
)
45+
endif()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
/**
3+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4+
*
5+
* Do not edit this file as changes may cause incorrect behavior and will be lost
6+
* once the code is regenerated.
7+
*
8+
* @generated by codegen project: GenerateComponentDescriptorCpp.js
9+
*/
10+
11+
#include "ComponentDescriptors.h"
12+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
13+
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
14+
15+
namespace facebook::react {
16+
17+
void rncamerakit_specs_registerComponentDescriptorsFromCodegen(
18+
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry) {
19+
registry->add(concreteComponentDescriptorProvider<CKCameraComponentDescriptor>());
20+
}
21+
22+
} // namespace facebook::react
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
/**
3+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4+
*
5+
* Do not edit this file as changes may cause incorrect behavior and will be lost
6+
* once the code is regenerated.
7+
*
8+
* @generated by codegen project: GenerateComponentDescriptorH.js
9+
*/
10+
11+
#pragma once
12+
13+
#include "ShadowNodes.h"
14+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
15+
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
16+
17+
namespace facebook::react {
18+
19+
using CKCameraComponentDescriptor = ConcreteComponentDescriptor<CKCameraShadowNode>;
20+
21+
void rncamerakit_specs_registerComponentDescriptorsFromCodegen(
22+
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry);
23+
24+
} // namespace facebook::react
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
/**
3+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4+
*
5+
* Do not edit this file as changes may cause incorrect behavior and will be lost
6+
* once the code is regenerated.
7+
*
8+
* @generated by codegen project: GenerateEventEmitterCpp.js
9+
*/
10+
11+
#include "EventEmitters.h"
12+
13+
14+
namespace facebook::react {
15+
16+
void CKCameraEventEmitter::onOrientationChange(OnOrientationChange $event) const {
17+
dispatchEvent("orientationChange", [$event=std::move($event)](jsi::Runtime &runtime) {
18+
auto $payload = jsi::Object(runtime);
19+
$payload.setProperty(runtime, "orientation", $event.orientation);
20+
return $payload;
21+
});
22+
}
23+
24+
25+
void CKCameraEventEmitter::onZoom(OnZoom $event) const {
26+
dispatchEvent("zoom", [$event=std::move($event)](jsi::Runtime &runtime) {
27+
auto $payload = jsi::Object(runtime);
28+
$payload.setProperty(runtime, "zoom", $event.zoom);
29+
return $payload;
30+
});
31+
}
32+
33+
34+
void CKCameraEventEmitter::onError(OnError $event) const {
35+
dispatchEvent("error", [$event=std::move($event)](jsi::Runtime &runtime) {
36+
auto $payload = jsi::Object(runtime);
37+
$payload.setProperty(runtime, "errorMessage", $event.errorMessage);
38+
return $payload;
39+
});
40+
}
41+
42+
43+
void CKCameraEventEmitter::onReadCode(OnReadCode $event) const {
44+
dispatchEvent("readCode", [$event=std::move($event)](jsi::Runtime &runtime) {
45+
auto $payload = jsi::Object(runtime);
46+
$payload.setProperty(runtime, "codeStringValue", $event.codeStringValue);
47+
$payload.setProperty(runtime, "codeFormat", $event.codeFormat);
48+
return $payload;
49+
});
50+
}
51+
52+
53+
void CKCameraEventEmitter::onCaptureButtonPressIn(OnCaptureButtonPressIn $event) const {
54+
dispatchEvent("captureButtonPressIn", [](jsi::Runtime &runtime) {
55+
auto $payload = jsi::Object(runtime);
56+
57+
return $payload;
58+
});
59+
}
60+
61+
62+
void CKCameraEventEmitter::onCaptureButtonPressOut(OnCaptureButtonPressOut $event) const {
63+
dispatchEvent("captureButtonPressOut", [](jsi::Runtime &runtime) {
64+
auto $payload = jsi::Object(runtime);
65+
66+
return $payload;
67+
});
68+
}
69+
70+
71+
void CKCameraEventEmitter::onPictureTaken(OnPictureTaken $event) const {
72+
dispatchEvent("pictureTaken", [$event=std::move($event)](jsi::Runtime &runtime) {
73+
auto $payload = jsi::Object(runtime);
74+
$payload.setProperty(runtime, "uri", $event.uri);
75+
return $payload;
76+
});
77+
}
78+
79+
} // namespace facebook::react

0 commit comments

Comments
 (0)