diff --git a/ios/RNUsercentricsModule+TurboModule.mm b/ios/RNUsercentricsModule+TurboModule.mm new file mode 100644 index 0000000..96f6020 --- /dev/null +++ b/ios/RNUsercentricsModule+TurboModule.mm @@ -0,0 +1,34 @@ +// +// RNUsercentricsModule+TurboModule.mm +// getTurboModule: implementation for RN 0.78+ (New Architecture). +// RCTTurboModule protocol requires C++ return type (shared_ptr), hence Obj-C++. +// + +#import + +#if RCT_NEW_ARCH_ENABLED + +#import + +// Header generated by the app's codegen (ReactCodegen pod; path may vary by RN version) +#if __has_include() +#import +#else +#import "RNUsercentricsModule/RNUsercentricsModule.h" +#endif + +// RNUsercentricsModule is defined in Swift (RNUsercentricsModule.swift). +// Minimal declaration so the compiler accepts the category; the real implementation is in Swift. +@interface RNUsercentricsModule : NSObject +@end + +@implementation RNUsercentricsModule (TurboModule) + +- (std::shared_ptr)getTurboModule: + (const facebook::react::ObjCTurboModule::InitParams &)params { + return std::make_shared(params); +} + +@end + +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/RNUsercentricsModule.swift b/ios/RNUsercentricsModule.swift index 359e38c..5794cc3 100644 --- a/ios/RNUsercentricsModule.swift +++ b/ios/RNUsercentricsModule.swift @@ -5,12 +5,14 @@ import UIKit import React #if RCT_NEW_ARCH_ENABLED -#if canImport(RNUsercentricsModuleSpec) +#if canImport(ReactCodegen) +// RN ≥ 0.79: getTurboModule: implemented in RNUsercentricsModule+TurboModule.mm (do not import ReactCodegen in Swift — C++ module) +#elseif canImport(React_Codegen) +// RN 0.78 +import React_Codegen +#elseif canImport(RNUsercentricsModuleSpec) // RN ≤ 0.77 import RNUsercentricsModuleSpec -#else -// RN ≥ 0.78 -import React_Codegen #endif #endif @@ -229,13 +231,21 @@ class RNUsercentricsModule: NSObject { // MARK: - RCTBridgeModule & TurboModule Conformance #if RCT_NEW_ARCH_ENABLED +#if canImport(React_Codegen) +// RN 0.78: codegen-generated protocol +extension RNUsercentricsModule: NativeUsercentricsModuleSpec { + func getTurboModule(jsInvoker: RCTJSInvoker) -> Any { + return self + } +} +#elseif canImport(RNUsercentricsModuleSpec) +// RN ≤ 0.77 extension RNUsercentricsModule: NativeUsercentricsSpec { func getTurboModule(jsInvoker: RCTJSInvoker) -> Any { return self } } +#endif #else -extension RNUsercentricsModule: RCTBridgeModule { - -} +extension RNUsercentricsModule: RCTBridgeModule {} #endif diff --git a/react-native-usercentrics.podspec b/react-native-usercentrics.podspec index 06c6de0..690e394 100644 --- a/react-native-usercentrics.podspec +++ b/react-native-usercentrics.podspec @@ -12,7 +12,6 @@ Pod::Spec.new do |s| s.homepage = package['homepage'] s.platform = :ios, "11.0" - # Use apenas o path local para desenvolvimento s.source = { :path => '.' } s.source_files = 'ios/**/*.{h,m,mm,swift}' @@ -21,9 +20,12 @@ Pod::Spec.new do |s| s.dependency 'React-NativeModulesApple' s.dependency 'UsercentricsUI', "#{package['iosPackageVersion']}" - # Base C++ configuration - # Note: RCT_NEW_ARCH_ENABLED is inherited from parent project build settings - # This ensures compatibility with Expo's prebuild process + # Required for TurboModules RN 0.78+: injects codegen dependencies (ReactCodegen, etc.) + if defined?(install_modules_dependencies) + install_modules_dependencies(s) + end + + # C++ configuration (compatible with Expo prebuild and New Architecture) base_cpp_flags = { 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++20', 'CLANG_CXX_LIBRARY' => 'libc++', @@ -50,14 +52,6 @@ Pod::Spec.new do |s| '$(PODS_ROOT)/Headers/Public/ReactCommon' ] - # Add new architecture paths if available (will be resolved at build time) - header_search_paths += [ - '$(PODS_ROOT)/Headers/Public/React-Fabric', - '$(PODS_ROOT)/Headers/Public/React-Codegen', - '$(PODS_CONFIGURATION_BUILD_DIR)/React-Codegen/React_Codegen.framework/Headers', - '$(PODS_CONFIGURATION_BUILD_DIR)/React-Fabric/React_Fabric.framework/Headers' - ] - base_cpp_flags['HEADER_SEARCH_PATHS'] = header_search_paths.map { |path| "\"#{path}\"" }.join(' ') # Preprocessor definitions - inherit RCT_NEW_ARCH_ENABLED from parent project