Skip to content

Commit fed5bef

Browse files
committed
refactor: cleanup module templates
1 parent 009ccd0 commit fed5bef

File tree

15 files changed

+55
-140
lines changed

15 files changed

+55
-140
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const NATIVE_COMMON_EXAMPLE_FILES = path.resolve(
7272
__dirname,
7373
'../templates/native-common-example'
7474
);
75+
const NITRO_COMMON_FILES = path.resolve(__dirname, '../templates/nitro-common');
7576

7677
const NATIVE_FILES = {
7778
module_new: path.resolve(__dirname, '../templates/native-library-new'),
@@ -211,11 +212,13 @@ export async function applyTemplates(
211212
}
212213

213214
if (config.project.moduleConfig === 'nitro-modules') {
215+
await applyTemplate(config, NITRO_COMMON_FILES, folder);
214216
await applyTemplate(config, NATIVE_FILES['module_nitro'], folder);
215217
return;
216218
}
217219

218220
if (config.project.viewConfig === 'nitro-view') {
221+
await applyTemplate(config, NITRO_COMMON_FILES, folder);
219222
await applyTemplate(config, NATIVE_FILES['view_nitro'], folder);
220223
return;
221224
}

packages/create-react-native-library/templates/common/$.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
runs-on: macos-latest
128128

129129
env:
130-
XCODE_VERSION: 16.3
130+
XCODE_VERSION: 26
131131
TURBO_CACHE_DIR: .turbo/ios
132132
RCT_USE_RN_DEP: 1
133133
RCT_USE_PREBUILT_RNCORE: 1

packages/create-react-native-library/templates/common/$package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@
135135
<% if (project.viewConfig === 'fabric-view') { -%>
136136
},
137137
"ios": {
138-
"componentProvider": {
139-
"<%- project.name -%>View": "<%- project.name -%>View"
138+
"components": {
139+
"<%- project.name -%>View": {
140+
"className": "<%- project.name -%>View"
141+
}
140142
}
141143
<% } -%>
142144
}

packages/create-react-native-library/templates/example-common/example/metro.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const path = require('path');
2-
const { getDefaultConfig } = require('@react-native/metro-config');
2+
const { getDefaultConfig } = require('<% if (example === 'expo') { -%>@expo/metro-config<% } else { -%>@react-native/metro-config<% } -%>');
33
const { withMetroConfig } = require('react-native-monorepo-config');
44

55
const root = path.resolve(__dirname, '..');
@@ -10,7 +10,9 @@ const root = path.resolve(__dirname, '..');
1010
*
1111
* @type {import('metro-config').MetroConfig}
1212
*/
13-
module.exports = withMetroConfig(getDefaultConfig(__dirname), {
13+
const config = withMetroConfig(getDefaultConfig(__dirname), {
1414
root,
1515
dirname: __dirname,
1616
});
17+
18+
module.exports = config;

packages/create-react-native-library/templates/expo-library/example/metro.config.js

Lines changed: 0 additions & 20 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
package com.<%- project.package %>
22

33
import com.facebook.react.bridge.ReactApplicationContext
4-
import com.facebook.react.module.annotations.ReactModule
54

6-
@ReactModule(name = <%- project.name -%>Module.NAME)
75
class <%- project.name -%>Module(reactContext: ReactApplicationContext) :
86
Native<%- project.name -%>Spec(reactContext) {
97

10-
override fun getName(): String {
11-
return NAME
12-
}
13-
14-
// Example method
15-
// See https://reactnative.dev/docs/native-modules-android
168
override fun multiply(a: Double, b: Double): Double {
179
return a * b
1810
}
1911

2012
companion object {
21-
const val NAME = "<%- project.name -%>"
13+
const val NAME = Native<%- project.name -%>Spec.NAME
2214
}
2315
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package com.<%- project.package %>
22

3-
import com.facebook.react.ReactPackage
3+
import com.facebook.react.BaseReactPackage
44
import com.facebook.react.bridge.NativeModule
55
import com.facebook.react.bridge.ReactApplicationContext
6+
import com.facebook.react.module.model.ReactModuleInfoProvider
67
import com.facebook.react.uimanager.ViewManager
7-
import java.util.ArrayList
88

9-
class <%- project.name -%>ViewPackage : ReactPackage {
9+
class <%- project.name -%>ViewPackage : BaseReactPackage() {
1010
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
11-
val viewManagers: MutableList<ViewManager<*, *>> = ArrayList()
12-
viewManagers.add(<%- project.name -%>ViewManager())
13-
return viewManagers
11+
return listOf(<%- project.name -%>ViewManager())
1412
}
1513

16-
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
17-
return emptyList()
18-
}
14+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
15+
16+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { emptyMap() }
1917
}

packages/create-react-native-library/templates/native-common/android/build.gradle

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
buildscript {
2-
ext.getExtOrDefault = {name ->
3-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['<%- project.name -%>_' + name]
2+
ext.<%- project.name -%> = [
3+
kotlinVersion: "2.0.21",
4+
minSdkVersion: 24,
5+
compileSdkVersion: 36,
6+
targetSdkVersion: 36
7+
]
8+
9+
ext.getExtOrDefault = { prop ->
10+
if (rootProject.ext.has(prop)) {
11+
return rootProject.ext.get(prop)
12+
}
13+
14+
return <%- project.name -%>[prop]
415
}
516

617
repositories {
@@ -30,22 +41,18 @@ apply from: '../nitrogen/generated/android/<%- project.package_cpp -%>+autolinki
3041

3142
apply plugin: "com.facebook.react"
3243

33-
def getExtOrIntegerDefault(name) {
34-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["<%- project.name -%>_" + name]).toInteger()
35-
}
36-
3744
android {
3845
<% if (project.moduleConfig === 'nitro-modules' || project.viewConfig === 'nitro-view') { -%>
3946
namespace "com.margelo.nitro.<%- project.package -%>"
4047
<% } else { -%>
4148
namespace "com.<%- project.package -%>"
4249
<% } -%>
4350

44-
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
51+
compileSdkVersion getExtOrDefault("compileSdkVersion")
4552

4653
defaultConfig {
47-
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
48-
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
54+
minSdkVersion getExtOrDefault("minSdkVersion")
55+
targetSdkVersion getExtOrDefault("targetSdkVersion")
4956
<% if (project.cpp || project.moduleConfig === 'nitro-modules' || project.viewConfig === 'nitro-view') { -%>
5057

5158
externalNativeBuild {
@@ -78,22 +85,22 @@ android {
7885

7986
packagingOptions {
8087
excludes = [
81-
"META-INF",
82-
"META-INF/**",
83-
"**/libc++_shared.so",
84-
"**/libfbjni.so",
85-
"**/libjsi.so",
86-
"**/libfolly_json.so",
87-
"**/libfolly_runtime.so",
88-
"**/libglog.so",
89-
"**/libhermes.so",
90-
"**/libhermes-executor-debug.so",
91-
"**/libhermes_executor.so",
92-
"**/libreactnative.so",
93-
"**/libreactnativejni.so",
94-
"**/libturbomodulejsijni.so",
95-
"**/libreact_nativemodule_core.so",
96-
"**/libjscexecutor.so"
88+
"META-INF",
89+
"META-INF/**",
90+
"**/libc++_shared.so",
91+
"**/libfbjni.so",
92+
"**/libjsi.so",
93+
"**/libfolly_json.so",
94+
"**/libfolly_runtime.so",
95+
"**/libglog.so",
96+
"**/libhermes.so",
97+
"**/libhermes-executor-debug.so",
98+
"**/libhermes_executor.so",
99+
"**/libreactnative.so",
100+
"**/libreactnativejni.so",
101+
"**/libturbomodulejsijni.so",
102+
"**/libreact_nativemodule_core.so",
103+
"**/libjscexecutor.so"
97104
]
98105
}
99106
<% } -%>
@@ -111,35 +118,18 @@ android {
111118
}
112119
}
113120

114-
lintOptions {
121+
lint {
115122
disable "GradleCompatible"
116123
}
117124

118125
compileOptions {
119126
sourceCompatibility JavaVersion.VERSION_1_8
120127
targetCompatibility JavaVersion.VERSION_1_8
121128
}
122-
123-
sourceSets {
124-
main {
125-
java.srcDirs += [
126-
"generated/java",
127-
"generated/jni"
128-
]
129-
}
130-
}
131129
}
132130

133-
repositories {
134-
mavenCentral()
135-
google()
136-
}
137-
138-
def kotlin_version = getExtOrDefault("kotlinVersion")
139-
140131
dependencies {
141132
implementation "com.facebook.react:react-android"
142-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
143133
<% if (project.moduleConfig === 'nitro-modules' || project.viewConfig === 'nitro-view') { -%>
144134
implementation project(":react-native-nitro-modules")
145135
<% } -%>

packages/create-react-native-library/templates/native-common/android/gradle.properties

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

packages/create-react-native-library/templates/nitro-module/android/CMakeLists.txt renamed to packages/create-react-native-library/templates/nitro-common/android/CMakeLists.txt

File renamed without changes.

0 commit comments

Comments
 (0)