Skip to content

Commit b0ada7a

Browse files
committed
feat: merge view+module native templates (#562)
This adds new templates that use `Kotlin` and `Objective-C`. The templates each have a native view and a native module included. 1. With 993d5cd, the new arch and mixed arch views will no longer have the `View` suffix in their codegen names. This doesn't break codegen as the name field is arbitrary as it isn't stated otherwise [in the new arch working group documents](https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-libraries-prerequisites.md#configure-codegen). One important matter to remember here is to make sure we pass the `RN` prefix since headers can conflict. 2. No more Java templates! I've removed them all for the sake of Kotlin. 3. I've removed templates like view-new (new arch-only view template) since we now have view+module templates and it would be hard to maintain the old model. 4. I kept `module-legacy`, `module-mixed`, and `module-new` since they are used by cpp. 5. I kept `module-legacy`, and `view-legacy` since they are used by Swift. 1. Go to `packages/create-react-native-library`. 7. Call `yarn prepare` to build the CLI. 8. Run `./bin/create-react-native-library` to run the CLI you built. 9. Fill in the name, email, etc., and make sure to select ` Fabric view and Turbo module with backward compat`. 10. Go to the library you created and make sure to build the following: a. Android with old architecture b. iOS with old architecture c. Android with new architecture d. iOS with new architecture
1 parent 5052841 commit b0ada7a

File tree

68 files changed

+636
-763
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+636
-763
lines changed

.github/workflows/build-templates.yml

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,57 +33,41 @@ jobs:
3333
- module-legacy
3434
- module-mixed
3535
- module-new
36-
- view-legacy
37-
- view-mixed
38-
- view-new
36+
- view-module-legacy
37+
- view-module-mixed
38+
- view-module-new
3939
language:
40-
- java-objc
41-
- java-swift
4240
- kotlin-objc
43-
- kotlin-swift
41+
- cpp
4442
exclude:
45-
- os: macos-14
43+
- type: view-module-legacy
44+
language: cpp
45+
- type: view-module-mixed
46+
language: cpp
47+
- type: view-module-new
48+
language: cpp
49+
- type: module-legacy
50+
language: kotlin-objc
51+
- type: module-mixed
4652
language: kotlin-objc
47-
- os: macos-14
48-
language: kotlin-swift
49-
- type: module-new
50-
language: java-swift
5153
- type: module-new
54+
language: kotlin-objc
55+
include:
56+
- os: ubuntu-latest
57+
type: view-legacy
5258
language: kotlin-swift
53-
- type: module-mixed
54-
language: java-swift
55-
- type: module-mixed
59+
- os: macos-14
60+
type: view-legacy
5661
language: kotlin-swift
57-
- type: view-new
58-
language: java-swift
59-
- type: view-new
62+
- os: ubuntu-latest
63+
type: module-legacy
6064
language: kotlin-swift
61-
- type: view-mixed
62-
language: java-swift
63-
- type: view-mixed
65+
- os: macos-14
66+
type: module-legacy
6467
language: kotlin-swift
65-
include:
6668
- os: ubuntu-latest
6769
type: library
6870
language: js
69-
- os: ubuntu-latest
70-
type: module-legacy
71-
language: cpp
72-
- os: ubuntu-latest
73-
type: module-mixed
74-
language: cpp
75-
- os: ubuntu-latest
76-
type: module-new
77-
language: cpp
78-
- os: macos-14
79-
type: module-legacy
80-
language: cpp
81-
- os: macos-14
82-
type: module-mixed
83-
language: cpp
84-
- os: macos-14
85-
type: module-new
86-
language: cpp
8771

8872
concurrency:
8973
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }}
@@ -153,17 +137,13 @@ jobs:
153137
working-directory: ${{ env.work_dir }}
154138
run: |
155139
# Build Android for only some matrices to skip redundant builds
156-
if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
157-
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
140+
if [[ ${{ matrix.os }} == ubuntu-latest ]] && [[ ${{ matrix.language }} != js ]] ; then
158141
echo "android_build=1" >> $GITHUB_ENV
159-
fi
160142
fi
161143
162144
# Build iOS for only some matrices to skip redundant builds
163-
if [[ ${{ matrix.os }} == macos-14 ]]; then
164-
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
145+
if [[ ${{ matrix.os }} == macos-14 ]] && [[ ${{ matrix.language }} != js ]]; then
165146
echo "ios_build=1" >> $GITHUB_ENV
166-
fi
167147
fi
168148
169149
- name: Cache turborepo

