Skip to content

Commit 9d0a89e

Browse files
committed
feat: create ts part
1 parent 1970c98 commit 9d0a89e

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
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+
multiply(a: number, b: number): Promise<number>;
6+
}
7+
8+
export default TurboModuleRegistry.getEnforcing<Spec>('<%- project.name -%>');
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { NativeModules, Platform } from 'react-native';
2+
3+
const LINKING_ERROR =
4+
`The package '<%- project.slug -%>' 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+
// @ts-expect-error
10+
const isTurboModuleEnabled = global.__turboModuleProxy != null;
11+
12+
const <%- project.name -%>Module = isTurboModuleEnabled
13+
? require('./Native<%- project.name -%>').default
14+
: NativeModules.<%- project.name -%>;
15+
16+
const <%- project.name -%> = <%- project.name -%>Module
17+
? <%- project.name -%>Module
18+
: new Proxy(
19+
{},
20+
{
21+
get() {
22+
throw new Error(LINKING_ERROR);
23+
},
24+
}
25+
);
26+
27+
export function multiply(a: number, b: number): Promise<number> {
28+
return <%- project.name -%>.multiply(a, b);
29+
}
30+
31+
export { default as <%- project.name -%>View } from './<%- project.name -%>NativeComponent';
32+
export * from './<%- project.name -%>NativeComponent';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
2+
import type { ViewProps } from 'react-native';
3+
4+
interface NativeProps extends ViewProps {
5+
color?: string;
6+
}
7+
8+
export default codegenNativeComponent<NativeProps>('<%- project.name -%>View');

0 commit comments

Comments
 (0)