diff --git a/packages/create-react-native-library/templates/native-library-legacy/src/Native{%- project.name %}.ts b/packages/create-react-native-library/templates/native-library-legacy/src/Native{%- project.name %}.ts new file mode 100644 index 000000000..651971c33 --- /dev/null +++ b/packages/create-react-native-library/templates/native-library-legacy/src/Native{%- project.name %}.ts @@ -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 { + return <%- project.name -%>.multiply(a, b); +} diff --git a/packages/create-react-native-library/templates/native-library-legacy/src/index.tsx b/packages/create-react-native-library/templates/native-library-legacy/src/index.tsx index 651971c33..da37908fe 100644 --- a/packages/create-react-native-library/templates/native-library-legacy/src/index.tsx +++ b/packages/create-react-native-library/templates/native-library-legacy/src/index.tsx @@ -1,22 +1,2 @@ -import { NativeModules, Platform } from 'react-native'; +export * from './Native<%- project.name -%>'; -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 { - return <%- project.name -%>.multiply(a, b); -} diff --git a/packages/create-react-native-library/templates/native-view-legacy/src/index.tsx b/packages/create-react-native-library/templates/native-view-legacy/src/index.tsx index 055016821..2a1507921 100644 --- a/packages/create-react-native-library/templates/native-view-legacy/src/index.tsx +++ b/packages/create-react-native-library/templates/native-view-legacy/src/index.tsx @@ -1,26 +1 @@ -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); - }; +export * from './<%- project.name -%>View'; diff --git a/packages/create-react-native-library/templates/native-view-legacy/src/{%- project.name %}View.ts b/packages/create-react-native-library/templates/native-view-legacy/src/{%- project.name %}View.ts new file mode 100644 index 000000000..ffeb5a901 --- /dev/null +++ b/packages/create-react-native-library/templates/native-view-legacy/src/{%- project.name %}View.ts @@ -0,0 +1,25 @@ +import { + requireNativeComponent, + UIManager, + Platform, + 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); + };