Skip to content

Commit 7eb20be

Browse files
authored
feat: Add support for new architecture (#126)
* fix: add support for new architecture * lint * PR feedback
1 parent 587a895 commit 7eb20be

File tree

5 files changed

+19
-28
lines changed

5 files changed

+19
-28
lines changed

ios/Tflite.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifdef RCT_NEW_ARCH_ENABLED
22

33
#import "RNTfliteSpec.h"
4-
@interface Tflite : NSObject <NativeTfliteSpec>
4+
@interface Tflite : NSObject <NativeRNTfliteSpec>
55
@end
66

77
#else

ios/Tflite.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ @interface RCTBridge (RCTTurboModule)
1515
using namespace facebook;
1616

1717
@implementation Tflite
18-
RCT_EXPORT_MODULE()
18+
RCT_EXPORT_MODULE(Tflite)
1919

20-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
20+
- (NSNumber *)install {
2121
RCTBridge* bridge = [RCTBridge currentBridge];
2222
RCTCxxBridge* cxxBridge = (RCTCxxBridge*)bridge;
2323
if (!cxxBridge.runtime) {
@@ -50,7 +50,7 @@ @implementation Tflite
5050
#ifdef RCT_NEW_ARCH_ENABLED
5151
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
5252
(const facebook::react::ObjCTurboModule::InitParams&)params {
53-
return std::make_shared<facebook::react::NativeTfliteSpecJSI>(params);
53+
return std::make_shared<facebook::react::NativeRNTfliteSpecJSI>(params);
5454
}
5555
#endif
5656

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,10 @@
138138
]
139139
]
140140
},
141-
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
141+
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447",
142+
"codegenConfig": {
143+
"name": "RNTfliteSpec",
144+
"type": "modules",
145+
"jsSrcsDir": "spec"
146+
}
142147
}

spec/NativeRNTflite.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { TurboModule } from 'react-native'
2+
import { TurboModuleRegistry } from 'react-native'
3+
4+
export interface Spec extends TurboModule {
5+
install(): boolean
6+
}
7+
8+
export default TurboModuleRegistry.getEnforcing<Spec>('Tflite')

src/TensorflowModule.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1 @@
1-
import { NativeModules, Platform } from 'react-native'
2-
3-
const LINKING_ERROR =
4-
"The package 'react-native-fast-tflite' doesn't seem to be linked. Make sure: \n\n" +
5-
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6-
'- You rebuilt the app after installing the package\n' +
7-
'- You are not using Expo Go\n'
8-
9-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
10-
const Tflite =
11-
NativeModules.Tflite != null
12-
? NativeModules.Tflite
13-
: new Proxy(
14-
{},
15-
{
16-
get() {
17-
throw new Error(LINKING_ERROR)
18-
},
19-
}
20-
)
21-
22-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
23-
export const TensorflowModule = Tflite
1+
export { default as TensorflowModule } from '../spec/NativeRNTflite'

0 commit comments

Comments
 (0)