packages/create-react-native-library/src/index.ts

Lines changed: 94 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -40,42 +40,70 @@ const NATIVE_COMMON_EXAMPLE_FILES = path.resolve(
4040
);
4141

4242
const NATIVE_FILES = {
43-
module_legacy: path.resolve(__dirname, '../templates/native-library-legacy'),
44-
module_new: path.resolve(__dirname, '../templates/native-library-new'),
45-
module_mixed: path.resolve(__dirname, '../templates/native-library-mixed'),
46-
view_legacy: path.resolve(__dirname, '../templates/native-view-legacy'),
47-
view_mixed: path.resolve(__dirname, '../templates/native-view-mixed'),
48-
view_new: path.resolve(__dirname, '../templates/native-view-new'),
49-
} as const;
50-
51-
const JAVA_FILES = {
52-
module_legacy: path.resolve(__dirname, '../templates/java-library-legacy'),
53-
module_new: path.resolve(__dirname, '../templates/java-library-new'),
54-
module_mixed: path.resolve(__dirname, '../templates/java-library-mixed'),
55-
view_legacy: path.resolve(__dirname, '../templates/java-view-legacy'),
56-
view_mixed: path.resolve(__dirname, '../templates/java-view-mixed'),
57-
view_new: path.resolve(__dirname, '../templates/java-view-new'),
43+
'module-legacy': path.resolve(
44+
__dirname,
45+
'../templates/native-library-legacy'
46+
),
47+
'module-new': path.resolve(__dirname, '../templates/native-library-new'),
48+
'module-mixed': path.resolve(__dirname, '../templates/native-library-mixed'),
49+
'view-legacy': path.resolve(__dirname, '../templates/native-view-legacy'),
50+
'view-module-legacy': path.resolve(
51+
__dirname,
52+
'../templates/native-view-library-legacy'
53+
),
54+
'view-module-mixed': path.resolve(
55+
__dirname,
56+
'../templates/native-view-library-mixed'
57+
),
58+
'view-module-new': path.resolve(
59+
__dirname,
60+
'../templates/native-view-library-new'
61+
),
5862
} as const;
5963

6064
const OBJC_FILES = {
61-
module_common: path.resolve(__dirname, '../templates/objc-library'),
62-
view_legacy: path.resolve(__dirname, '../templates/objc-view-legacy'),
63-
view_mixed: path.resolve(__dirname, '../templates/objc-view-mixed'),
64-
view_new: path.resolve(__dirname, '../templates/objc-view-new'),
65+
'module-legacy': path.resolve(__dirname, '../templates/objc-library'),
66+
'module-mixed': path.resolve(__dirname, '../templates/objc-library'),
67+
'module-new': path.resolve(__dirname, '../templates/objc-library'),
68+
'view-module-legacy': path.resolve(
69+
__dirname,
70+
'../templates/objc-view-library-legacy'
71+
),
72+
'view-module-mixed': path.resolve(
73+
__dirname,
74+
'../templates/objc-view-library-mixed'
75+
),
76+
'view-module-new': path.resolve(
77+
__dirname,
78+
'../templates/objc-view-library-new'
79+
),
6580
} as const;
6681

