Skip to content

Commit a75cf32

Browse files
authored
feat: merge view+module native templates (#562)
## Summary This adds new templates that use `Kotlin` and `Objective-C`. The templates each have a native view and a native module included. ### Other Changes / Side Effects 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. ## Test plan 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 3676c71 commit a75cf32

File tree

68 files changed

+638
-762
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

+638
-762
lines changed

.github/workflows/build-templates.yml

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,57 +28,41 @@ jobs:
2828
- module-legacy
2929
- module-mixed
3030
- module-new
31-
- view-legacy
32-
- view-mixed
33-
- view-new
31+
- view-module-legacy
32+
- view-module-mixed
33+
- view-module-new
3434
language:
35-
- java-objc
36-
- java-swift
3735
- kotlin-objc
38-
- kotlin-swift
36+
- cpp
3937
exclude:
40-
- os: macos-14
38+
- type: view-module-legacy
39+
language: cpp
40+
- type: view-module-mixed
41+
language: cpp
42+
- type: view-module-new
43+
language: cpp
44+
- type: module-legacy
45+
language: kotlin-objc
46+
- type: module-mixed
4147
language: kotlin-objc
42-
- os: macos-14
43-
language: kotlin-swift
44-
- type: module-new
45-
language: java-swift
4648
- type: module-new
49+
language: kotlin-objc
50+
include:
51+
- os: ubuntu-latest
52+
type: view-legacy
4753
language: kotlin-swift
48-
- type: module-mixed
49-
language: java-swift
50-
- type: module-mixed
54+
- os: macos-14
55+
type: view-legacy
5156
language: kotlin-swift
52-
- type: view-new
53-
language: java-swift
54-
- type: view-new
57+
- os: ubuntu-latest
58+
type: module-legacy
5559
language: kotlin-swift
56-
- type: view-mixed
57-
language: java-swift
58-
- type: view-mixed
60+
- os: macos-14
61+
type: module-legacy
5962
language: kotlin-swift
60-
include:
6163
- os: ubuntu-latest
6264
type: library
6365
language: js
64-
- os: ubuntu-latest
65-
type: module-legacy
66-
language: cpp
67-
- os: ubuntu-latest
68-
type: module-mixed
69-
language: cpp
70-
- os: ubuntu-latest
71-
type: module-new
72-
language: cpp
73-
- os: macos-14
74-
type: module-legacy
75-
language: cpp
76-
- os: macos-14
77-
type: module-mixed
78-
language: cpp
79-
- os: macos-14
80-
type: module-new
81-
language: cpp
8266

8367
concurrency:
8468
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }}
@@ -138,17 +122,13 @@ jobs:
138122
working-directory: ${{ env.work_dir }}
139123
run: |
140124
# Build Android for only some matrices to skip redundant builds
141-
if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
142-
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
125+
if [[ ${{ matrix.os }} == ubuntu-latest ]] && [[ ${{ matrix.language }} != js ]] ; then
143126
echo "android_build=1" >> $GITHUB_ENV
144-
fi
145127
fi
146128
147129
# Build iOS for only some matrices to skip redundant builds
148-
if [[ ${{ matrix.os }} == macos-14 ]]; then
149-
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
130+
if [[ ${{ matrix.os }} == macos-14 ]] && [[ ${{ matrix.language }} != js ]]; then
150131
echo "ios_build=1" >> $GITHUB_ENV
151-
fi
152132
fi
153133
154134
- name: Cache turborepo

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

Lines changed: 96 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,70 @@ const NATIVE_COMMON_EXAMPLE_FILES = path.resolve(
3838
);
3939

4040
const NATIVE_FILES = {
41-
module_legacy: path.resolve(__dirname, '../templates/native-library-legacy'),
42-
module_new: path.resolve(__dirname, '../templates/native-library-new'),
43-
module_mixed: path.resolve(__dirname, '../templates/native-library-mixed'),
44-
view_legacy: path.resolve(__dirname, '../templates/native-view-legacy'),
45-
view_mixed: path.resolve(__dirname, '../templates/native-view-mixed'),
46-
view_new: path.resolve(__dirname, '../templates/native-view-new'),
47-
} as const;
48-
49-
const JAVA_FILES = {
50-
module_legacy: path.resolve(__dirname, '../templates/java-library-legacy'),
51-
module_new: path.resolve(__dirname, '../templates/java-library-new'),
52-
module_mixed: path.resolve(__dirname, '../templates/java-library-mixed'),
53-
view_legacy: path.resolve(__dirname, '../templates/java-view-legacy'),
54-
view_mixed: path.resolve(__dirname, '../templates/java-view-mixed'),
55-
view_new: path.resolve(__dirname, '../templates/java-view-new'),
41+
'module-legacy': path.resolve(
42+
__dirname,
43+
'../templates/native-library-legacy'
44+
),
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-module-legacy': path.resolve(
49+
__dirname,
50+
'../templates/native-view-library-legacy'
51+
),
52+
'view-module-mixed': path.resolve(
53+
__dirname,
54+
'../templates/native-view-library-mixed'
55+
),
56+
'view-module-new': path.resolve(
57+
__dirname,
58+
'../templates/native-view-library-new'
59+
),
5660
} as const;
5761

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

