Skip to content

Commit 09e7a3a

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 091a768 commit 09e7a3a

File tree

44 files changed

+525
-238
lines changed

Some content is hidden

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

44 files changed

+525
-238
lines changed

.github/workflows/build-templates.yml

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,71 +30,50 @@ jobs:
3030
- ubuntu-latest
3131
- macos-14 # macos latest defaults to macos 12 at the moment.
3232
type:
33-
- module-legacy
34-
- module-mixed
35-
- module-new
36-
- view-legacy
37-
- view-mixed
38-
- view-new
33+
- module
34+
- view
35+
- view-module
3936
language:
4037
- kotlin-objc
41-
- kotlin-swift
38+
- cpp
4239
arch:
4340
- auto
4441
exclude:
45-
- type: module-new
46-
language: kotlin-swift
47-
- type: module-mixed
42+
- type: view
43+
language: cpp
44+
- type: view-module
45+
language: cpp
46+
- type: module
47+
language: kotlin-objc
48+
include:
49+
- os: ubuntu-latest
50+
type: view
4851
language: kotlin-swift
49-
- type: view-new
52+
arch: auto
53+
- os: macos-14
54+
type: view
5055
language: kotlin-swift
51-
- type: view-mixed
56+
arch: auto
57+
- os: ubuntu-latest
58+
type: module
5259
language: kotlin-swift
53-
include:
60+
arch: auto
5461
- os: ubuntu-latest
5562
type: library
5663
language: js
5764
arch: auto
5865
- os: ubuntu-latest
59-
type: module-mixed
66+
type: view-module
6067
language: kotlin-objc
6168
arch: new
6269
- os: macos-14
63-
type: module-mixed
70+
type: view-module
6471
language: kotlin-objc
6572
arch: new
6673
- os: ubuntu-latest
67-
type: view-mixed
68-
language: kotlin-objc
69-
arch: new
70-
- os: macos-14
71-
type: view-mixed
74+
type: view
7275
language: kotlin-objc
7376
arch: new
74-
- os: ubuntu-latest
75-
type: module-legacy
76-
language: cpp
77-
arch: auto
78-
- os: ubuntu-latest
79-
type: module-mixed
80-
language: cpp
81-
arch: auto
82-
- os: ubuntu-latest
83-
type: module-new
84-
language: cpp
85-
arch: auto
86-
- os: macos-14
87-
type: module-legacy
88-
language: cpp
89-
arch: auto
90-
- os: macos-14
91-
type: module-mixed
92-
language: cpp
93-
arch: auto
94-
- os: macos-14
95-
type: module-new
96-
language: cpp
97-
arch: auto
9877

9978
concurrency:
10079
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }}-${{ matrix.arch }}
@@ -171,17 +150,13 @@ jobs:
171150
working-directory: ${{ env.work_dir }}
172151
run: |
173152
# Build Android for only some matrices to skip redundant builds
174-
if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
175-
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
153+
if [[ ${{ matrix.os }} == ubuntu-latest ]] && [[ ${{ matrix.language }} != js ]] ; then
176154
echo "android_build=1" >> $GITHUB_ENV
177-
fi
178155
fi
179156
180157
# Build iOS for only some matrices to skip redundant builds
181-
if [[ ${{ matrix.os }} == macos-14 ]]; then
182-
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == kotlin-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == kotlin-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
158+
if [[ ${{ matrix.os }} == macos-14 ]] && [[ ${{ matrix.language }} != js ]]; then
183159
echo "ios_build=1" >> $GITHUB_ENV
184-
fi
185160
fi
186161
187162
- name: Cache turborepo

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

Lines changed: 92 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,70 @@ const NATIVE_COMMON_EXAMPLE_FILES = path.resolve(
4141
);
4242

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