6782
const KOTLIN_FILES = {
68-
module_legacy: path.resolve(__dirname, '../templates/kotlin-library-legacy'),
69-
module_new: path.resolve(__dirname, '../templates/kotlin-library-new'),
70-
module_mixed: path.resolve(__dirname, '../templates/kotlin-library-mixed'),
71-
view_legacy: path.resolve(__dirname, '../templates/kotlin-view-legacy'),
72-
view_mixed: path.resolve(__dirname, '../templates/kotlin-view-mixed'),
73-
view_new: path.resolve(__dirname, '../templates/kotlin-view-new'),
83+
'module-legacy': path.resolve(
84+
__dirname,
85+
'../templates/kotlin-library-legacy'
86+
),
87+
'module-new': path.resolve(__dirname, '../templates/kotlin-library-new'),
88+
'module-mixed': path.resolve(__dirname, '../templates/kotlin-library-mixed'),
89+
'view-legacy': path.resolve(__dirname, '../templates/kotlin-view-legacy'),
90+
'view-module-legacy': path.resolve(
91+
__dirname,
92+
'../templates/kotlin-view-library-legacy'
93+
),
94+
'view-module-mixed': path.resolve(
95+
__dirname,
96+
'../templates/kotlin-view-library-mixed'
97+
),
98+
'view-module-new': path.resolve(
99+
__dirname,
100+
'../templates/kotlin-view-library-new'
101+
),
74102
} as const;
75103

76104
const SWIFT_FILES = {
77-
module_legacy: path.resolve(__dirname, '../templates/swift-library-legacy'),
78-
view_legacy: path.resolve(__dirname, '../templates/swift-view-legacy'),
105+
'module-legacy': path.resolve(__dirname, '../templates/swift-library-legacy'),
106+
'view-legacy': path.resolve(__dirname, '../templates/swift-view-legacy'),
79107
} as const;
80108

81109
type ArgName =
@@ -91,22 +119,17 @@ type ArgName =
91119
| 'example'
92120
| 'react-native-version';
93121

94-
type ProjectLanguages =
95-
| 'java-objc'
96-
| 'java-swift'
97-
| 'kotlin-objc'
98-
| 'kotlin-swift'
99-
| 'cpp'
100-
| 'js';
122+
type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js';
101123

102124
type ProjectType =
125+
| 'library'
103126
| 'module-legacy'
104-
| 'module-new'
105127
| 'module-mixed'
106-
| 'view-mixed'
107-
| 'view-new'
128+
| 'module-new'
108129
| 'view-legacy'
109-
| 'library';
130+
| 'view-module-legacy'
131+
| 'view-module-mixed'
132+
| 'view-module-new';
110133