6580
const KOTLIN_FILES = {
66-
module_legacy: path.resolve(__dirname, '../templates/kotlin-library-legacy'),
67-
module_new: path.resolve(__dirname, '../templates/kotlin-library-new'),
68-
module_mixed: path.resolve(__dirname, '../templates/kotlin-library-mixed'),
69-
view_legacy: path.resolve(__dirname, '../templates/kotlin-view-legacy'),
70-
view_mixed: path.resolve(__dirname, '../templates/kotlin-view-mixed'),
71-
view_new: path.resolve(__dirname, '../templates/kotlin-view-new'),
81+
'module-legacy': path.resolve(
82+
__dirname,
83+
'../templates/kotlin-library-legacy'
84+
),
85+
'module-new': path.resolve(__dirname, '../templates/kotlin-library-new'),
86+
'module-mixed': path.resolve(__dirname, '../templates/kotlin-library-mixed'),
87+
'view-legacy': path.resolve(__dirname, '../templates/kotlin-view-legacy'),
88+
'view-module-legacy': path.resolve(
89+
__dirname,
90+
'../templates/kotlin-view-library-legacy'
91+
),
92+
'view-module-mixed': path.resolve(
93+
__dirname,
94+
'../templates/kotlin-view-library-mixed'
95+
),
96+
'view-module-new': path.resolve(
97+
__dirname,
98+
'../templates/kotlin-view-library-new'
99+
),
72100
} as const;
73101

74102
const SWIFT_FILES = {
75-
module_legacy: path.resolve(__dirname, '../templates/swift-library-legacy'),
76-
view_legacy: path.resolve(__dirname, '../templates/swift-view-legacy'),
103+
'module-legacy': path.resolve(__dirname, '../templates/swift-library-legacy'),
104+
'view-legacy': path.resolve(__dirname, '../templates/swift-view-legacy'),
77105
} as const;
78106

79107
type ArgName =
@@ -89,22 +117,17 @@ type ArgName =
89117
| 'example'
90118
| 'react-native-version';
91119

92-
type ProjectLanguages =
93-
| 'java-objc'
94-
| 'java-swift'
95-
| 'kotlin-objc'
96-
| 'kotlin-swift'
97-
| 'cpp'
98-
| 'js';
120+
type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js';
99121

100122
type ProjectType =
123+
| 'library'
101124
| 'module-legacy'
102-
| 'module-new'
103125
| 'module-mixed'
104-
| 'view-mixed'
105-
| 'view-new'
126+
| 'module-new'
106127
| 'view-legacy'
107-
| 'library';
128+
| 'view-module-legacy'
129+
| 'view-module-mixed'
130+
| 'view-module-new';
108131