5265
const OBJC_FILES = {
53-
module_common: path.resolve(__dirname, '../templates/objc-library'),
54-
view_legacy: path.resolve(__dirname, '../templates/objc-view-legacy'),
55-
view_mixed: path.resolve(__dirname, '../templates/objc-view-mixed'),
56-
view_new: path.resolve(__dirname, '../templates/objc-view-new'),
66+
'module-legacy': path.resolve(__dirname, '../templates/objc-library'),
67+
'module-mixed': path.resolve(__dirname, '../templates/objc-library'),
68+
'module-new': path.resolve(__dirname, '../templates/objc-library'),
69+
'view-module-legacy': path.resolve(
70+
__dirname,
71+
'../templates/objc-view-library-legacy'
72+
),
73+
'view-module-mixed': path.resolve(
74+
__dirname,
75+
'../templates/objc-view-library-mixed'
76+
),
77+
'view-module-new': path.resolve(
78+
__dirname,
79+
'../templates/objc-view-library-new'
80+
),
5781
} as const;
5882

5983
const KOTLIN_FILES = {
60-
module_legacy: path.resolve(__dirname, '../templates/kotlin-library-legacy'),
61-
module_new: path.resolve(__dirname, '../templates/kotlin-library-new'),
62-
module_mixed: path.resolve(__dirname, '../templates/kotlin-library-mixed'),
63-
view_legacy: path.resolve(__dirname, '../templates/kotlin-view-legacy'),
64-
view_mixed: path.resolve(__dirname, '../templates/kotlin-view-mixed'),
65-
view_new: path.resolve(__dirname, '../templates/kotlin-view-new'),
84+
'module-legacy': path.resolve(
85+
__dirname,
86+
'../templates/kotlin-library-legacy'
87+
),
88+
'module-new': path.resolve(__dirname, '../templates/kotlin-library-new'),
89+
'module-mixed': path.resolve(__dirname, '../templates/kotlin-library-mixed'),
90+
'view-legacy': path.resolve(__dirname, '../templates/kotlin-view-legacy'),
91+
'view-module-legacy': path.resolve(
92+
__dirname,
93+
'../templates/kotlin-view-library-legacy'
94+
),
95+
'view-module-mixed': path.resolve(
96+
__dirname,
97+
'../templates/kotlin-view-library-mixed'
98+
),
99+
'view-module-new': path.resolve(
100+
__dirname,
101+
'../templates/kotlin-view-library-new'
102+
),
66103
} as const;
67104

68105
const SWIFT_FILES = {
69-
module_legacy: path.resolve(__dirname, '../templates/swift-library-legacy'),
70-
view_legacy: path.resolve(__dirname, '../templates/swift-view-legacy'),
106+
'module-legacy': path.resolve(__dirname, '../templates/swift-library-legacy'),
107+
'view-legacy': path.resolve(__dirname, '../templates/swift-view-legacy'),
71108
} as const;
72109

73110
type ArgName =
@@ -86,13 +123,14 @@ type ArgName =
86123
type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js';
87124

88125
type ProjectType =
126+
| 'library'
89127
| 'module-legacy'
90-
| 'module-new'
91128
| 'module-mixed'
92-
| 'view-mixed'
93-
| 'view-new'
129+
| 'module-new'
94130
| 'view-legacy'
95-
| 'library';
131+
| 'view-module-legacy'
132+
| 'view-module-mixed'
133+
| 'view-module-new';
96134

