Skip to content

Commit

Permalink
feat: readd templates for cpp and swift
Browse files Browse the repository at this point in the history
  • Loading branch information
atlj committed Jun 12, 2024
1 parent 759e510 commit dc7e2f8
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NativeModules, Platform } from 'react-native';

const LINKING_ERROR =
`The package '<%- project.slug -%>' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';

const <%- project.name -%> = NativeModules.<%- project.name %>
? NativeModules.<%- project.name %>
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);

export function multiply(a: number, b: number): Promise<number> {
return <%- project.name -%>.multiply(a, b);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

export interface Spec extends TurboModule {
multiply(a: number, b: number): Promise<number>;
}

export default TurboModuleRegistry.getEnforcing<Spec>('<%- project.name -%>');
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { NativeModules, Platform } from 'react-native';

const LINKING_ERROR =
`The package '<%- project.slug -%>' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';

// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;

const <%- project.name -%>Module = isTurboModuleEnabled
? require('./Native<%- project.name -%>').default
: NativeModules.<%- project.name -%>;

const <%- project.name -%> = <%- project.name -%>Module
? <%- project.name -%>Module
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);

export function multiply(a: number, b: number): Promise<number> {
return <%- project.name -%>.multiply(a, b);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

export interface Spec extends TurboModule {
multiply(a: number, b: number): number;
}

export default TurboModuleRegistry.getEnforcing<Spec>('<%- project.name -%>');
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const <%- project.name -%> = require('./Native<%- project.name -%>').default;

export function multiply(a: number, b: number): number {
return <%- project.name -%>.multiply(a, b);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
requireNativeComponent,
UIManager,
Platform,
type ViewStyle,
} from 'react-native';

const LINKING_ERROR =
`The package '<%- project.slug -%>' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';

type <%- project.name -%>Props = {
color: string;
style: ViewStyle;
};

const ComponentName = '<%- project.name -%>View';

export const <%- project.name -%>View =
UIManager.getViewManagerConfig(ComponentName) != null
? requireNativeComponent<<%- project.name -%>Props>(ComponentName)
: () => {
throw new Error(LINKING_ERROR);
};

0 comments on commit dc7e2f8

Please sign in to comment.