Skip to content

Commit

Permalink
ios端原生模块demo
Browse files Browse the repository at this point in the history
  • Loading branch information
drafish committed Jan 30, 2020
1 parent f70e5b0 commit d43ed2c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
7 changes: 5 additions & 2 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ import TestExample from "./TestExample";
// console.warn(res)
// })

TestExample.add(1, 2, (res) => {
console.warn(res)
});

const App: () => React$Node = () => {
console.warn(TestExample.runTest(2, 2));

// console.warn(TestExample.runTest(2, 2));

return (
<>
Expand Down
10 changes: 5 additions & 5 deletions TestExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* 2. int duration: The duration of the toast. May be ToastExample.SHORT or
* ToastExample.LONG
*/
// import { NativeModules } from "react-native";
// // 下一句中的ToastExample即对应上文
// // public String getName()中返回的字符串
// export default NativeModules.TestExample;
export default global.nativeTest;
import { NativeModules } from "react-native";
// 下一句中的ToastExample即对应上文
// public String getName()中返回的字符串
export default NativeModules.TestExample;
// export default global.nativeTest;
17 changes: 16 additions & 1 deletion ios/ReactNativeCppDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
4D1613E2C50272DB7F48D7F7 /* libPods-ReactNativeCppDemo-tvOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FAC29F1BC72B680AA5F76D2 /* libPods-ReactNativeCppDemo-tvOSTests.a */; };
89E87BEE2756359352AB391D /* libPods-ReactNativeCppDemoTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19FEF3DAEE73C7C95A2D19AF /* libPods-ReactNativeCppDemoTests.a */; };
9EC97CE4AEE232C3AAB9E838 /* libPods-ReactNativeCppDemo-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CCDA862AB3EF9D7B4B43F706 /* libPods-ReactNativeCppDemo-tvOS.a */; };
FC7D142823E2C74700397311 /* TestModule.m in Sources */ = {isa = PBXBuildFile; fileRef = FC7D142723E2C74700397311 /* TestModule.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -67,6 +68,8 @@
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
ED2971642150620600B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS12.0.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; };
EEB2EF7A2F55C70D37204724 /* Pods-ReactNativeCppDemo-tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeCppDemo-tvOS.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeCppDemo-tvOS/Pods-ReactNativeCppDemo-tvOS.debug.xcconfig"; sourceTree = "<group>"; };
FC7D142623E2C74700397311 /* TestModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestModule.h; sourceTree = "<group>"; };
FC7D142723E2C74700397311 /* TestModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestModule.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -128,6 +131,7 @@
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
13B07FB01A68108700A75B9A /* AppDelegate.m */,
FC7D142523E2C74700397311 /* jni */,
13B07FB51A68108700A75B9A /* Images.xcassets */,
13B07FB61A68108700A75B9A /* Info.plist */,
13B07FB11A68108700A75B9A /* LaunchScreen.xib */,
Expand All @@ -148,7 +152,6 @@
DB072E366BF39FCDAA54031F /* Pods-ReactNativeCppDemoTests.debug.xcconfig */,
27DAA7DC201E6F1C6E2ED2CE /* Pods-ReactNativeCppDemoTests.release.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -198,6 +201,16 @@
name = Products;
sourceTree = "<group>";
};
FC7D142523E2C74700397311 /* jni */ = {
isa = PBXGroup;
children = (
FC7D142623E2C74700397311 /* TestModule.h */,
FC7D142723E2C74700397311 /* TestModule.m */,
);
name = jni;
path = ReactNativeCppDemo/example/jni;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -308,6 +321,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -529,6 +543,7 @@
buildActionMask = 2147483647;
files = (
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */,
FC7D142823E2C74700397311 /* TestModule.m in Sources */,
13B07FC11A68108700A75B9A /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
4 changes: 4 additions & 0 deletions ios/ReactNativeCppDemo/example/jni/TestModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import <React/RCTBridgeModule.h>

@interface TestExample : NSObject <RCTBridgeModule>
@end
13 changes: 13 additions & 0 deletions ios/ReactNativeCppDemo/example/jni/TestModule.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import "TestModule.h"

@implementation TestExample

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(add:(NSInteger)numberA numberParameter:(NSInteger)numberB callback:(RCTResponseSenderBlock)callback)
{
NSInteger c = numberA + numberB;
callback(@[@(c)]);
}

@end

0 comments on commit d43ed2c

Please sign in to comment.