111134
type Answers = {
112135
name: string;
@@ -131,37 +154,13 @@ const LANGUAGE_CHOICES: {
131154
{
132155
title: 'Kotlin & Objective-C',
133156
value: 'kotlin-objc',
134-
types: [
135-
'module-legacy',
136-
'module-new',
137-
'module-mixed',
138-
'view-mixed',
139-
'view-new',
140-
'view-legacy',
141-
],
142-
},
143-
{
144-
title: 'Java & Objective-C',
145-
value: 'java-objc',
146-
types: [
147-
'module-legacy',
148-
'module-new',
149-
'module-mixed',
150-
'view-mixed',
151-
'view-new',
152-
'view-legacy',
153-
],
157+
types: ['view-module-legacy', 'view-module-mixed', 'view-module-new'],
154158
},
155159
{
156160
title: 'Kotlin & Swift',
157161
value: 'kotlin-swift',
158162
types: ['module-legacy', 'view-legacy'],
159163
},
160-
{
161-
title: 'Java & Swift',
162-
value: 'java-swift',
163-
types: ['module-legacy', 'view-legacy'],
164-
},
165164
{
166165
title: 'C++ for Android & iOS',
167166
value: 'cpp',
@@ -200,6 +199,21 @@ const TYPE_CHOICES: {
200199
value: ProjectType;
201200
description: string;
202201
}[] = [
202+
{
203+
title: 'Fabric view and Turbo module with backward compat',
204+
value: 'view-module-mixed',
205+
description: BACKCOMPAT_DESCRIPTION,
206+
},
207+
{
208+
title: 'Fabric view and Turbo module',
209+
value: 'view-module-new',
210+
description: NEWARCH_DESCRIPTION,
211+
},
212+
{
213+
title: 'Native module and Native view',
214+
value: 'view-module-legacy',
215+
description: 'bridge for native APIs and views to JS',
216+
},
203217
{
204218
title: 'JavaScript library',
205219
value: 'library',
@@ -225,16 +239,6 @@ const TYPE_CHOICES: {
225239
value: 'module-new',
226240
description: NEWARCH_DESCRIPTION,
227241
},
228-
{
229-
title: 'Fabric view with backward compat',
230-
value: 'view-mixed',
231-
description: BACKCOMPAT_DESCRIPTION,
232-
},
233-
{
234-
title: 'Fabric view',
235-
value: 'view-new',
236-
description: NEWARCH_DESCRIPTION,
237-
},
238242
];
239243

240244
const args: Record<ArgName, yargs.Options> = {
@@ -620,13 +624,11 @@ async function create(_argv: yargs.Arguments<any>) {
620624
bobVersion = FALLBACK_BOB_VERSION;
621625
}
622626

623-
const moduleType = type.startsWith('view-') ? 'view' : 'module';
624-
const arch =
625-
type === 'module-new' || type === 'view-new'
626-
? 'new'
627-
: type === 'module-mixed' || type === 'view-mixed'
628-
? 'mixed'
629-
: 'legacy';
627+
const arch = type.endsWith('new')
628+
? 'new'
629+
: type.endsWith('mixed')
630+
? 'mixed'
631+
: 'legacy';
630632

631633
const project = slug.replace(/^(react-native-|@[^/]+\/)/, '');
632634

@@ -666,10 +668,9 @@ async function create(_argv: yargs.Arguments<any>) {
666668
native: languages !== 'js',
667669
arch,
668670
cpp: languages === 'cpp',
669-
kotlin: languages === 'kotlin-objc' || languages === 'kotlin-swift',
670-
swift: languages === 'java-swift' || languages === 'kotlin-swift',
671-
view: moduleType === 'view',
672-
module: moduleType === 'module',
671+
swift: languages === 'kotlin-swift',
672+
view: type.includes('view'),
673+
module: type.includes('module'),
673674
},
674675
author: {
675676
name: authorName,
@@ -756,7 +757,7 @@ async function create(_argv: yargs.Arguments<any>) {
756757
}
757758
}
758759

759-
if (languages === 'js') {
760+
if (type === 'library') {
760761
await copyDir(JS_FILES, folder);
761762
await copyDir(EXPO_FILES, folder);
762763
} else {
@@ -766,29 +767,18 @@ async function create(_argv: yargs.Arguments<any>) {
766767
await copyDir(NATIVE_COMMON_EXAMPLE_FILES, folder);
767768
}
768769

769-
if (moduleType === 'module') {
770-
await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder);
771-
} else {
772-
await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder);
773-
}
770+
await copyDir(NATIVE_FILES[type], folder);
774771

775-
if (options.project.swift) {
776-
await copyDir(SWIFT_FILES[`${moduleType}_legacy`], folder);
772+
if (
773+
type === 'view-legacy' ||
774+
(type === 'module-legacy' && options.project.swift)
775+
) {
776+
await copyDir(SWIFT_FILES[type], folder);
777777
} else {
778-
if (moduleType === 'module') {
779-
await copyDir(OBJC_FILES[`${moduleType}_common`], folder);
780-
} else {
781-
await copyDir(OBJC_FILES[`view_${arch}`], folder);
782-
}
778+
await copyDir(OBJC_FILES[type], folder);
783779
}
784780

785-
const templateType = `${moduleType}_${arch}` as const;
786-
787-
if (options.project.kotlin) {
788-
await copyDir(KOTLIN_FILES[templateType], folder);
789-
} else {
790-
await copyDir(JAVA_FILES[templateType], folder);
791-
}
781+
await copyDir(KOTLIN_FILES[type], folder);
792782

793783
if (options.project.cpp) {
794784
await copyDir(CPP_FILES, folder);

0 commit comments

Comments
 (0)