Skip to content

Commit 34b1f80

Browse files
authored
refactor: drop backward compatible templates (#712)
As of React Native 0.76, the new architecture is now default. So this moves the templates with new architecture up. New libraries should start with new arch template. For legacy usage, we still have the legacy template for now. Old architecture libraries still work in new architecture via compat layer. So the backward compatible templates are unnecessary. They are also difficult to maintain and are currently broken, so I'm removing them.
1 parent 2553e24 commit 34b1f80

File tree

36 files changed

+129
-590
lines changed

36 files changed

+129
-590
lines changed

.github/workflows/build-templates.yml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ jobs:
3131
- macos-14 # macos latest defaults to macos 12 at the moment.
3232
type:
3333
- module-legacy
34-
- module-mixed
3534
- module-new
3635
- view-legacy
37-
- view-mixed
3836
- view-new
3937
language:
4038
- kotlin-objc
@@ -44,41 +42,17 @@ jobs:
4442
exclude:
4543
- type: module-new
4644
language: kotlin-swift
47-
- type: module-mixed
48-
language: kotlin-swift
4945
- type: view-new
5046
language: kotlin-swift
51-
- type: view-mixed
52-
language: kotlin-swift
5347
include:
5448
- os: ubuntu-latest
5549
type: library
5650
language: js
5751
arch: auto
58-
- os: ubuntu-latest
59-
type: module-mixed
60-
language: kotlin-objc
61-
arch: new
62-
- os: macos-14
63-
type: module-mixed
64-
language: kotlin-objc
65-
arch: new
66-
- os: ubuntu-latest
67-
type: view-mixed
68-
language: kotlin-objc
69-
arch: new
70-
- os: macos-14
71-
type: view-mixed
72-
language: kotlin-objc
73-
arch: new
7452
- os: ubuntu-latest
7553
type: module-legacy
7654
language: cpp
7755
arch: auto
78-
- os: ubuntu-latest
79-
type: module-mixed
80-
language: cpp
81-
arch: auto
8256
- os: ubuntu-latest
8357
type: module-new
8458
language: cpp
@@ -87,10 +61,6 @@ jobs:
8761
type: module-legacy
8862
language: cpp
8963
arch: auto
90-
- os: macos-14
91-
type: module-mixed
92-
language: cpp
93-
arch: auto
9464
- os: macos-14
9565
type: module-new
9666
language: cpp

packages/create-react-native-library/src/exampleApp/generateExampleApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default async function generateExampleApp({
5151
}: {
5252
type: ExampleApp;
5353
dest: string;
54-
arch: 'new' | 'mixed' | 'legacy';
54+
arch: 'new' | 'legacy';
5555
project: {
5656
slug: string;
5757
name: string;

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

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ export type ArgName =
2121
export type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js';
2222

2323
export type ProjectType =
24-
| 'module-legacy'
2524
| 'module-new'
26-
| 'module-mixed'
27-
| 'view-mixed'
2825
| 'view-new'
26+
| 'module-legacy'
2927
| 'view-legacy'
3028
| 'library';
3129

@@ -37,14 +35,7 @@ const LANGUAGE_CHOICES: {
3735
{
3836
title: 'Kotlin & Objective-C',
3937
value: 'kotlin-objc',
40-
types: [
41-
'module-legacy',
42-
'module-new',
43-
'module-mixed',
44-
'view-mixed',
45-
'view-new',
46-
'view-legacy',
47-
],
38+
types: ['module-new', 'view-new', 'module-legacy', 'view-legacy'],
4839
},
4940
{
5041
title: 'Kotlin & Swift',
@@ -54,7 +45,7 @@ const LANGUAGE_CHOICES: {
5445
{
5546
title: 'C++ for Android & iOS',
5647
value: 'cpp',
57-
types: ['module-legacy', 'module-mixed', 'module-new'],
48+
types: ['module-new', 'module-legacy'],
5849
},
5950
{
6051
title: 'JavaScript for Android, iOS & Web',
@@ -88,48 +79,35 @@ const EXAMPLE_CHOICES = (
8879
] as const
8980
).filter((choice) => !choice.disabled);
9081

91-
const NEWARCH_DESCRIPTION = 'requires new arch';
92-
const BACKCOMPAT_DESCRIPTION = 'supports new arch';
93-
9482
const TYPE_CHOICES: {
9583
title: string;
9684
value: ProjectType;
9785
description: string;
9886
}[] = [
9987
{
100-
title: 'JavaScript library',
101-
value: 'library',
102-
description: 'supports Expo Go and Web',
103-
},
104-
{
105-
title: 'Native module',
106-
value: 'module-legacy',
107-
description: 'bridge for native APIs to JS',
108-
},
109-
{
110-
title: 'Native view',
111-
value: 'view-legacy',
112-
description: 'bridge for native views to JS',
88+
title: 'Turbo module',
89+
value: 'module-new',
90+
description: 'integration for native APIs to JS',
11391
},
11492
{
115-
title: 'Turbo module with backward compat',
116-
value: 'module-mixed',
117-
description: BACKCOMPAT_DESCRIPTION,
93+
title: 'Fabric view',
94+
value: 'view-new',
95+
description: 'integration for native views to JS',
11896
},
11997
{
120-
title: 'Turbo module',
121-
value: 'module-new',
122-
description: NEWARCH_DESCRIPTION,
98+
title: 'Legacy Native module',
99+
value: 'module-legacy',
100+
description: 'bridge for native APIs to JS (old architecture)',
123101
},
124102
{
125-
title: 'Fabric view with backward compat',
126-
value: 'view-mixed',
127-
description: BACKCOMPAT_DESCRIPTION,
103+
title: 'Legacy Native view',
104+
value: 'view-legacy',
105+
description: 'bridge for native views to JS (old architecture)',
128106
},
129107
{
130-
title: 'Fabric view',
131-
value: 'view-new',
132-
description: NEWARCH_DESCRIPTION,
108+
title: 'JavaScript library',
109+
value: 'library',
110+
description: 'supports Expo Go and Web',
133111
},
134112
];
135113

@@ -190,7 +168,7 @@ export const acceptedArgs: Record<ArgName, yargs.Options> = {
190168
} as const;
191169

192170
export type Args = Record<ArgName | 'name', string>;
193-
export type SupportedArchitecture = 'new' | 'mixed' | 'legacy';
171+
export type SupportedArchitecture = 'new' | 'legacy';
194172
export type ExampleApp = 'none' | 'test-app' | 'expo' | 'vanilla';
195173

196174
export type Answers = {

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,21 @@ const BINARIES = [
4040
];
4141

4242
const COMMON_FILES = path.resolve(__dirname, '../templates/common');
43-
const COMMON_EXAMPLE_FILES = path.resolve(
43+
const COMMON_LOCAL_FILES = path.resolve(__dirname, '../templates/common-local');
44+
const EXAMPLE_COMMON_FILES = path.resolve(
4445
__dirname,
45-
'../templates/common-example'
46+
'../templates/example-common'
4647
);
47-
const COMMON_LOCAL_FILES = path.resolve(__dirname, '../templates/common-local');
48+
const EXAMPLE_MODULE_LEGACY_FILES = path.resolve(
49+
__dirname,
50+
'../templates/example-module-legacy'
51+
);
52+
const EXAMPLE_MODULE_NEW_FILES = path.resolve(
53+
__dirname,
54+
'../templates/example-module-new'
55+
);
56+
const EXAMPLE_VIEW_FILES = path.resolve(__dirname, '../templates/example-view');
57+
4858
const JS_FILES = path.resolve(__dirname, '../templates/js-library');
4959
const EXPO_FILES = path.resolve(__dirname, '../templates/expo-library');
5060
const CPP_FILES = path.resolve(__dirname, '../templates/cpp-library');
@@ -60,25 +70,20 @@ const NATIVE_COMMON_EXAMPLE_FILES = path.resolve(
6070
const NATIVE_FILES = {
6171
module_legacy: path.resolve(__dirname, '../templates/native-library-legacy'),
6272
module_new: path.resolve(__dirname, '../templates/native-library-new'),
63-
module_mixed: path.resolve(__dirname, '../templates/native-library-mixed'),
6473
view_legacy: path.resolve(__dirname, '../templates/native-view-legacy'),
65-
view_mixed: path.resolve(__dirname, '../templates/native-view-mixed'),
6674
view_new: path.resolve(__dirname, '../templates/native-view-new'),
6775
} as const;
6876

6977
const OBJC_FILES = {
7078
module_common: path.resolve(__dirname, '../templates/objc-library'),
7179
view_legacy: path.resolve(__dirname, '../templates/objc-view-legacy'),
72-
view_mixed: path.resolve(__dirname, '../templates/objc-view-mixed'),
7380
view_new: path.resolve(__dirname, '../templates/objc-view-new'),
7481
} as const;
7582

7683
const KOTLIN_FILES = {
7784
module_legacy: path.resolve(__dirname, '../templates/kotlin-library-legacy'),
7885
module_new: path.resolve(__dirname, '../templates/kotlin-library-new'),
79-
module_mixed: path.resolve(__dirname, '../templates/kotlin-library-mixed'),
8086
view_legacy: path.resolve(__dirname, '../templates/kotlin-view-legacy'),
81-
view_mixed: path.resolve(__dirname, '../templates/kotlin-view-mixed'),
8287
view_new: path.resolve(__dirname, '../templates/kotlin-view-new'),
8388
} as const;
8489

@@ -99,11 +104,7 @@ export function generateTemplateConfiguration({
99104
const { slug, languages, type } = answers;
100105

101106
const arch =
102-
type === 'module-new' || type === 'view-new'
103-
? 'new'
104-
: type === 'module-mixed' || type === 'view-mixed'
105-
? 'mixed'
106-
: 'legacy';
107+
type === 'module-legacy' || type === 'view-legacy' ? 'legacy' : 'new';
107108

108109
const project = slug.replace(/^(react-native-|@[^/]+\/)/, '');
109110
let namespace: string | undefined;
@@ -169,7 +170,17 @@ export async function applyTemplates(
169170
await applyTemplate(config, COMMON_FILES, folder);
170171

171172
if (config.example !== 'none') {
172-
await applyTemplate(config, COMMON_EXAMPLE_FILES, folder);
173+
await applyTemplate(config, EXAMPLE_COMMON_FILES, folder);
174+
175+
if (config.project.view) {
176+
await applyTemplate(config, EXAMPLE_VIEW_FILES, folder);
177+
} else {
178+
if (config.project.arch === 'legacy') {
179+
await applyTemplate(config, EXAMPLE_MODULE_LEGACY_FILES, folder);
180+
} else {
181+
await applyTemplate(config, EXAMPLE_MODULE_NEW_FILES, folder);
182+
}
183+
}
173184
}
174185
}
175186

packages/create-react-native-library/templates/common-example/example/src/App.tsx

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

packages/create-react-native-library/templates/common/CONTRIBUTING.md

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,6 @@ To run the example app on iOS:
4949
yarn example ios
5050
```
5151

52-
<% if (project.arch === 'mixed') { -%>
53-
By default, the example is configured to build with the old architecture. To run the example with the new architecture, you can do the following:
54-
55-
1. For Android, run:
56-
57-
```sh
58-
ORG_GRADLE_PROJECT_newArchEnabled=true yarn example android
59-
```
60-
61-
2. For iOS, run:
62-
63-
```sh
64-
cd example/ios
65-
RCT_NEW_ARCH_ENABLED=1 pod install
66-
cd -
67-
yarn example ios
68-
```
69-
70-
If you are building for a different architecture than your previous build, make sure to remove the build folders first. You can run the following command to cleanup all build folders:
71-
72-
```sh
73-
yarn clean
74-
```
75-
76-
<% } -%>
7752
<% if (project.arch !== 'legacy') { -%>
7853
To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this:
7954

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useState, useEffect } from 'react';
2+
import { Text, View, StyleSheet } from 'react-native';
3+
import { multiply } from '<%- project.slug -%>';
4+
5+
export default function App() {
6+
const [result, setResult] = useState<number | undefined>();
7+
8+
useEffect(() => {
9+
multiply(3, 7).then(setResult);
10+
}, []);
11+
12+
return (
13+
<View style={styles.container}>
14+
<Text>Result: {result}</Text>
15+
</View>
16+
);
17+
}
18+
19+
const styles = StyleSheet.create({
20+
container: {
21+
flex: 1,
22+
alignItems: 'center',
23+
justifyContent: 'center',
24+
},
25+
});

0 commit comments

Comments
 (0)