97135
type Answers = {
98136
name: string;
@@ -117,14 +155,7 @@ const LANGUAGE_CHOICES: {
117155
{
118156
title: 'Kotlin & Objective-C',
119157
value: 'kotlin-objc',
120-
types: [
121-
'module-legacy',
122-
'module-new',
123-
'module-mixed',
124-
'view-mixed',
125-
'view-new',
126-
'view-legacy',
127-
],
158+
types: ['view-module-legacy', 'view-module-mixed', 'view-module-new'],
128159
},
129160
{
130161
title: 'Kotlin & Swift',
@@ -169,6 +200,21 @@ const TYPE_CHOICES: {
169200
value: ProjectType;
170201
description: string;
171202
}[] = [
203+
{
204+
title: 'Fabric view and Turbo module with backward compat',
205+
value: 'view-module-mixed',
206+
description: BACKCOMPAT_DESCRIPTION,
207+
},
208+
{
209+
title: 'Fabric view and Turbo module',
210+
value: 'view-module-new',
211+
description: NEWARCH_DESCRIPTION,
212+
},
213+
{
214+
title: 'Native module and Native view',
215+
value: 'view-module-legacy',
216+
description: 'bridge for native APIs and views to JS',
217+
},
172218
{
173219
title: 'JavaScript library',
174220
value: 'library',
@@ -194,16 +240,6 @@ const TYPE_CHOICES: {
194240
value: 'module-new',
195241
description: NEWARCH_DESCRIPTION,
196242
},
197-
{
198-
title: 'Fabric view with backward compat',
199-
value: 'view-mixed',
200-
description: BACKCOMPAT_DESCRIPTION,
201-
},
202-
{
203-
title: 'Fabric view',
204-
value: 'view-new',
205-
description: NEWARCH_DESCRIPTION,
206-
},
207243
];
208244

209245
const args: Record<ArgName, yargs.Options> = {
@@ -599,13 +635,11 @@ async function create(_argv: yargs.Arguments<any>) {
599635
bobVersion = FALLBACK_BOB_VERSION;
600636
}
601637

602-
const moduleType = type.startsWith('view-') ? 'view' : 'module';
603-
const arch =
604-
type === 'module-new' || type === 'view-new'
605-
? 'new'
606-
: type === 'module-mixed' || type === 'view-mixed'
607-
? 'mixed'
608-
: 'legacy';
638+
const arch = type.endsWith('new')
639+
? 'new'
640+
: type.endsWith('mixed')
641+
? 'mixed'
642+
: 'legacy';
609643

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

@@ -646,8 +680,8 @@ async function create(_argv: yargs.Arguments<any>) {
646680
arch,
647681
cpp: languages === 'cpp',
648682
swift: languages === 'kotlin-swift',
649-
view: moduleType === 'view',
650-
module: moduleType === 'module',
683+
view: type.includes('view'),
684+
module: type.includes('module'),
651685
},
652686
author: {
653687
name: authorName,
@@ -735,7 +769,7 @@ async function create(_argv: yargs.Arguments<any>) {
735769
}
736770
}
737771

738-
if (languages === 'js') {
772+
if (type === 'library') {
739773
await copyDir(JS_FILES, folder);
740774
await copyDir(EXPO_FILES, folder);
741775
} else {
@@ -745,25 +779,18 @@ async function create(_argv: yargs.Arguments<any>) {
745779
await copyDir(NATIVE_COMMON_EXAMPLE_FILES, folder);
746780
}
747781

748-
if (moduleType === 'module') {
749-
await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder);
750-
} else {
751-
await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder);
752-
}
782+
await copyDir(NATIVE_FILES[type], folder);
753783

754-
if (options.project.swift) {
755-
await copyDir(SWIFT_FILES[`${moduleType}_legacy`], folder);
784+
if (
785+
type === 'view-legacy' ||
786+
(type === 'module-legacy' && options.project.swift)
787+
) {
788+
await copyDir(SWIFT_FILES[type], folder);
756789
} else {
757-
if (moduleType === 'module') {
758-
await copyDir(OBJC_FILES[`${moduleType}_common`], folder);
759-
} else {
760-
await copyDir(OBJC_FILES[`view_${arch}`], folder);
761-
}
790+
await copyDir(OBJC_FILES[type], folder);
762791
}
763792

764-
const templateType = `${moduleType}_${arch}` as const;
765-
766-
await copyDir(KOTLIN_FILES[templateType], folder);
793+
await copyDir(KOTLIN_FILES[type], folder);
767794

768795
if (options.project.cpp) {
769796
await copyDir(CPP_FILES, folder);

0 commit comments

Comments
 (0)