Skip to content

Commit 0a74b6b

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

File tree

13 files changed

+18
-110
lines changed

13 files changed

+18
-110
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/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.

packages/create-react-native-library/templates/kotlin-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,10 @@ package com.<%- project.package %>
33
import com.facebook.react.bridge.ReactApplicationContext
44
import com.facebook.react.module.annotations.ReactModule
55

6-
@ReactModule(name = <%- project.name -%>Module.NAME)
76
class <%- project.name -%>Module(reactContext: ReactApplicationContext) :
87
Native<%- project.name -%>Spec(reactContext) {
98

10-
override fun getName(): String {
11-
return NAME
12-
}
13-
14-
// Example method
15-
// See https://reactnative.dev/docs/native-modules-android
169
override fun multiply(a: Double, b: Double): Double {
1710
return a * b
1811
}
19-
20-
companion object {
21-
const val NAME = "<%- project.name -%>"
22-
}
2312
}
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: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,35 +111,18 @@ android {
111111
}
112112
}
113113

114-
lintOptions {
114+
lint {
115115
disable "GradleCompatible"
116116
}
117117

118118
compileOptions {
119119
sourceCompatibility JavaVersion.VERSION_1_8
120120
targetCompatibility JavaVersion.VERSION_1_8
121121
}
122-
123-
sourceSets {
124-
main {
125-
java.srcDirs += [
126-
"generated/java",
127-
"generated/jni"
128-
]
129-
}
130-
}
131122
}
132123

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

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.

packages/create-react-native-library/templates/nitro-module/android/src/main/cpp/cpp-adapter.cpp renamed to packages/create-react-native-library/templates/nitro-common/android/src/main/cpp/cpp-adapter.cpp

File renamed without changes.

packages/create-react-native-library/templates/nitro-view/nitro.json renamed to packages/create-react-native-library/templates/nitro-common/nitro.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
},
1010
"autolinking": {
1111
"<%- project.name -%>": {
12-
"swift": "Hybrid<%- project.name -%>",
13-
"kotlin": "Hybrid<%- project.name -%>"
12+
"swift": "<% if (project.viewConfig === 'nitro-view') { -%>Hybrid<% } -%><%- project.name -%>",
13+
"kotlin": "<% if (project.viewConfig === 'nitro-view') { -%>Hybrid<% } -%><%- project.name -%>"
1414
}
1515
},
1616
"ignorePaths": ["node_modules"]

packages/create-react-native-library/templates/nitro-module/nitro.json

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

0 commit comments

Comments
 (0)