diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index 73d5df0b9..f6b3412cd 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -30,35 +30,19 @@ jobs: - ubuntu - macos type: - - turbo-module - - fabric-view - - legacy-module - - legacy-view - - nitro-module - language: - - kotlin-objc - - kotlin-swift - - cpp - exclude: - - type: turbo-module - language: kotlin-swift - - type: fabric-view - language: kotlin-swift - - type: fabric-view - language: cpp - - type: legacy-view - language: cpp - - type: nitro-module + - name: turbo-module language: kotlin-objc - - type: nitro-module - language: cpp + - name: fabric-view + language: kotlin-objc + - name: nitro-module + language: kotlin-swift include: - os: ubuntu - type: library - language: js + type.name: library + type.language: js concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }} + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type.name }}-${{ matrix.type.language }} cancel-in-progress: true runs-on: ${{ matrix.os }}-latest @@ -76,7 +60,7 @@ jobs: - name: Get working directory run: | - echo "work_dir=${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }}" >> $GITHUB_ENV + echo "work_dir=${{ matrix.os }}-${{ matrix.type.name }}-${{ matrix.type.language }}" >> $GITHUB_ENV - name: Create library run: | @@ -88,9 +72,9 @@ jobs: --author-email test@test \ --author-url https://test.test \ --repo-url https://test.test \ - --type ${{ matrix.type }} \ - --languages ${{ matrix.language }} \ - --example ${{ matrix.language == 'js' && 'expo' || 'vanilla' }} \ + --type ${{ matrix.type.name }} \ + --languages ${{ matrix.type.language }} \ + --example ${{ matrix.type.language == 'js' && 'expo' || 'vanilla' }} \ --no-local - name: Restore dependencies of library @@ -135,14 +119,14 @@ jobs: run: | # Build Android for only some matrices to skip redundant builds if [[ ${{ matrix.os }} == ubuntu ]]; then - if [[ ${{ matrix.type }} == *-view && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == *-module && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == *-module && ${{ matrix.language }} == cpp ]]; then + if [[ ${{ matrix.type.name }} == *-view && ${{ matrix.type.language }} == *-objc ]] || [[ ${{ matrix.type.name }} == *-module && ${{ matrix.type.language }} == *-objc ]]; then echo "android_build=1" >> $GITHUB_ENV fi fi # Build iOS for only some matrices to skip redundant builds if [[ ${{ matrix.os }} == macos ]]; then - if [[ ${{ matrix.type }} == *-view && ${{ matrix.language }} == kotlin-* ]] || [[ ${{ matrix.type }} == *-module && ${{ matrix.language }} == kotlin-* ]] || [[ ${{ matrix.type }} == *-module && ${{ matrix.language }} == cpp ]]; then + if [[ ${{ matrix.type.name }} == *-view && ${{ matrix.type.language }} == kotlin-* ]] || [[ ${{ matrix.type.name }} == *-module && ${{ matrix.type.language }} == kotlin-* ]]; then echo "ios_build=1" >> $GITHUB_ENV fi fi @@ -153,9 +137,9 @@ jobs: with: path: | ${{ env.work_dir }}/.turbo - key: ${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-${{ hashFiles(format('{0}/yarn.lock', env.work_dir)) }} + key: ${{ runner.os }}-library-turborepo-${{ matrix.type.name }}-${{ matrix.type.language }}-${{ hashFiles(format('{0}/yarn.lock', env.work_dir)) }} restore-keys: | - ${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}- + ${{ runner.os }}-library-turborepo-${{ matrix.type.name }}-${{ matrix.type.language }}- - name: Check turborepo cache if: env.android_build == 1 || env.ios_build == 1 @@ -194,7 +178,7 @@ jobs: - name: Build example (Web) working-directory: ${{ env.work_dir }} - if: matrix.language == 'js' + if: matrix.type.language == 'js' run: | yarn example expo export --platform web diff --git a/docs/pages/create.md b/docs/pages/create.md index e2e6aa61e..56e5eb7c3 100644 --- a/docs/pages/create.md +++ b/docs/pages/create.md @@ -29,6 +29,8 @@ This will ask you a few questions about your project and generate a new project After the project is created, you can find the development workflow in the generated `CONTRIBUTING.md` file. +> Note: If you want to create a library using the legacy native modules and view APIs instead of the new architecture, you can use the `0.49.8` version of `create-react-native-library`: `npx create-react-native-library@0.49.8 awesome-library`. + ## Local library While the default templates are for libraries that are published to npm, you can also create a local library that is not published but used locally in your app. diff --git a/packages/create-react-native-library/src/exampleApp/generateExampleApp.ts b/packages/create-react-native-library/src/exampleApp/generateExampleApp.ts index 79295b051..605aa8d3a 100644 --- a/packages/create-react-native-library/src/exampleApp/generateExampleApp.ts +++ b/packages/create-react-native-library/src/exampleApp/generateExampleApp.ts @@ -261,39 +261,33 @@ export default async function generateExampleApp({ 'android.enableJetifier=false' ); - // If the library is on new architecture, enable new arch for iOS and Android - if (config.project.arch === 'new') { - // iOS - // Add ENV['RCT_NEW_ARCH_ENABLED'] = 1 on top of example/ios/Podfile - const podfile = await fs.readFile( - path.join(directory, 'ios', 'Podfile'), - 'utf8' - ); + // Enable new arch for iOS and Android + // iOS + // Add ENV['RCT_NEW_ARCH_ENABLED'] = 1 on top of example/ios/Podfile + const podfile = await fs.readFile( + path.join(directory, 'ios', 'Podfile'), + 'utf8' + ); - await fs.writeFile( - path.join(directory, 'ios', 'Podfile'), - "ENV['RCT_NEW_ARCH_ENABLED'] = '1'\n\n" + podfile - ); + await fs.writeFile( + path.join(directory, 'ios', 'Podfile'), + "ENV['RCT_NEW_ARCH_ENABLED'] = '1'\n\n" + podfile + ); - // Android - // Make sure newArchEnabled=true is present in android/gradle.properties - if (gradleProperties.split('\n').includes('#newArchEnabled=true')) { - gradleProperties = gradleProperties.replace( - '#newArchEnabled=true', - 'newArchEnabled=true' - ); - } else if ( - gradleProperties.split('\n').includes('newArchEnabled=false') - ) { - gradleProperties = gradleProperties.replace( - 'newArchEnabled=false', - 'newArchEnabled=true' - ); - } else if ( - !gradleProperties.split('\n').includes('newArchEnabled=true') - ) { - gradleProperties += '\nnewArchEnabled=true'; - } + // Android + // Make sure newArchEnabled=true is present in android/gradle.properties + if (gradleProperties.split('\n').includes('#newArchEnabled=true')) { + gradleProperties = gradleProperties.replace( + '#newArchEnabled=true', + 'newArchEnabled=true' + ); + } else if (gradleProperties.split('\n').includes('newArchEnabled=false')) { + gradleProperties = gradleProperties.replace( + 'newArchEnabled=false', + 'newArchEnabled=true' + ); + } else if (!gradleProperties.split('\n').includes('newArchEnabled=true')) { + gradleProperties += '\nnewArchEnabled=true'; } await fs.writeFile( diff --git a/packages/create-react-native-library/src/input.ts b/packages/create-react-native-library/src/input.ts index 162ee17ea..f14fa18d8 100644 --- a/packages/create-react-native-library/src/input.ts +++ b/packages/create-react-native-library/src/input.ts @@ -18,13 +18,11 @@ export type ArgName = | 'example' | 'reactNativeVersion'; -export type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js'; +export type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'js'; export type ProjectType = | 'turbo-module' | 'fabric-view' - | 'legacy-module' - | 'legacy-view' | 'nitro-module' | 'library'; @@ -36,17 +34,12 @@ const LANGUAGE_CHOICES: { { title: 'Kotlin & Swift', value: 'kotlin-swift', - types: ['nitro-module', 'legacy-module', 'legacy-view'], + types: ['nitro-module'], }, { title: 'Kotlin & Objective-C', value: 'kotlin-objc', - types: ['turbo-module', 'fabric-view', 'legacy-module', 'legacy-view'], - }, - { - title: 'C++ for Android & iOS', - value: 'cpp', - types: ['turbo-module', 'legacy-module'], + types: ['turbo-module', 'fabric-view'], }, { title: 'JavaScript for Android, iOS & Web', @@ -101,16 +94,6 @@ const TYPE_CHOICES: { description: 'type-safe, fast integration for native APIs to JS (experimental)', }, - { - title: 'Legacy Native module', - value: 'legacy-module', - description: 'bridge for native APIs to JS (old architecture)', - }, - { - title: 'Legacy Native view', - value: 'legacy-view', - description: 'bridge for native views to JS (old architecture)', - }, { title: 'JavaScript library', value: 'library', @@ -167,7 +150,6 @@ export const acceptedArgs: Record = { } as const; export type Args = Record; -export type SupportedArchitecture = 'new' | 'legacy'; export type ExampleApp = 'none' | 'test-app' | 'expo' | 'vanilla'; export type Answers = { diff --git a/packages/create-react-native-library/src/template.ts b/packages/create-react-native-library/src/template.ts index c003891c1..faad7fcce 100644 --- a/packages/create-react-native-library/src/template.ts +++ b/packages/create-react-native-library/src/template.ts @@ -1,12 +1,7 @@ import path from 'path'; import fs from 'fs-extra'; import ejs from 'ejs'; -import type { - Answers, - ExampleApp, - ProjectType, - SupportedArchitecture, -} from './input'; +import type { Answers, ExampleApp, ProjectType } from './input'; export type TemplateVersions = { bob: string; @@ -35,8 +30,6 @@ export type TemplateConfiguration = { package_cpp: string; identifier: string; native: boolean; - arch: SupportedArchitecture; - cpp: boolean; swift: boolean; viewConfig: ViewConfig; moduleConfig: ModuleConfig; @@ -62,10 +55,6 @@ const EXAMPLE_COMMON_FILES = path.resolve( __dirname, '../templates/example-common' ); -const EXAMPLE_MODULE_LEGACY_FILES = path.resolve( - __dirname, - '../templates/example-module-legacy' -); const EXAMPLE_MODULE_NEW_FILES = path.resolve( __dirname, '../templates/example-module-new' @@ -74,7 +63,6 @@ const EXAMPLE_VIEW_FILES = path.resolve(__dirname, '../templates/example-view'); const JS_FILES = path.resolve(__dirname, '../templates/js-library'); const EXPO_FILES = path.resolve(__dirname, '../templates/expo-library'); -const CPP_FILES = path.resolve(__dirname, '../templates/cpp-library'); const NATIVE_COMMON_FILES = path.resolve( __dirname, '../templates/native-common' @@ -85,31 +73,21 @@ const NATIVE_COMMON_EXAMPLE_FILES = path.resolve( ); const NATIVE_FILES = { - module_legacy: path.resolve(__dirname, '../templates/native-library-legacy'), module_new: path.resolve(__dirname, '../templates/native-library-new'), - view_legacy: path.resolve(__dirname, '../templates/native-view-legacy'), view_new: path.resolve(__dirname, '../templates/native-view-new'), module_nitro: path.resolve(__dirname, '../templates/nitro-module'), } as const; const OBJC_FILES = { module_common: path.resolve(__dirname, '../templates/objc-library'), - view_legacy: path.resolve(__dirname, '../templates/objc-view-legacy'), view_new: path.resolve(__dirname, '../templates/objc-view-new'), } as const; const KOTLIN_FILES = { - module_legacy: path.resolve(__dirname, '../templates/kotlin-library-legacy'), module_new: path.resolve(__dirname, '../templates/kotlin-library-new'), - view_legacy: path.resolve(__dirname, '../templates/kotlin-view-legacy'), view_new: path.resolve(__dirname, '../templates/kotlin-view-new'), } as const; -const SWIFT_FILES = { - module_legacy: path.resolve(__dirname, '../templates/swift-library-legacy'), - view_legacy: path.resolve(__dirname, '../templates/swift-view-legacy'), -} as const; - export function generateTemplateConfiguration({ versions, basename, @@ -121,11 +99,6 @@ export function generateTemplateConfiguration({ }): TemplateConfiguration { const { slug, languages, type } = answers; - const arch = - type === 'legacy-module' || type === 'legacy-view' || type === 'library' - ? 'legacy' - : 'new'; - const project = slug.replace(/^(react-native-|@[^/]+\/)/, ''); let namespace: string | undefined; @@ -159,8 +132,6 @@ export function generateTemplateConfiguration({ package_cpp: pack.replace(/\./g, '_'), identifier: slug.replace(/[^a-z0-9]+/g, '-').replace(/^-/, ''), native: languages !== 'js', - arch, - cpp: languages === 'cpp', swift: languages === 'kotlin-swift', viewConfig: getViewConfig(type), moduleConfig: getModuleConfig(type), @@ -182,8 +153,6 @@ function getModuleConfig(projectType: ProjectType): ModuleConfig { return 'nitro-modules'; case 'turbo-module': return 'turbo-modules'; - case 'legacy-module': - return 'native-modules'; default: return null; } @@ -191,8 +160,6 @@ function getModuleConfig(projectType: ProjectType): ModuleConfig { function getViewConfig(projectType: ProjectType): ViewConfig { switch (projectType) { - case 'legacy-view': - return 'paper-view'; case 'fabric-view': return 'fabric-view'; default: @@ -217,11 +184,7 @@ export async function applyTemplates( if (config.project.viewConfig !== null) { await applyTemplate(config, EXAMPLE_VIEW_FILES, folder); } else { - if (config.project.arch === 'legacy') { - await applyTemplate(config, EXAMPLE_MODULE_LEGACY_FILES, folder); - } else { - await applyTemplate(config, EXAMPLE_MODULE_NEW_FILES, folder); - } + await applyTemplate(config, EXAMPLE_MODULE_NEW_FILES, folder); } } } @@ -242,43 +205,22 @@ export async function applyTemplates( } if (config.project.moduleConfig !== null) { - await applyTemplate( - config, - NATIVE_FILES[`module_${config.project.arch}`], - folder - ); + await applyTemplate(config, NATIVE_FILES[`module_new`], folder); } else { - await applyTemplate( - config, - NATIVE_FILES[`view_${config.project.arch}`], - folder - ); + await applyTemplate(config, NATIVE_FILES[`view_new`], folder); } - if (config.project.swift) { - await applyTemplate(config, SWIFT_FILES[`module_legacy`], folder); + if (config.project.moduleConfig !== null) { + await applyTemplate(config, OBJC_FILES[`module_common`], folder); } else { - if (config.project.moduleConfig !== null) { - await applyTemplate(config, OBJC_FILES[`module_common`], folder); - } else { - await applyTemplate( - config, - OBJC_FILES[`view_${config.project.arch}`], - folder - ); - } + await applyTemplate(config, OBJC_FILES[`view_new`], folder); } const templateType = `${ config.project.moduleConfig !== null ? 'module' : 'view' - }_${config.project.arch}` as const; + }_new` as const; await applyTemplate(config, KOTLIN_FILES[templateType], folder); - - if (config.project.cpp) { - await applyTemplate(config, CPP_FILES, folder); - await fs.remove(path.join(folder, 'ios', `${config.project.name}.m`)); - } } } @@ -295,13 +237,20 @@ async function applyTemplate( const files = await fs.readdir(source); for (const f of files) { - const target = path.join( - destination, - ejs.render(f.replace(/^\$/, ''), config, { + let name; + + try { + name = ejs.render(f.replace(/^\$/, ''), config, { openDelimiter: '{', closeDelimiter: '}', - }) - ); + }); + } catch (e) { + throw new Error(`Failed to render template file name: ${f}`, { + cause: e, + }); + } + + const target = path.join(destination, name); const file = path.join(source, f); const stats = await fs.stat(file); @@ -311,7 +260,17 @@ async function applyTemplate( } else if (!BINARIES.some((r) => r.test(file))) { const content = await fs.readFile(file, 'utf8'); - await fs.writeFile(target, ejs.render(content, config)); + let result; + + try { + result = ejs.render(content, config); + } catch (e) { + throw new Error(`Failed to render template file content: ${f}`, { + cause: e, + }); + } + + await fs.writeFile(target, result); } else { await fs.copyFile(file, target); } diff --git a/packages/create-react-native-library/templates/common-local/$package.json b/packages/create-react-native-library/templates/common-local/$package.json index 19d884ddc..9970c8f8f 100644 --- a/packages/create-react-native-library/templates/common-local/$package.json +++ b/packages/create-react-native-library/templates/common-local/$package.json @@ -3,13 +3,11 @@ "version": "0.0.0", "description": "<%- project.description %>", "main": "src/index", -<% if (project.arch === 'new') { -%> "codegenConfig": { "name": "RN<%- project.name -%><%- project.viewConfig !== null ? 'View': '' -%>Spec", "type": <%- project.viewConfig !== null ? '"all"': '"modules"' %>, "jsSrcsDir": "src" }, -<% } -%> "author": "<%- author.name -%> <<%- author.email -%>> (<%- author.url -%>)", "license": "UNLICENSED", "homepage": "<%- repo -%>#readme" diff --git a/packages/create-react-native-library/templates/common/CONTRIBUTING.md b/packages/create-react-native-library/templates/common/CONTRIBUTING.md index fa78e872c..ab5549219 100644 --- a/packages/create-react-native-library/templates/common/CONTRIBUTING.md +++ b/packages/create-react-native-library/templates/common/CONTRIBUTING.md @@ -18,13 +18,14 @@ yarn ``` > Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development. -<% if (project.moduleConfig === 'nitro-modules') { -%> +<% if (project.moduleConfig === 'nitro-modules') { -%> This project uses Nitro Modules. If you're not familiar with how Nitro works, make sure to check the [Nitro Modules Docs](https://nitro.margelo.com/). You need to run [Nitrogen](https://nitro.margelo.com/docs/nitrogen) to generate the boilerplate code required for this project. The example app will not build without this step. Run **Nitrogen** in following cases: + - When you make changes to any `*.nitro.ts` files. - When running the project for the first time (since the generated files are not committed to the repository). @@ -33,8 +34,8 @@ To invoke **Nitrogen**, use the following command: ```sh yarn nitrogen ``` -<% } -%> +<% } -%> The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make. It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app. @@ -65,7 +66,6 @@ To run the example app on iOS: yarn example ios ``` -<% if (project.arch === 'new') { -%> To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this: ```sh @@ -74,7 +74,6 @@ Running "<%- project.name -%>Example" with {"fabric":true,"initialProps":{"concu Note the `"fabric":true` and `"concurrentRoot":true` properties. -<% } -%> <% if (!project.native) { -%> To run the example app on Web: diff --git a/packages/create-react-native-library/templates/cpp-library/android/CMakeLists.txt b/packages/create-react-native-library/templates/cpp-library/android/CMakeLists.txt deleted file mode 100644 index 9747045ca..000000000 --- a/packages/create-react-native-library/templates/cpp-library/android/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(<%- project.name -%>) - -set (CMAKE_VERBOSE_MAKEFILE ON) -set (CMAKE_CXX_STANDARD 14) - -add_library(<%- project.identifier -%> - SHARED - ../cpp/<%- project.identifier -%>.cpp - cpp-adapter.cpp -) - -# Specifies a path to native header files. -include_directories( - ../cpp -) diff --git a/packages/create-react-native-library/templates/cpp-library/android/cpp-adapter.cpp b/packages/create-react-native-library/templates/cpp-library/android/cpp-adapter.cpp deleted file mode 100644 index 36b6a390c..000000000 --- a/packages/create-react-native-library/templates/cpp-library/android/cpp-adapter.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "<%- project.identifier -%>.h" - -extern "C" -JNIEXPORT jdouble JNICALL -Java_com_<%- project.package_cpp -%>_<%- project.name -%>Module_nativeMultiply(JNIEnv *env, jclass type, jdouble a, jdouble b) { - return <%- project.package_cpp -%>::multiply(a, b); -} diff --git a/packages/create-react-native-library/templates/cpp-library/cpp/{%- project.identifier %}.cpp b/packages/create-react-native-library/templates/cpp-library/cpp/{%- project.identifier %}.cpp deleted file mode 100644 index 73f81528e..000000000 --- a/packages/create-react-native-library/templates/cpp-library/cpp/{%- project.identifier %}.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "<%- project.identifier -%>.h" - -namespace <%- project.package_cpp -%> { - double multiply(double a, double b) { - return a * b; - } -} diff --git a/packages/create-react-native-library/templates/cpp-library/cpp/{%- project.identifier %}.h b/packages/create-react-native-library/templates/cpp-library/cpp/{%- project.identifier %}.h deleted file mode 100644 index 7f3ee334f..000000000 --- a/packages/create-react-native-library/templates/cpp-library/cpp/{%- project.identifier %}.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef <%- project.package_cpp.toUpperCase() -%>_H -#define <%- project.package_cpp.toUpperCase() -%>_H - -namespace <%- project.package_cpp -%> { - double multiply(double a, double b); -} - -#endif /* <%- project.package_cpp.toUpperCase() -%>_H */ diff --git a/packages/create-react-native-library/templates/example-module-legacy/example/src/App.tsx b/packages/create-react-native-library/templates/example-module-legacy/example/src/App.tsx deleted file mode 100644 index 05c7d3ad5..000000000 --- a/packages/create-react-native-library/templates/example-module-legacy/example/src/App.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import { multiply } from '<%- project.slug -%>'; -import { Text, View, StyleSheet } from 'react-native'; -<% if (project.native) { -%> -import { useState, useEffect } from 'react'; - -export default function App() { - const [result, setResult] = useState(); - - useEffect(() => { - multiply(3, 7).then(setResult); - }, []); - -<% } else { -%> - -const result = multiply(3, 7); - -export default function App() { -<% } -%> - return ( - - Result: {result} - - ); -} - -const styles = StyleSheet.create({ - container: { - flex: 1, - alignItems: 'center', - justifyContent: 'center', - }, -}); diff --git a/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt b/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt deleted file mode 100644 index 392956228..000000000 --- a/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.ReactContextBaseJavaModule -import com.facebook.react.bridge.ReactMethod -import com.facebook.react.bridge.Promise - -class <%- project.name -%>Module(reactContext: ReactApplicationContext) : - ReactContextBaseJavaModule(reactContext) { - - override fun getName(): String { - return NAME - } - - // Example method - // See https://reactnative.dev/docs/native-modules-android - @ReactMethod - fun multiply(a: Double, b: Double, promise: Promise) { - promise.resolve(a * b) - } - - companion object { - const val NAME = "<%- project.name -%>" - } -} diff --git a/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt deleted file mode 100644 index d34649aee..000000000 --- a/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.ReactPackage -import com.facebook.react.bridge.NativeModule -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.uimanager.ViewManager - - -class <%- project.name -%>Package : ReactPackage { - override fun createNativeModules(reactContext: ReactApplicationContext): List { - return listOf(<%- project.name -%>Module(reactContext)) - } - - override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return emptyList() - } -} diff --git a/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt deleted file mode 100644 index 67e778677..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.ReactPackage -import com.facebook.react.bridge.NativeModule -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.uimanager.ViewManager - - -class <%- project.name -%>Package : ReactPackage { - override fun createNativeModules(reactContext: ReactApplicationContext): List { - return emptyList() - } - - override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return listOf(<%- project.name -%>ViewManager()) - } -} diff --git a/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt b/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt deleted file mode 100644 index f52229f97..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.<%- project.package %> - -import android.graphics.Color -import android.view.View -import com.facebook.react.uimanager.SimpleViewManager -import com.facebook.react.uimanager.ThemedReactContext -import com.facebook.react.uimanager.annotations.ReactProp - -class <%- project.name -%>ViewManager : SimpleViewManager() { - override fun getName() = "<%- project.name -%>View" - - override fun createViewInstance(reactContext: ThemedReactContext): View { - return View(reactContext) - } - - @ReactProp(name = "color") - fun setColor(view: View, color: String) { - view.setBackgroundColor(Color.parseColor(color)) - } -} diff --git a/packages/create-react-native-library/templates/native-common/android/build.gradle b/packages/create-react-native-library/templates/native-common/android/build.gradle index d7925a44d..0a6265285 100644 --- a/packages/create-react-native-library/templates/native-common/android/build.gradle +++ b/packages/create-react-native-library/templates/native-common/android/build.gradle @@ -15,7 +15,7 @@ buildscript { } } -<% if (project.cpp || project.moduleConfig === 'nitro-modules') { -%> +<% if (project.moduleConfig === 'nitro-modules') { -%> def reactNativeArchitectures() { def value = rootProject.getProperties().get("reactNativeArchitectures") return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] @@ -28,9 +28,7 @@ apply plugin: "kotlin-android" apply from: '../nitrogen/generated/android/<%- project.package_cpp -%>+autolinking.gradle' <% } -%> -<% if (project.arch === "new") { -%> apply plugin: "com.facebook.react" -<% } -%> def getExtOrIntegerDefault(name) { return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["<%- project.name -%>_" + name]).toInteger() @@ -60,15 +58,12 @@ android { } } -<% if (project.cpp) { -%> - ndkVersion getExtOrDefault("ndkVersion") -<% } -%> compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") defaultConfig { minSdkVersion getExtOrIntegerDefault("minSdkVersion") targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") -<% if (project.cpp || project.moduleConfig === 'nitro-modules') { -%> +<% if (project.moduleConfig === 'nitro-modules') { -%> externalNativeBuild { cmake { @@ -88,7 +83,7 @@ android { } <% } -%> } -<% if (project.cpp || project.moduleConfig === 'nitro-modules') { -%> +<% if (project.moduleConfig === 'nitro-modules') { -%> externalNativeBuild { cmake { @@ -119,7 +114,6 @@ android { ] } <% } -%> -<% if (project.arch === "new") { -%> buildFeatures { buildConfig true @@ -127,7 +121,6 @@ android { prefab true <% } -%> } -<% } -%> buildTypes { release { @@ -143,7 +136,6 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } -<% if (project.arch === "new") { -%> sourceSets { main { @@ -153,7 +145,6 @@ android { ] } } -<% } -%> } repositories { diff --git a/packages/create-react-native-library/templates/native-common/{%- project.name %}.podspec b/packages/create-react-native-library/templates/native-common/{%- project.name %}.podspec index ec8f8785c..c6ea4db12 100644 --- a/packages/create-react-native-library/templates/native-common/{%- project.name %}.podspec +++ b/packages/create-react-native-library/templates/native-common/{%- project.name %}.podspec @@ -13,15 +13,11 @@ Pod::Spec.new do |s| s.platforms = { :ios => min_ios_version_supported } s.source = { :git => "<%- repo -%>.git", :tag => "#{s.version}" } -<% if (project.cpp) { -%> - s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}" -<% } else if (project.swift) { -%> +<% if (project.swift) { -%> s.source_files = "ios/**/*.{h,m,mm,swift}" -<% } else if (project.arch !== "legacy") { -%> +<% } else { -%> s.source_files = "ios/**/*.{h,m,mm,cpp}" s.private_header_files = "ios/**/*.h" -<% } else { -%> - s.source_files = "ios/**/*.{h,m,mm}" <% } -%> <% if (project.moduleConfig === "nitro-modules") { -%> diff --git a/packages/create-react-native-library/templates/native-library-legacy/src/index.tsx b/packages/create-react-native-library/templates/native-library-legacy/src/index.tsx deleted file mode 100644 index 651971c33..000000000 --- a/packages/create-react-native-library/templates/native-library-legacy/src/index.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { NativeModules, Platform } from 'react-native'; - -const LINKING_ERROR = - `The package '<%- project.slug -%>' doesn't seem to be linked. Make sure: \n\n` + - Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + - '- You rebuilt the app after installing the package\n' + - '- You are not using Expo Go\n'; - -const <%- project.name -%> = NativeModules.<%- project.name %> - ? NativeModules.<%- project.name %> - : new Proxy( - {}, - { - get() { - throw new Error(LINKING_ERROR); - }, - } - ); - -export function multiply(a: number, b: number): Promise { - return <%- project.name -%>.multiply(a, b); -} diff --git a/packages/create-react-native-library/templates/native-view-legacy/src/index.tsx b/packages/create-react-native-library/templates/native-view-legacy/src/index.tsx deleted file mode 100644 index 055016821..000000000 --- a/packages/create-react-native-library/templates/native-view-legacy/src/index.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { - requireNativeComponent, - UIManager, - Platform, - type ViewStyle, -} from 'react-native'; - -const LINKING_ERROR = - `The package '<%- project.slug -%>' doesn't seem to be linked. Make sure: \n\n` + - Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + - '- You rebuilt the app after installing the package\n' + - '- You are not using Expo Go\n'; - -type <%- project.name -%>Props = { - color: string; - style: ViewStyle; -}; - -const ComponentName = '<%- project.name -%>View'; - -export const <%- project.name -%>View = - UIManager.getViewManagerConfig(ComponentName) != null - ? requireNativeComponent<<%- project.name -%>Props>(ComponentName) - : () => { - throw new Error(LINKING_ERROR); - }; diff --git a/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.h b/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.h index 2ab64d0f7..cd2f0acd7 100644 --- a/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.h +++ b/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.h @@ -1,17 +1,5 @@ -<% if (project.cpp) { -%> -#ifdef __cplusplus -#import "<%- project.identifier -%>.h" -#endif -<% } -%> - -<% if (project.arch === 'new') { -%> #import <<%- project.name -%>/RN<%- project.name -%>Spec.h> @interface <%- project.name -%> : NSObject Spec> -<% } else { -%> -#import - -@interface <%- project.name -%> : NSObject -<% } -%> @end diff --git a/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.mm b/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.mm index 823ce78c0..ce5beab67 100644 --- a/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.mm +++ b/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.mm @@ -4,31 +4,8 @@ @implementation <%- project.name -%> RCT_EXPORT_MODULE() -<% if (project.arch === 'legacy') { -%> -// Example method -// See // https://reactnative.dev/docs/native-modules-ios -RCT_EXPORT_METHOD(multiply:(double)a - b:(double)b - resolve:(RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject) -{ -<% if (project.cpp) { -%> - NSNumber *result = @(<%- project.package_cpp -%>::multiply(a, b)); -<% } else { -%> - NSNumber *result = @(a * b); -<% } -%> - - resolve(result); -} - -<% } -%> -<% if (project.arch === 'new') { -%> - (NSNumber *)multiply:(double)a b:(double)b { -<% if (project.cpp) { -%> - NSNumber *result = @(<%- project.package_cpp -%>::multiply(a, b)); -<% } else { -%> NSNumber *result = @(a * b); -<% } -%> return result; } @@ -38,6 +15,5 @@ - (NSNumber *)multiply:(double)a b:(double)b { { return std::make_sharedSpecJSI>(params); } -<% } -%> @end diff --git a/packages/create-react-native-library/templates/objc-view-legacy/ios/{%- project.name %}ViewManager.m b/packages/create-react-native-library/templates/objc-view-legacy/ios/{%- project.name %}ViewManager.m deleted file mode 100644 index c9f9c0e00..000000000 --- a/packages/create-react-native-library/templates/objc-view-legacy/ios/{%- project.name %}ViewManager.m +++ /dev/null @@ -1,34 +0,0 @@ -#import - -@interface <%- project.name -%>ViewManager : RCTViewManager -@end - -@implementation <%- project.name -%>ViewManager - -RCT_EXPORT_MODULE(<%- project.name -%>View) - -- (UIView *)view -{ - return [[UIView alloc] init]; -} - -RCT_CUSTOM_VIEW_PROPERTY(color, NSString, UIView) -{ - [view setBackgroundColor:[self hexStringToColor:json]]; -} - -- hexStringToColor:(NSString *)stringToConvert -{ - NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""]; - NSScanner *stringScanner = [NSScanner scannerWithString:noHashString]; - - unsigned hex; - if (![stringScanner scanHexInt:&hex]) return nil; - int r = (hex >> 16) & 0xFF; - int g = (hex >> 8) & 0xFF; - int b = (hex) & 0xFF; - - return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f]; -} - -@end diff --git a/packages/create-react-native-library/templates/swift-library-legacy/ios/{%- project.name %}-Bridging-Header.h b/packages/create-react-native-library/templates/swift-library-legacy/ios/{%- project.name %}-Bridging-Header.h deleted file mode 100644 index dea7ff6bf..000000000 --- a/packages/create-react-native-library/templates/swift-library-legacy/ios/{%- project.name %}-Bridging-Header.h +++ /dev/null @@ -1,2 +0,0 @@ -#import -#import diff --git a/packages/create-react-native-library/templates/swift-library-legacy/ios/{%- project.name %}.mm b/packages/create-react-native-library/templates/swift-library-legacy/ios/{%- project.name %}.mm deleted file mode 100644 index 77a769b05..000000000 --- a/packages/create-react-native-library/templates/swift-library-legacy/ios/{%- project.name %}.mm +++ /dev/null @@ -1,14 +0,0 @@ -#import - -@interface RCT_EXTERN_MODULE(<%- project.name -%>, NSObject) - -RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b - withResolver:(RCTPromiseResolveBlock)resolve - withRejecter:(RCTPromiseRejectBlock)reject) - -+ (BOOL)requiresMainQueueSetup -{ - return NO; -} - -@end diff --git a/packages/create-react-native-library/templates/swift-library-legacy/ios/{%- project.name %}.swift b/packages/create-react-native-library/templates/swift-library-legacy/ios/{%- project.name %}.swift deleted file mode 100644 index 2c5c942f0..000000000 --- a/packages/create-react-native-library/templates/swift-library-legacy/ios/{%- project.name %}.swift +++ /dev/null @@ -1,8 +0,0 @@ -@objc(<%- project.name -%>) -class <%- project.name -%>: NSObject { - - @objc(multiply:withB:withResolver:withRejecter:) - func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void { - resolve(a*b) - } -} diff --git a/packages/create-react-native-library/templates/swift-view-legacy/ios/{%- project.name %}-Bridging-Header.h b/packages/create-react-native-library/templates/swift-view-legacy/ios/{%- project.name %}-Bridging-Header.h deleted file mode 100644 index 16eb5eb19..000000000 --- a/packages/create-react-native-library/templates/swift-view-legacy/ios/{%- project.name %}-Bridging-Header.h +++ /dev/null @@ -1 +0,0 @@ -#import diff --git a/packages/create-react-native-library/templates/swift-view-legacy/ios/{%- project.name %}ViewManager.m b/packages/create-react-native-library/templates/swift-view-legacy/ios/{%- project.name %}ViewManager.m deleted file mode 100644 index b9adb6816..000000000 --- a/packages/create-react-native-library/templates/swift-view-legacy/ios/{%- project.name %}ViewManager.m +++ /dev/null @@ -1,7 +0,0 @@ -#import - -@interface RCT_EXTERN_MODULE(<%- project.name -%>ViewManager, RCTViewManager) - -RCT_EXPORT_VIEW_PROPERTY(color, NSString) - -@end diff --git a/packages/create-react-native-library/templates/swift-view-legacy/ios/{%- project.name %}ViewManager.swift b/packages/create-react-native-library/templates/swift-view-legacy/ios/{%- project.name %}ViewManager.swift deleted file mode 100644 index b075661d3..000000000 --- a/packages/create-react-native-library/templates/swift-view-legacy/ios/{%- project.name %}ViewManager.swift +++ /dev/null @@ -1,36 +0,0 @@ -@objc(<%- project.name -%>ViewManager) -class <%- project.name -%>ViewManager: RCTViewManager { - - override func view() -> (<%- project.name -%>View) { - return <%- project.name -%>View() - } - - @objc override static func requiresMainQueueSetup() -> Bool { - return false - } -} - -class <%- project.name -%>View : UIView { - - @objc var color: String = "" { - didSet { - self.backgroundColor = hexStringToUIColor(hexColor: color) - } - } - - func hexStringToUIColor(hexColor: String) -> UIColor { - let stringScanner = Scanner(string: hexColor) - - if(hexColor.hasPrefix("#")) { - stringScanner.scanLocation = 1 - } - var color: UInt32 = 0 - stringScanner.scanHexInt32(&color) - - let r = CGFloat(Int(color >> 16) & 0x000000FF) - let g = CGFloat(Int(color >> 8) & 0x000000FF) - let b = CGFloat(Int(color) & 0x000000FF) - - return UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: 1) - } -}