109132
type Answers = {
110133
slug: string;
@@ -127,37 +150,13 @@ const LANGUAGE_CHOICES: {
127150
{
128151
title: 'Kotlin & Objective-C',
129152
value: 'kotlin-objc',
130-
types: [
131-
'module-legacy',
132-
'module-new',
133-
'module-mixed',
134-
'view-mixed',
135-
'view-new',
136-
'view-legacy',
137-
],
138-
},
139-
{
140-
title: 'Java & Objective-C',
141-
value: 'java-objc',
142-
types: [
143-
'module-legacy',
144-
'module-new',
145-
'module-mixed',
146-
'view-mixed',
147-
'view-new',
148-
'view-legacy',
149-
],
153+
types: ['view-module-legacy', 'view-module-mixed', 'view-module-new'],
150154
},
151155
{
152156
title: 'Kotlin & Swift',
153157
value: 'kotlin-swift',
154158
types: ['module-legacy', 'view-legacy'],
155159
},
156-
{
157-
title: 'Java & Swift',
158-
value: 'java-swift',
159-
types: ['module-legacy', 'view-legacy'],
160-
},
161160
{
162161
title: 'C++ for Android & iOS',
163162
value: 'cpp',
@@ -178,6 +177,21 @@ const TYPE_CHOICES: {
178177
value: ProjectType;
179178
description: string;
180179
}[] = [
180+
{
181+
title: 'Fabric view and Turbo module with backward compat',
182+
value: 'view-module-mixed',
183+
description: BACKCOMPAT_DESCRIPTION,
184+
},
185+
{
186+
title: 'Fabric view and Turbo module',
187+
value: 'view-module-new',
188+
description: NEWARCH_DESCRIPTION,
189+
},
190+
{
191+
title: 'Native module and Native view',
192+
value: 'view-module-legacy',
193+
description: 'bridge for native APIs and views to JS',
194+
},
181195
{
182196
title: 'JavaScript library',
183197
value: 'library',
@@ -203,16 +217,6 @@ const TYPE_CHOICES: {
203217
value: 'module-new',
204218
description: NEWARCH_DESCRIPTION,
205219
},
206-
{
207-
title: 'Fabric view with backward compat',
208-
value: 'view-mixed',
209-
description: BACKCOMPAT_DESCRIPTION,
210-
},
211-
{
212-
title: 'Fabric view',
213-
value: 'view-new',
214-
description: NEWARCH_DESCRIPTION,
215-
},
216220
];
217221

218222
const args: Record<ArgName, yargs.Options> = {
@@ -501,8 +505,8 @@ async function create(argv: yargs.Arguments<any>) {
501505
authorEmail,
502506
authorUrl,
503507
repoUrl,
504-
type = 'module-mixed',
505-
languages = type === 'library' ? 'js' : 'java-objc',
508+
type = 'view-module-mixed',
509+
languages = type === 'library' ? 'js' : 'kotlin-objc',
506510
example: hasExample,
507511
reactNativeVersion,
508512
} = {
@@ -561,13 +565,11 @@ async function create(argv: yargs.Arguments<any>) {
561565
version = FALLBACK_BOB_VERSION;
562566
}
563567

564-
const moduleType = type.startsWith('view-') ? 'view' : 'module';
565-
const arch =
566-
type === 'module-new' || type === 'view-new'
567-
? 'new'
568-
: type === 'module-mixed' || type === 'view-mixed'
569-
? 'mixed'
570-
: 'legacy';
568+
const arch = type.endsWith('new')
569+
? 'new'
570+
: type.endsWith('mixed')
571+
? 'mixed'
572+
: 'legacy';
571573

572574
const example =
573575
hasExample && !local ? (type === 'library' ? 'expo' : 'native') : 'none';
@@ -610,10 +612,9 @@ async function create(argv: yargs.Arguments<any>) {
610612
native: languages !== 'js',
611613
arch,
612614
cpp: languages === 'cpp',
613-
kotlin: languages === 'kotlin-objc' || languages === 'kotlin-swift',
614-
swift: languages === 'java-swift' || languages === 'kotlin-swift',
615-
view: moduleType === 'view',
616-
module: moduleType === 'module',
615+
swift: languages === 'kotlin-swift',
616+
view: type.includes('view'),
617+
module: type.includes('module'),
617618
},
618619
author: {
619620
name: authorName,
@@ -697,7 +698,7 @@ async function create(argv: yargs.Arguments<any>) {
697698
}
698699
}
699700

700-
if (languages === 'js') {
701+
if (type === 'library') {
701702
await copyDir(JS_FILES, folder);
702703
await copyDir(EXPO_FILES, folder);
703704
} else {
@@ -714,29 +715,18 @@ async function create(argv: yargs.Arguments<any>) {
714715
await copyDir(NATIVE_COMMON_EXAMPLE_FILES, folder);
715716
}
716717

717-
if (moduleType === 'module') {
718-
await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder);
719-
} else {
720-
await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder);
721-
}
718+
await copyDir(NATIVE_FILES[type], folder);
722719

723-
if (options.project.swift) {
724-
await copyDir(SWIFT_FILES[`${moduleType}_legacy`], folder);
720+
if (
721+
type === 'view-legacy' ||
722+
(type === 'module-legacy' && options.project.swift)
723+
) {
724+
await copyDir(SWIFT_FILES[type], folder);
725725
} else {
726-
if (moduleType === 'module') {
727-
await copyDir(OBJC_FILES[`${moduleType}_common`], folder);
728-
} else {
729-
await copyDir(OBJC_FILES[`view_${arch}`], folder);
730-
}
726+
await copyDir(OBJC_FILES[type], folder);
731727
}
732728

733-
const templateType = `${moduleType}_${arch}` as const;
734-
735-
if (options.project.kotlin) {
736-
await copyDir(KOTLIN_FILES[templateType], folder);
737-
} else {
738-
await copyDir(JAVA_FILES[templateType], folder);
739-
}
729+
await copyDir(KOTLIN_FILES[type], folder);
740730

741731
if (options.project.cpp) {
742732
await copyDir(CPP_FILES, folder);

0 commit comments

Comments
 (0)