feat: support ios new architecture

This commit is contained in:
Lethe 2025-08-17 19:44:52 +09:00
parent 7480025ed6
commit 2d89d4eaf1
5 changed files with 97 additions and 15 deletions

11
ios/CaptureProtection.h Normal file
View File

@ -0,0 +1,11 @@
#ifdef RCT_NEW_ARCH_ENABLED
#import "generated/CaptureProtectionSpec/CaptureProtectionSpec.h"
@interface CaptureProtection : NSObject <NativeCaptureProtectionSpec>
#else
#import <React/RCTBridgeModule.h>
@interface CaptureProtection : NSObject <RCTBridgeModule>
#endif
@end

View File

@ -26,6 +26,7 @@
/* Begin PBXFileReference section */
0434F4A12D756B8300247D8B /* CaptureProtection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CaptureProtection.m; sourceTree = "<group>"; };
0434F4A52D756BAA00247D8B /* CaptureProtection-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CaptureProtection-Bridging-Header.h"; sourceTree = "<group>"; };
04AC65552E51A18700E1B26C /* CaptureProtection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CaptureProtection.h; sourceTree = "<group>"; };
134814201AA4EA6300B7C361 /* libCaptureProtection.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCaptureProtection.a; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@ -66,6 +67,7 @@
58B511D21A9E6C8500147676 = {
isa = PBXGroup;
children = (
04AC65552E51A18700E1B26C /* CaptureProtection.h */,
040D5EA22DA21C2B0014FE24 /* CaptureProtection */,
0434F4A12D756B8300247D8B /* CaptureProtection.m */,
0434F4A52D756BAA00247D8B /* CaptureProtection-Bridging-Header.h */,

View File

@ -158,6 +158,7 @@
"source": "src",
"output": "lib",
"targets": [
"codegen",
"commonjs",
"module",
[
@ -170,5 +171,18 @@
},
"dependencies": {
"expo-dev-client": "~5.2.1"
},
"codegenConfig": {
"name": "CaptureProtectionSpec",
"type": "modules",
"jsSrcsDir": "./src/spec",
"outputDir": {
"ios": "ios/generated",
"android": "android/generated"
},
"android": {
"javaPackageName": "com.captureprotection"
},
"includesGeneratedCode": true
}
}

View File

@ -15,21 +15,24 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/wn-na/react-native-capture-protection.git", :tag => "#{s.version}" }
s.source_files = "ios/**/*.{h,m,mm,swift}"
if respond_to?(:install_modules_dependencies, true)
install_modules_dependencies(s)
else
s.dependency "React-Core"
s.dependency "React-Core"
# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
end
end

View File

@ -0,0 +1,52 @@
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
type CaptureProtectionModuleStatus = {
screenshot?: boolean;
record?: boolean;
appSwitcher?: boolean;
};
export interface Spec extends TurboModule {
allowScreenshot: () => Promise<void>;
preventScreenshot: () => Promise<void>;
allowScreenRecord: () => Promise<void>;
preventScreenRecord: () => Promise<void>;
preventScreenRecordWithText: (
text: string,
textColor?: string,
backgroundColor?: string
) => Promise<void>;
preventScreenRecordWithImage: (
image: {
height: number;
width: number;
scale: number;
uri: string;
},
backgroundColor?: string,
contentMode?: number
) => Promise<void>;
allowAppSwitcher: () => Promise<void>;
preventAppSwitcher: () => Promise<void>;
preventAppSwitcherWithText: (
text: string,
textColor?: string,
backgroundColor?: string
) => Promise<void>;
preventAppSwitcherWithImage: (
image: {
height: number;
width: number;
scale: number;
uri: string;
},
backgroundColor?: string,
contentMode?: number
) => Promise<void>;
hasListener: () => Promise<boolean>;
protectionStatus: () => Promise<CaptureProtectionModuleStatus>;
isScreenRecording: () => Promise<boolean | undefined>;
}
export default TurboModuleRegistry.getEnforcing<Spec>('CaptureProtection');