-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: readd templates for cpp and swift
- Loading branch information
Showing
6 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
packages/create-react-native-library/templates/native-library-legacy/src/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
8 changes: 8 additions & 0 deletions
8
...eate-react-native-library/templates/native-library-mixed/src/Native{%- project.name %}.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -%>'); |
29 changes: 29 additions & 0 deletions
29
packages/create-react-native-library/templates/native-library-mixed/src/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
8 changes: 8 additions & 0 deletions
8
...create-react-native-library/templates/native-library-new/src/Native{%- project.name %}.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -%>'); |
5 changes: 5 additions & 0 deletions
5
packages/create-react-native-library/templates/native-library-new/src/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/create-react-native-library/templates/native-view-legacy/src/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |