Skip to content

Commit 9eb2445

Browse files
Combine native and native-view into native-common
1 parent 69d10c5 commit 9eb2445

File tree

12 files changed

+29
-383
lines changed

12 files changed

+29
-383
lines changed

src/create.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@ const JS_FILES = path.resolve(__dirname, '../templates/js-library');
1717
const EXPO_FILES = path.resolve(__dirname, '../templates/expo-library');
1818
const CPP_FILES = path.resolve(__dirname, '../templates/cpp-library');
1919
const EXAMPLE_FILES = path.resolve(__dirname, '../templates/example');
20-
21-
// Common native library template files
22-
const NATIVE_FILES = (moduleType: ModuleType) => {
23-
switch (moduleType) {
24-
case 'module':
25-
return path.resolve(__dirname, '../templates/native-library');
26-
case 'view':
27-
return path.resolve(__dirname, '../templates/native-view-library');
28-
}
29-
};
20+
const NATIVE_COMMON_FILES = path.resolve(
21+
__dirname,
22+
'../templates/native-common'
23+
);
3024

3125
// Java
3226
const JAVA_FILES = (moduleType: ModuleType) => {
@@ -417,7 +411,7 @@ export default async function create(argv: yargs.Arguments<any>) {
417411
path.join(folder, 'example')
418412
);
419413

420-
await copyDir(NATIVE_FILES(moduleType), folder);
414+
await copyDir(NATIVE_COMMON_FILES, folder);
421415

422416
if (options.project.cpp) {
423417
await copyDir(CPP_FILES, folder);

templates/native-common/src/index.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<% if (project.moduleType === "view") { -%>
2+
import { requireNativeComponent, ViewStyle } from 'react-native';
3+
4+
type <%- project.name %>Props = {
5+
color: string;
6+
style: ViewStyle;
7+
};
8+
9+
export const <%- project.name %>ViewManager = requireNativeComponent<<%- project.name %>Props>(
10+
'<%- project.name %>View'
11+
);
12+
13+
export default <%- project.name %>ViewManager;
14+
<% } else { -%>
15+
import { NativeModules } from 'react-native';
16+
17+
type <%- project.name %>Type = {
18+
multiply(a: number, b: number): Promise<number>;
19+
};
20+
21+
const { <%- project.name %> } = NativeModules;
22+
23+
export default <%- project.name %> as <%- project.name %>Type;
24+
<% } -%>

templates/native-library/src/index.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

templates/native-view-library/android/src/main/AndroidManifest.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

templates/native-view-library/ios/{%- project.name %}.xcodeproj/project.pbxproj

Lines changed: 0 additions & 317 deletions
This file was deleted.

templates/native-view-library/ios/{%- project.name %}.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)