From 154c81985ca6f71348d99910ac863f5309485fb1 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Tue, 2 Jul 2024 17:24:45 +0200 Subject: [PATCH] Revert "feat: merge view+module native templates (#562)" This reverts commit a75cf32890804bcfc20819df4fdfe5bd4fafb7f2. --- .github/workflows/build-templates.yml | 70 +++--- .../create-react-native-library/src/index.ts | 202 +++++++++--------- .../common-example/example/src/App.tsx | 32 +-- .../templates/common/$package.json | 4 +- .../templates/common/CONTRIBUTING.md | 2 +- .../templates/common/README.md | 5 +- .../{%- project.name %}Module.java | 43 ++++ .../{%- project.name %}Package.java | 28 +++ .../{%- project.name %}Module.java | 40 ++++ .../{%- project.name %}Package.java | 45 ++++ .../src/newarch/{%- project.name %}Spec.java | 9 + .../src/oldarch/{%- project.name %}Spec.java | 13 ++ .../{%- project.name %}Module.java | 40 ++++ .../{%- project.name %}Package.java | 44 ++++ .../{%- project.name %}Package.java | 22 ++ .../{%- project.name %}ViewManager.java | 31 +++ .../{%- project.name %}View.java | 24 +++ .../{%- project.name %}ViewManager.java | 31 +++ .../{%- project.name %}ViewPackage.java | 25 +++ .../{%- project.name %}ViewManagerSpec.java | 24 +++ .../{%- project.name %}ViewManagerSpec.java | 12 ++ .../{%- project.name %}View.java | 24 +++ .../{%- project.name %}ViewManager.java | 47 ++++ .../{%- project.name %}ViewPackage.java | 25 +++ .../{%- project.name %}Module.kt | 25 --- .../{%- project.name %}Package.kt | 39 ---- .../{%- project.name %}ViewManager.kt | 20 -- .../{%- project.name %}Module.kt | 24 --- .../{%- project.name %}Package.kt | 40 ---- .../src/newarch/{%- project.name %}Spec.kt | 7 - .../src/oldarch/{%- project.name %}Spec.kt | 11 - .../{%- project.name %}Module.kt | 23 -- .../{%- project.name %}Package.kt | 40 ---- .../{%- project.name %}Package.kt | 19 ++ .../{%- project.name %}View.kt | 0 .../{%- project.name %}ViewManager.kt | 0 .../{%- project.name %}ViewManagerSpec.kt | 0 .../{%- project.name %}ViewManagerSpec.kt | 0 .../{%- project.name %}Package.kt | 19 ++ .../{%- project.name %}View.kt | 0 .../{%- project.name %}ViewManager.kt | 0 .../native-common/android/build.gradle | 10 + .../native-view-library-legacy/src/index.tsx | 7 - .../src/{%- project.name %}.ts | 18 -- .../src/{%- project.name %}View.ts | 26 --- .../src/Native{%- project.name %}.ts | 8 - .../native-view-library-mixed/src/index.tsx | 32 --- .../src/Native{%- project.name %}.ts | 8 - .../native-view-library-new/src/index.tsx | 8 - .../templates/native-view-mixed/src/index.tsx | 2 + ...{%- project.name %}ViewNativeComponent.ts} | 0 .../templates/native-view-new/src/index.tsx | 2 + ...{%- project.name %}ViewNativeComponent.ts} | 0 .../ios/{%- project.name %}ViewManager.m | 0 .../ios/{%- project.name %}.h | 6 - .../ios/{%- project.name %}.mm | 18 -- .../ios/{%- project.name %}.h | 17 -- .../ios/{%- project.name %}.mm | 48 ----- .../ios/{%- project.name %}.h | 17 -- .../ios/{%- project.name %}.mm | 48 ----- .../ios/Utils.h | 0 .../ios/Utils.m | 0 .../ios/{%- project.name %}View.h | 0 .../ios/{%- project.name %}View.mm | 8 +- .../ios/{%- project.name %}ViewManager.mm | 0 .../ios/{%- project.name %}View.h | 0 .../ios/{%- project.name %}View.mm | 8 +- .../ios/{%- project.name %}ViewManager.mm | 0 68 files changed, 762 insertions(+), 638 deletions(-) create mode 100644 packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java create mode 100644 packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java create mode 100644 packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java create mode 100644 packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java create mode 100644 packages/create-react-native-library/templates/java-library-mixed/android/src/newarch/{%- project.name %}Spec.java create mode 100644 packages/create-react-native-library/templates/java-library-mixed/android/src/oldarch/{%- project.name %}Spec.java create mode 100644 packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java create mode 100644 packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java create mode 100644 packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java create mode 100644 packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java create mode 100644 packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java create mode 100644 packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java create mode 100644 packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java create mode 100644 packages/create-react-native-library/templates/java-view-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.java create mode 100644 packages/create-react-native-library/templates/java-view-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.java create mode 100644 packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java create mode 100644 packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java create mode 100644 packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java delete mode 100644 packages/create-react-native-library/templates/kotlin-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/newarch/{%- project.name %}Spec.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt create mode 100644 packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt rename packages/create-react-native-library/templates/{kotlin-view-library-mixed => kotlin-view-mixed}/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt (100%) rename packages/create-react-native-library/templates/{kotlin-view-library-mixed => kotlin-view-mixed}/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt (100%) rename packages/create-react-native-library/templates/{kotlin-view-library-mixed => kotlin-view-mixed}/android/src/newarch/{%- project.name %}ViewManagerSpec.kt (100%) rename packages/create-react-native-library/templates/{kotlin-view-library-mixed => kotlin-view-mixed}/android/src/oldarch/{%- project.name %}ViewManagerSpec.kt (100%) create mode 100644 packages/create-react-native-library/templates/kotlin-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt rename packages/create-react-native-library/templates/{kotlin-view-library-new => kotlin-view-new}/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt (100%) rename packages/create-react-native-library/templates/{kotlin-view-library-new => kotlin-view-new}/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt (100%) delete mode 100644 packages/create-react-native-library/templates/native-view-library-legacy/src/index.tsx delete mode 100644 packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}.ts delete mode 100644 packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}View.ts delete mode 100644 packages/create-react-native-library/templates/native-view-library-mixed/src/Native{%- project.name %}.ts delete mode 100644 packages/create-react-native-library/templates/native-view-library-mixed/src/index.tsx delete mode 100644 packages/create-react-native-library/templates/native-view-library-new/src/Native{%- project.name %}.ts delete mode 100644 packages/create-react-native-library/templates/native-view-library-new/src/index.tsx create mode 100644 packages/create-react-native-library/templates/native-view-mixed/src/index.tsx rename packages/create-react-native-library/templates/{native-view-library-mixed/src/{%- project.name %}NativeComponent.ts => native-view-mixed/src/{%- project.name %}ViewNativeComponent.ts} (100%) create mode 100644 packages/create-react-native-library/templates/native-view-new/src/index.tsx rename packages/create-react-native-library/templates/{native-view-library-new/src/{%- project.name %}NativeComponent.ts => native-view-new/src/{%- project.name %}ViewNativeComponent.ts} (100%) rename packages/create-react-native-library/templates/{objc-view-library-legacy => objc-view-legacy}/ios/{%- project.name %}ViewManager.m (100%) delete mode 100644 packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.h delete mode 100644 packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.mm delete mode 100644 packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.h delete mode 100644 packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.mm delete mode 100644 packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.h delete mode 100644 packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.mm rename packages/create-react-native-library/templates/{objc-view-library-mixed => objc-view-mixed}/ios/Utils.h (100%) rename packages/create-react-native-library/templates/{objc-view-library-mixed => objc-view-mixed}/ios/Utils.m (100%) rename packages/create-react-native-library/templates/{objc-view-library-mixed => objc-view-mixed}/ios/{%- project.name %}View.h (100%) rename packages/create-react-native-library/templates/{objc-view-library-mixed => objc-view-mixed}/ios/{%- project.name %}View.mm (81%) rename packages/create-react-native-library/templates/{objc-view-library-mixed => objc-view-mixed}/ios/{%- project.name %}ViewManager.mm (100%) rename packages/create-react-native-library/templates/{objc-view-library-new => objc-view-new}/ios/{%- project.name %}View.h (100%) rename packages/create-react-native-library/templates/{objc-view-library-new => objc-view-new}/ios/{%- project.name %}View.mm (84%) rename packages/create-react-native-library/templates/{objc-view-library-new => objc-view-new}/ios/{%- project.name %}ViewManager.mm (100%) diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index e3e81206f..e7b2bb312 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -31,41 +31,57 @@ jobs: - module-legacy - module-mixed - module-new - - view-module-legacy - - view-module-mixed - - view-module-new + - view-legacy + - view-mixed + - view-new language: + - java-objc + - java-swift - kotlin-objc - - cpp + - kotlin-swift exclude: - - type: view-module-legacy - language: cpp - - type: view-module-mixed - language: cpp - - type: view-module-new - language: cpp - - type: module-legacy - language: kotlin-objc - - type: module-mixed + - os: macos-14 language: kotlin-objc + - os: macos-14 + language: kotlin-swift + - type: module-new + language: java-swift - type: module-new - language: kotlin-objc - include: - - os: ubuntu-latest - type: view-legacy language: kotlin-swift - - os: macos-14 - type: view-legacy + - type: module-mixed + language: java-swift + - type: module-mixed language: kotlin-swift - - os: ubuntu-latest - type: module-legacy + - type: view-new + language: java-swift + - type: view-new language: kotlin-swift - - os: macos-14 - type: module-legacy + - type: view-mixed + language: java-swift + - type: view-mixed language: kotlin-swift + include: - os: ubuntu-latest type: library language: js + - os: ubuntu-latest + type: module-legacy + language: cpp + - os: ubuntu-latest + type: module-mixed + language: cpp + - os: ubuntu-latest + type: module-new + language: cpp + - os: macos-14 + type: module-legacy + language: cpp + - os: macos-14 + type: module-mixed + language: cpp + - os: macos-14 + type: module-new + language: cpp concurrency: group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }} @@ -134,13 +150,17 @@ jobs: working-directory: ${{ env.work_dir }} run: | # Build Android for only some matrices to skip redundant builds - if [[ ${{ matrix.os }} == ubuntu-latest ]] && [[ ${{ matrix.language }} != js ]] ; then + if [[ ${{ matrix.os }} == ubuntu-latest ]]; then + if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then echo "android_build=1" >> $GITHUB_ENV + fi fi # Build iOS for only some matrices to skip redundant builds - if [[ ${{ matrix.os }} == macos-14 ]] && [[ ${{ matrix.language }} != js ]]; then + if [[ ${{ matrix.os }} == macos-14 ]]; then + if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then echo "ios_build=1" >> $GITHUB_ENV + fi fi - name: Cache turborepo diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index 37092969c..c757a8eed 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -38,70 +38,42 @@ 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'), - 'module-mixed': path.resolve(__dirname, '../templates/native-library-mixed'), - 'view-legacy': path.resolve(__dirname, '../templates/native-view-legacy'), - 'view-module-legacy': path.resolve( - __dirname, - '../templates/native-view-library-legacy' - ), - 'view-module-mixed': path.resolve( - __dirname, - '../templates/native-view-library-mixed' - ), - 'view-module-new': path.resolve( - __dirname, - '../templates/native-view-library-new' - ), + module_legacy: path.resolve(__dirname, '../templates/native-library-legacy'), + module_new: path.resolve(__dirname, '../templates/native-library-new'), + module_mixed: path.resolve(__dirname, '../templates/native-library-mixed'), + view_legacy: path.resolve(__dirname, '../templates/native-view-legacy'), + view_mixed: path.resolve(__dirname, '../templates/native-view-mixed'), + view_new: path.resolve(__dirname, '../templates/native-view-new'), +} as const; + +const JAVA_FILES = { + module_legacy: path.resolve(__dirname, '../templates/java-library-legacy'), + module_new: path.resolve(__dirname, '../templates/java-library-new'), + module_mixed: path.resolve(__dirname, '../templates/java-library-mixed'), + view_legacy: path.resolve(__dirname, '../templates/java-view-legacy'), + view_mixed: path.resolve(__dirname, '../templates/java-view-mixed'), + view_new: path.resolve(__dirname, '../templates/java-view-new'), } as const; const OBJC_FILES = { - 'module-legacy': path.resolve(__dirname, '../templates/objc-library'), - 'module-mixed': path.resolve(__dirname, '../templates/objc-library'), - 'module-new': path.resolve(__dirname, '../templates/objc-library'), - 'view-module-legacy': path.resolve( - __dirname, - '../templates/objc-view-library-legacy' - ), - 'view-module-mixed': path.resolve( - __dirname, - '../templates/objc-view-library-mixed' - ), - 'view-module-new': path.resolve( - __dirname, - '../templates/objc-view-library-new' - ), + module_common: path.resolve(__dirname, '../templates/objc-library'), + view_legacy: path.resolve(__dirname, '../templates/objc-view-legacy'), + view_mixed: path.resolve(__dirname, '../templates/objc-view-mixed'), + 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'), - 'module-mixed': path.resolve(__dirname, '../templates/kotlin-library-mixed'), - 'view-legacy': path.resolve(__dirname, '../templates/kotlin-view-legacy'), - 'view-module-legacy': path.resolve( - __dirname, - '../templates/kotlin-view-library-legacy' - ), - 'view-module-mixed': path.resolve( - __dirname, - '../templates/kotlin-view-library-mixed' - ), - 'view-module-new': path.resolve( - __dirname, - '../templates/kotlin-view-library-new' - ), + module_legacy: path.resolve(__dirname, '../templates/kotlin-library-legacy'), + module_new: path.resolve(__dirname, '../templates/kotlin-library-new'), + module_mixed: path.resolve(__dirname, '../templates/kotlin-library-mixed'), + view_legacy: path.resolve(__dirname, '../templates/kotlin-view-legacy'), + view_mixed: path.resolve(__dirname, '../templates/kotlin-view-mixed'), + 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'), + module_legacy: path.resolve(__dirname, '../templates/swift-library-legacy'), + view_legacy: path.resolve(__dirname, '../templates/swift-view-legacy'), } as const; type ArgName = @@ -117,17 +89,22 @@ type ArgName = | 'example' | 'react-native-version'; -type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js'; +type ProjectLanguages = + | 'java-objc' + | 'java-swift' + | 'kotlin-objc' + | 'kotlin-swift' + | 'cpp' + | 'js'; type ProjectType = - | 'library' | 'module-legacy' - | 'module-mixed' | 'module-new' + | 'module-mixed' + | 'view-mixed' + | 'view-new' | 'view-legacy' - | 'view-module-legacy' - | 'view-module-mixed' - | 'view-module-new'; + | 'library'; type Answers = { slug: string; @@ -150,13 +127,37 @@ const LANGUAGE_CHOICES: { { title: 'Kotlin & Objective-C', value: 'kotlin-objc', - types: ['view-module-legacy', 'view-module-mixed', 'view-module-new'], + types: [ + 'module-legacy', + 'module-new', + 'module-mixed', + 'view-mixed', + 'view-new', + 'view-legacy', + ], + }, + { + title: 'Java & Objective-C', + value: 'java-objc', + types: [ + 'module-legacy', + 'module-new', + 'module-mixed', + 'view-mixed', + 'view-new', + 'view-legacy', + ], }, { title: 'Kotlin & Swift', value: 'kotlin-swift', types: ['module-legacy', 'view-legacy'], }, + { + title: 'Java & Swift', + value: 'java-swift', + types: ['module-legacy', 'view-legacy'], + }, { title: 'C++ for Android & iOS', value: 'cpp', @@ -177,21 +178,6 @@ const TYPE_CHOICES: { value: ProjectType; description: string; }[] = [ - { - title: 'Fabric view and Turbo module with backward compat', - value: 'view-module-mixed', - description: BACKCOMPAT_DESCRIPTION, - }, - { - title: 'Fabric view and Turbo module', - value: 'view-module-new', - description: NEWARCH_DESCRIPTION, - }, - { - title: 'Native module and Native view', - value: 'view-module-legacy', - description: 'bridge for native APIs and views to JS', - }, { title: 'JavaScript library', value: 'library', @@ -217,6 +203,16 @@ const TYPE_CHOICES: { value: 'module-new', description: NEWARCH_DESCRIPTION, }, + { + title: 'Fabric view with backward compat', + value: 'view-mixed', + description: BACKCOMPAT_DESCRIPTION, + }, + { + title: 'Fabric view', + value: 'view-new', + description: NEWARCH_DESCRIPTION, + }, ]; const args: Record = { @@ -505,8 +501,8 @@ async function create(argv: yargs.Arguments) { authorEmail, authorUrl, repoUrl, - type = 'view-module-mixed', - languages = type === 'library' ? 'js' : 'kotlin-objc', + type = 'module-mixed', + languages = type === 'library' ? 'js' : 'java-objc', example: hasExample, reactNativeVersion, } = { @@ -573,11 +569,13 @@ async function create(argv: yargs.Arguments) { version = FALLBACK_BOB_VERSION; } - const arch = type.endsWith('new') - ? 'new' - : type.endsWith('mixed') - ? 'mixed' - : 'legacy'; + const moduleType = type.startsWith('view-') ? 'view' : 'module'; + const arch = + type === 'module-new' || type === 'view-new' + ? 'new' + : type === 'module-mixed' || type === 'view-mixed' + ? 'mixed' + : 'legacy'; const example = hasExample && !local ? (type === 'library' ? 'expo' : 'native') : 'none'; @@ -620,9 +618,10 @@ async function create(argv: yargs.Arguments) { native: languages !== 'js', arch, cpp: languages === 'cpp', - swift: languages === 'kotlin-swift', - view: type.includes('view'), - module: type.includes('module'), + kotlin: languages === 'kotlin-objc' || languages === 'kotlin-swift', + swift: languages === 'java-swift' || languages === 'kotlin-swift', + view: moduleType === 'view', + module: moduleType === 'module', }, author: { name: authorName, @@ -706,7 +705,7 @@ async function create(argv: yargs.Arguments) { } } - if (type === 'library') { + if (languages === 'js') { await copyDir(JS_FILES, folder); await copyDir(EXPO_FILES, folder); } else { @@ -723,18 +722,29 @@ async function create(argv: yargs.Arguments) { await copyDir(NATIVE_COMMON_EXAMPLE_FILES, folder); } - await copyDir(NATIVE_FILES[type], folder); + if (moduleType === 'module') { + await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder); + } else { + await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder); + } - if ( - type === 'view-legacy' || - (type === 'module-legacy' && options.project.swift) - ) { - await copyDir(SWIFT_FILES[type], folder); + if (options.project.swift) { + await copyDir(SWIFT_FILES[`${moduleType}_legacy`], folder); } else { - await copyDir(OBJC_FILES[type], folder); + if (moduleType === 'module') { + await copyDir(OBJC_FILES[`${moduleType}_common`], folder); + } else { + await copyDir(OBJC_FILES[`view_${arch}`], folder); + } } - await copyDir(KOTLIN_FILES[type], folder); + const templateType = `${moduleType}_${arch}` as const; + + if (options.project.kotlin) { + await copyDir(KOTLIN_FILES[templateType], folder); + } else { + await copyDir(JAVA_FILES[templateType], folder); + } if (options.project.cpp) { await copyDir(CPP_FILES, folder); diff --git a/packages/create-react-native-library/templates/common-example/example/src/App.tsx b/packages/create-react-native-library/templates/common-example/example/src/App.tsx index 55ebf1f82..38db6fe50 100644 --- a/packages/create-react-native-library/templates/common-example/example/src/App.tsx +++ b/packages/create-react-native-library/templates/common-example/example/src/App.tsx @@ -1,9 +1,6 @@ import * as React from 'react'; -<% if (project.view && project.module) { -%> -import { StyleSheet, View, Text } from 'react-native'; -import { <%- project.name -%>View, multiply } from '<%- project.slug -%>'; -<% } else if (project.view) { -%> +<% if (project.view) { -%> import { StyleSheet, View } from 'react-native'; import { <%- project.name -%>View } from '<%- project.slug -%>'; <% } else { -%> @@ -11,30 +8,39 @@ import { StyleSheet, View, Text } from 'react-native'; import { multiply } from '<%- project.slug -%>'; <% } -%> -<% if (project.arch === 'new' && project.module) { -%> +<% if (project.view) { -%> +export default function App() { + return ( + + <<%- project.name -%>View color="#32a852" style={styles.box} /> + + ); +} +<% } else if (project.arch === 'new' && project.module) { -%> const result = multiply(3, 7); -<% } -%> export default function App() { -<% if ((project.arch !== 'new' && project.module) || !project.native) { -%> + return ( + + Result: {result} + + ); +} +<% } else { -%> +export default function App() { const [result, setResult] = React.useState(); React.useEffect(() => { multiply(3, 7).then(setResult); }, []); -<% } -%> return ( -<% if (project.module || !project.native) { -%> Result: {result} -<% } -%> -<% if (project.view) { -%> - <<%- project.name -%>View color="#32a852" style={styles.box} /> -<% } -%> ); } +<% } -%> const styles = StyleSheet.create({ container: { diff --git a/packages/create-react-native-library/templates/common/$package.json b/packages/create-react-native-library/templates/common/$package.json index e86a80224..5cf2ca060 100644 --- a/packages/create-react-native-library/templates/common/$package.json +++ b/packages/create-react-native-library/templates/common/$package.json @@ -169,8 +169,8 @@ <% if (project.arch !== 'legacy') { -%> }, "codegenConfig": { - "name": "RN<%- project.name -%>Spec", - "type": <%- project.view && project.module ? '"all"' : project.view ? '"components"': '"modules"' %>, + "name": "RN<%- project.name -%><%- project.view ? 'View': '' -%>Spec", + "type": <%- project.view ? '"components"': '"modules"' %>, "jsSrcsDir": "src" <% } -%> } diff --git a/packages/create-react-native-library/templates/common/CONTRIBUTING.md b/packages/create-react-native-library/templates/common/CONTRIBUTING.md index 303a6b326..6d2908914 100644 --- a/packages/create-react-native-library/templates/common/CONTRIBUTING.md +++ b/packages/create-react-native-library/templates/common/CONTRIBUTING.md @@ -26,7 +26,7 @@ It is configured to use the local version of the library, so any changes you mak <% if (project.native) { -%> If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/<%- project.name -%>Example.xcworkspace` in XCode and find the source files at `Pods > Development Pods > <%- project.slug -%>`. -To edit the the Kotlin files, open `example/android` in Android studio and find the source files at `<%- project.identifier -%>` under `Android`. +To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `<%- project.identifier -%>` under `Android`. <% } -%> You can use various commands from the root directory to work with the project. diff --git a/packages/create-react-native-library/templates/common/README.md b/packages/create-react-native-library/templates/common/README.md index d42a79cb3..ea2b491f0 100644 --- a/packages/create-react-native-library/templates/common/README.md +++ b/packages/create-react-native-library/templates/common/README.md @@ -18,8 +18,7 @@ import { <%- project.name -%>View } from "<%- project.slug -%>"; <<%- project.name -%>View color="tomato" /> ``` -<% } -%> -<% if (project.module && project.arch === 'new') { -%> +<% } else if (project.arch === 'new' && project.module) { -%> ```js import { multiply } from '<%- project.slug -%>'; @@ -28,7 +27,7 @@ import { multiply } from '<%- project.slug -%>'; const result = multiply(3, 7); ``` -<% } else if (project.module) { -%> +<% } else { -%> ```js import { multiply } from '<%- project.slug -%>'; diff --git a/packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java b/packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java new file mode 100644 index 000000000..798e50429 --- /dev/null +++ b/packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java @@ -0,0 +1,43 @@ +package com.<%- project.package %>; + +import androidx.annotation.NonNull; + +import com.facebook.react.bridge.Promise; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.module.annotations.ReactModule; + +@ReactModule(name = <%- project.name -%>Module.NAME) +public class <%- project.name -%>Module extends ReactContextBaseJavaModule { + public static final String NAME = "<%- project.name -%>"; + + public <%- project.name -%>Module(ReactApplicationContext reactContext) { + super(reactContext); + } + + @Override + @NonNull + public String getName() { + return NAME; + } + +<% if (project.cpp) { -%> + static { + System.loadLibrary("<%- project.identifier -%>"); + } + + private static native double nativeMultiply(double a, double b); +<% } -%> + + // Example method + // See https://reactnative.dev/docs/native-modules-android + @ReactMethod + public void multiply(double a, double b, Promise promise) { +<% if (project.cpp) { -%> + promise.resolve(nativeMultiply(a, b)); +<% } else { -%> + promise.resolve(a * b); +<% } -%> + } +} diff --git a/packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java b/packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java new file mode 100644 index 000000000..0a7e05207 --- /dev/null +++ b/packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java @@ -0,0 +1,28 @@ +package com.<%- project.package %>; + +import androidx.annotation.NonNull; + +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class <%- project.name -%>Package implements ReactPackage { + @NonNull + @Override + public List createNativeModules(@NonNull ReactApplicationContext reactContext) { + List modules = new ArrayList<>(); + modules.add(new <%- project.name -%>Module(reactContext)); + return modules; + } + + @NonNull + @Override + public List createViewManagers(@NonNull ReactApplicationContext reactContext) { + return Collections.emptyList(); + } +} diff --git a/packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java b/packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java new file mode 100644 index 000000000..afd27c5c5 --- /dev/null +++ b/packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java @@ -0,0 +1,40 @@ +package com.<%- project.package %>; + +import androidx.annotation.NonNull; + +import com.facebook.react.bridge.Promise; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactMethod; + +public class <%- project.name -%>Module extends <%- project.name -%>Spec { + public static final String NAME = "<%- project.name -%>"; + + <%- project.name -%>Module(ReactApplicationContext context) { + super(context); + } + + @Override + @NonNull + public String getName() { + return NAME; + } + +<% if (project.cpp) { -%> + static { + System.loadLibrary("<%- project.identifier -%>"); + } + + public static native double nativeMultiply(double a, double b); +<% } -%> + + // Example method + // See https://reactnative.dev/docs/native-modules-android + @ReactMethod + public void multiply(double a, double b, Promise promise) { +<% if (project.cpp) { -%> + promise.resolve(nativeMultiply(a, b)); +<% } else { -%> + promise.resolve(a * b); +<% } -%> + } +} diff --git a/packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java b/packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java new file mode 100644 index 000000000..89e8c71b2 --- /dev/null +++ b/packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java @@ -0,0 +1,45 @@ +package com.<%- project.package %>; + +import androidx.annotation.Nullable; + +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.module.model.ReactModuleInfo; +import com.facebook.react.module.model.ReactModuleInfoProvider; +import com.facebook.react.TurboReactPackage; + +import java.util.HashMap; +import java.util.Map; + +public class <%- project.name -%>Package extends TurboReactPackage { + + @Nullable + @Override + public NativeModule getModule(String name, ReactApplicationContext reactContext) { + if (name.equals(<%- project.name -%>Module.NAME)) { + return new <%- project.name -%>Module(reactContext); + } else { + return null; + } + } + + @Override + public ReactModuleInfoProvider getReactModuleInfoProvider() { + return () -> { + final Map moduleInfos = new HashMap<>(); + boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; + moduleInfos.put( + <%- project.name -%>Module.NAME, + new ReactModuleInfo( + <%- project.name -%>Module.NAME, + <%- project.name -%>Module.NAME, + false, // canOverrideExistingModule + false, // needsEagerInit + true, // hasConstants + false, // isCxxModule + isTurboModule // isTurboModule + )); + return moduleInfos; + }; + } +} diff --git a/packages/create-react-native-library/templates/java-library-mixed/android/src/newarch/{%- project.name %}Spec.java b/packages/create-react-native-library/templates/java-library-mixed/android/src/newarch/{%- project.name %}Spec.java new file mode 100644 index 000000000..4edc2ec82 --- /dev/null +++ b/packages/create-react-native-library/templates/java-library-mixed/android/src/newarch/{%- project.name %}Spec.java @@ -0,0 +1,9 @@ +package com.<%- project.package %>; + +import com.facebook.react.bridge.ReactApplicationContext; + +abstract class <%- project.name -%>Spec extends Native<%- project.name -%>Spec { + <%- project.name -%>Spec(ReactApplicationContext context) { + super(context); + } +} diff --git a/packages/create-react-native-library/templates/java-library-mixed/android/src/oldarch/{%- project.name %}Spec.java b/packages/create-react-native-library/templates/java-library-mixed/android/src/oldarch/{%- project.name %}Spec.java new file mode 100644 index 000000000..350d05a34 --- /dev/null +++ b/packages/create-react-native-library/templates/java-library-mixed/android/src/oldarch/{%- project.name %}Spec.java @@ -0,0 +1,13 @@ +package com.<%- project.package %>; + +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.Promise; + +abstract class <%- project.name -%>Spec extends ReactContextBaseJavaModule { + <%- project.name -%>Spec(ReactApplicationContext context) { + super(context); + } + + public abstract void multiply(double a, double b, Promise promise); +} diff --git a/packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java b/packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java new file mode 100644 index 000000000..e9a2e6aaf --- /dev/null +++ b/packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java @@ -0,0 +1,40 @@ +package com.<%- project.package %>; + +import androidx.annotation.NonNull; + +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.module.annotations.ReactModule; + +@ReactModule(name = <%- project.name -%>Module.NAME) +public class <%- project.name -%>Module extends Native<%- project.name -%>Spec { + public static final String NAME = "<%- project.name -%>"; + + public <%- project.name -%>Module(ReactApplicationContext reactContext) { + super(reactContext); + } + + @Override + @NonNull + public String getName() { + return NAME; + } + +<% if (project.cpp) { -%> + static { + System.loadLibrary("<%- project.identifier -%>"); + } + + private static native double nativeMultiply(double a, double b); +<% } -%> + + // Example method + // See https://reactnative.dev/docs/native-modules-android + @Override + public double multiply(double a, double b) { +<% if (project.cpp) { -%> + return nativeMultiply(a, b); +<% } else { -%> + return a * b; +<% } -%> + } +} diff --git a/packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java b/packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java new file mode 100644 index 000000000..bcc5307ba --- /dev/null +++ b/packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java @@ -0,0 +1,44 @@ +package com.<%- project.package %>; + +import androidx.annotation.Nullable; + +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.module.model.ReactModuleInfo; +import com.facebook.react.module.model.ReactModuleInfoProvider; +import com.facebook.react.TurboReactPackage; + +import java.util.HashMap; +import java.util.Map; + +public class <%- project.name -%>Package extends TurboReactPackage { + + @Nullable + @Override + public NativeModule getModule(String name, ReactApplicationContext reactContext) { + if (name.equals(<%- project.name -%>Module.NAME)) { + return new <%- project.name -%>Module(reactContext); + } else { + return null; + } + } + + @Override + public ReactModuleInfoProvider getReactModuleInfoProvider() { + return () -> { + final Map moduleInfos = new HashMap<>(); + moduleInfos.put( + <%- project.name -%>Module.NAME, + new ReactModuleInfo( + <%- project.name -%>Module.NAME, + <%- project.name -%>Module.NAME, + false, // canOverrideExistingModule + false, // needsEagerInit + true, // hasConstants + false, // isCxxModule + true // isTurboModule + )); + return moduleInfos; + }; + } +} diff --git a/packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java b/packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java new file mode 100644 index 000000000..f8626aab1 --- /dev/null +++ b/packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java @@ -0,0 +1,22 @@ +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; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class <%- project.name -%>Package implements ReactPackage { + @Override + public List createNativeModules(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } + + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return Arrays.asList(new <%- project.name -%>ViewManager()); + } +} diff --git a/packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java b/packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java new file mode 100644 index 000000000..9fa0a42bc --- /dev/null +++ b/packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java @@ -0,0 +1,31 @@ +package com.<%- project.package %>; + +import android.graphics.Color; +import android.view.View; + +import androidx.annotation.NonNull; + +import com.facebook.react.uimanager.SimpleViewManager; +import com.facebook.react.uimanager.ThemedReactContext; +import com.facebook.react.uimanager.annotations.ReactProp; + +public class <%- project.name -%>ViewManager extends SimpleViewManager { + public static final String REACT_CLASS = "<%- project.name -%>View"; + + @Override + @NonNull + public String getName() { + return REACT_CLASS; + } + + @Override + @NonNull + public View createViewInstance(ThemedReactContext reactContext) { + return new View(reactContext); + } + + @ReactProp(name = "color") + public void setColor(View view, String color) { + view.setBackgroundColor(Color.parseColor(color)); + } +} diff --git a/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java b/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java new file mode 100644 index 000000000..d053791f8 --- /dev/null +++ b/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java @@ -0,0 +1,24 @@ +package com.<%- project.package %>; + +import androidx.annotation.Nullable; + +import android.content.Context; +import android.util.AttributeSet; + +import android.view.View; + +public class <%- project.name -%>View extends View { + + public <%- project.name -%>View(Context context) { + super(context); + } + + public <%- project.name -%>View(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public <%- project.name -%>View(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + +} diff --git a/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java b/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java new file mode 100644 index 000000000..7442a7b44 --- /dev/null +++ b/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java @@ -0,0 +1,31 @@ +package com.<%- project.package %>; + +import android.graphics.Color; + +import androidx.annotation.Nullable; + +import com.facebook.react.module.annotations.ReactModule; +import com.facebook.react.uimanager.ThemedReactContext; +import com.facebook.react.uimanager.annotations.ReactProp; + +@ReactModule(name = <%- project.name -%>ViewManager.NAME) +public class <%- project.name -%>ViewManager extends <%- project.name -%>ViewManagerSpec<<%- project.name -%>View> { + + public static final String NAME = "<%- project.name -%>View"; + + @Override + public String getName() { + return NAME; + } + + @Override + public <%- project.name -%>View createViewInstance(ThemedReactContext context) { + return new <%- project.name -%>View(context); + } + + @Override + @ReactProp(name = "color") + public void setColor(<%- project.name -%>View view, @Nullable String color) { + view.setBackgroundColor(Color.parseColor(color)); + } +} diff --git a/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java b/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java new file mode 100644 index 000000000..c46da2710 --- /dev/null +++ b/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java @@ -0,0 +1,25 @@ +<% /* TODO: try to migrate it to TurboReactPackage */ %> +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; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class <%- project.name -%>ViewPackage implements ReactPackage { + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + List viewManagers = new ArrayList<>(); + viewManagers.add(new <%- project.name -%>ViewManager()); + return viewManagers; + } + + @Override + public List createNativeModules(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } +} diff --git a/packages/create-react-native-library/templates/java-view-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.java b/packages/create-react-native-library/templates/java-view-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.java new file mode 100644 index 000000000..763f28eaa --- /dev/null +++ b/packages/create-react-native-library/templates/java-view-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.java @@ -0,0 +1,24 @@ +package com.<%- project.package %>; + +import android.view.View; + +import androidx.annotation.Nullable; + +import com.facebook.react.uimanager.SimpleViewManager; +import com.facebook.react.uimanager.ViewManagerDelegate; +import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerDelegate; +import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerInterface; + +public abstract class <%- project.name -%>ViewManagerSpec extends SimpleViewManager implements <%- project.name -%>ViewManagerInterface { + private final ViewManagerDelegate mDelegate; + + public <%- project.name -%>ViewManagerSpec() { + mDelegate = new <%- project.name -%>ViewManagerDelegate(this); + } + + @Nullable + @Override + protected ViewManagerDelegate getDelegate() { + return mDelegate; + } +} diff --git a/packages/create-react-native-library/templates/java-view-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.java b/packages/create-react-native-library/templates/java-view-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.java new file mode 100644 index 000000000..0962fb3d1 --- /dev/null +++ b/packages/create-react-native-library/templates/java-view-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.java @@ -0,0 +1,12 @@ +package com.<%- project.package %>; + +import android.view.View; + +import androidx.annotation.Nullable; + +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.SimpleViewManager; + +public abstract class <%- project.name -%>ViewManagerSpec extends SimpleViewManager { + public abstract void setColor(T view, @Nullable String value); +} diff --git a/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java b/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java new file mode 100644 index 000000000..d053791f8 --- /dev/null +++ b/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java @@ -0,0 +1,24 @@ +package com.<%- project.package %>; + +import androidx.annotation.Nullable; + +import android.content.Context; +import android.util.AttributeSet; + +import android.view.View; + +public class <%- project.name -%>View extends View { + + public <%- project.name -%>View(Context context) { + super(context); + } + + public <%- project.name -%>View(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public <%- project.name -%>View(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + +} diff --git a/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java b/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java new file mode 100644 index 000000000..6360c1940 --- /dev/null +++ b/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java @@ -0,0 +1,47 @@ +package com.<%- project.package %>; + +import android.graphics.Color; + +import androidx.annotation.Nullable; + +import com.facebook.react.module.annotations.ReactModule; +import com.facebook.react.uimanager.SimpleViewManager; +import com.facebook.react.uimanager.ThemedReactContext; +import com.facebook.react.uimanager.ViewManagerDelegate; +import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerDelegate; +import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerInterface; + +@ReactModule(name = <%- project.name -%>ViewManager.NAME) +public class <%- project.name -%>ViewManager extends SimpleViewManager<<%- project.name -%>View> implements <%- project.name -%>ViewManagerInterface<<%- project.name -%>View> { + + public static final String NAME = "<%- project.name -%>View"; + + private final ViewManagerDelegate<<%- project.name -%>View> mDelegate; + + public <%- project.name -%>ViewManager() { + mDelegate = new <%- project.name -%>ViewManagerDelegate(this); + } + + @Nullable + @Override + protected ViewManagerDelegate<<%- project.name -%>View> getDelegate() { + return mDelegate; + } + + @Override + public String getName() { + return NAME; + } + + @Override + public <%- project.name -%>View createViewInstance(ThemedReactContext context) { + return new <%- project.name -%>View(context); + } + + @Override + @ReactProp(name = "color") + public void setColor(<%- project.name -%>View view, String color) { + view.setBackgroundColor(Color.parseColor(color)); + } +} diff --git a/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java b/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java new file mode 100644 index 000000000..c46da2710 --- /dev/null +++ b/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java @@ -0,0 +1,25 @@ +<% /* TODO: try to migrate it to TurboReactPackage */ %> +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; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class <%- project.name -%>ViewPackage implements ReactPackage { + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + List viewManagers = new ArrayList<>(); + viewManagers.add(new <%- project.name -%>ViewManager()); + return viewManagers; + } + + @Override + public List createNativeModules(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } +} diff --git a/packages/create-react-native-library/templates/kotlin-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt b/packages/create-react-native-library/templates/kotlin-view-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-view-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-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt deleted file mode 100644 index dbd7eec4e..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.BaseReactPackage -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.NativeModule -import com.facebook.react.module.model.ReactModuleInfoProvider -import com.facebook.react.module.model.ReactModuleInfo -import com.facebook.react.uimanager.ViewManager -import java.util.HashMap - -class <%- project.name -%>Package : BaseReactPackage() { - override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { - return if (name == <%- project.name -%>Module.NAME) { - <%- project.name -%>Module(reactContext) - } else { - null - } - } - - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { - val moduleInfos: MutableMap = HashMap() - moduleInfos[<%- project.name -%>Module.NAME] = ReactModuleInfo( - <%- project.name -%>Module.NAME, - <%- project.name -%>Module.NAME, - false, // canOverrideExistingModule - false, // needsEagerInit - true, // hasConstants - false, // isCxxModule - false // isTurboModule - ) - moduleInfos - } - } - - override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return mutableListOf(<%- project.name -%>ViewManager()); - } -} diff --git a/packages/create-react-native-library/templates/kotlin-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt b/packages/create-react-native-library/templates/kotlin-view-library-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-library-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/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt deleted file mode 100644 index 2cf84d752..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.ReactMethod -import com.facebook.react.bridge.Promise - -class <%- project.name -%>Module internal constructor(context: ReactApplicationContext) : - <%- project.name -%>Spec(context) { - - override fun getName(): String { - return NAME - } - - // Example method - // See https://reactnative.dev/docs/native-modules-android - @ReactMethod - override 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-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt deleted file mode 100644 index fae83afe0..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.BaseReactPackage -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.NativeModule -import com.facebook.react.module.model.ReactModuleInfoProvider -import com.facebook.react.module.model.ReactModuleInfo -import com.facebook.react.uimanager.ViewManager -import java.util.HashMap - -class <%- project.name -%>Package : BaseReactPackage() { - override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { - return if (name == <%- project.name -%>Module.NAME) { - <%- project.name -%>Module(reactContext) - } else { - null - } - } - - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { - val moduleInfos: MutableMap = HashMap() - val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED - moduleInfos[<%- project.name -%>Module.NAME] = ReactModuleInfo( - <%- project.name -%>Module.NAME, - <%- project.name -%>Module.NAME, - false, // canOverrideExistingModule - false, // needsEagerInit - true, // hasConstants - false, // isCxxModule - isTurboModule // isTurboModule - ) - moduleInfos - } - } - - override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return mutableListOf(<%- project.name -%>ViewManager()); - } -} diff --git a/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/newarch/{%- project.name %}Spec.kt b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/newarch/{%- project.name %}Spec.kt deleted file mode 100644 index 3711dacb2..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/newarch/{%- project.name %}Spec.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.bridge.ReactApplicationContext - -abstract class <%- project.name -%>Spec internal constructor(context: ReactApplicationContext) : - Native<%- project.name -%>Spec(context) { -} diff --git a/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt deleted file mode 100644 index ef0259618..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.ReactContextBaseJavaModule -import com.facebook.react.bridge.Promise - -abstract class <%- project.name -%>Spec internal constructor(context: ReactApplicationContext) : - ReactContextBaseJavaModule(context) { - - abstract fun multiply(a: Double, b: Double, promise: Promise) -} diff --git a/packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt b/packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt deleted file mode 100644 index 5da133031..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.module.annotations.ReactModule - -@ReactModule(name = <%- project.name -%>Module.NAME) -class <%- project.name -%>Module(reactContext: ReactApplicationContext) : - Native<%- project.name -%>Spec(reactContext) { - - override fun getName(): String { - return NAME - } - - // Example method - // See https://reactnative.dev/docs/native-modules-android - override fun multiply(a: Double, b: Double): Double { - return a * b - } - - companion object { - const val NAME = "<%- project.name -%>" - } -} diff --git a/packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt deleted file mode 100644 index fae83afe0..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.BaseReactPackage -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.NativeModule -import com.facebook.react.module.model.ReactModuleInfoProvider -import com.facebook.react.module.model.ReactModuleInfo -import com.facebook.react.uimanager.ViewManager -import java.util.HashMap - -class <%- project.name -%>Package : BaseReactPackage() { - override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { - return if (name == <%- project.name -%>Module.NAME) { - <%- project.name -%>Module(reactContext) - } else { - null - } - } - - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { - val moduleInfos: MutableMap = HashMap() - val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED - moduleInfos[<%- project.name -%>Module.NAME] = ReactModuleInfo( - <%- project.name -%>Module.NAME, - <%- project.name -%>Module.NAME, - false, // canOverrideExistingModule - false, // needsEagerInit - true, // hasConstants - false, // isCxxModule - isTurboModule // isTurboModule - ) - moduleInfos - } - } - - override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return mutableListOf(<%- project.name -%>ViewManager()); - } -} diff --git a/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt new file mode 100644 index 000000000..9f3ab9124 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt @@ -0,0 +1,19 @@ +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 +import java.util.ArrayList + +class <%- project.name -%>ViewPackage : ReactPackage { + override fun createViewManagers(reactContext: ReactApplicationContext): List> { + val viewManagers: MutableList> = ArrayList() + viewManagers.add(<%- project.name -%>ViewManager()) + return viewManagers + } + + override fun createNativeModules(reactContext: ReactApplicationContext): List { + return emptyList() + } +} diff --git a/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt b/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt similarity index 100% rename from packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt rename to packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt diff --git a/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt b/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt similarity index 100% rename from packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt rename to packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt diff --git a/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.kt b/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.kt similarity index 100% rename from packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.kt rename to packages/create-react-native-library/templates/kotlin-view-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.kt diff --git a/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.kt b/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.kt similarity index 100% rename from packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.kt rename to packages/create-react-native-library/templates/kotlin-view-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.kt diff --git a/packages/create-react-native-library/templates/kotlin-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt new file mode 100644 index 000000000..9f3ab9124 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt @@ -0,0 +1,19 @@ +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 +import java.util.ArrayList + +class <%- project.name -%>ViewPackage : ReactPackage { + override fun createViewManagers(reactContext: ReactApplicationContext): List> { + val viewManagers: MutableList> = ArrayList() + viewManagers.add(<%- project.name -%>ViewManager()) + return viewManagers + } + + override fun createNativeModules(reactContext: ReactApplicationContext): List { + return emptyList() + } +} diff --git a/packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt b/packages/create-react-native-library/templates/kotlin-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt similarity index 100% rename from packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt rename to packages/create-react-native-library/templates/kotlin-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt diff --git a/packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt b/packages/create-react-native-library/templates/kotlin-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt similarity index 100% rename from packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt rename to packages/create-react-native-library/templates/kotlin-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt 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 fb68eaefe..e0e3a6428 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 @@ -1,7 +1,9 @@ buildscript { +<% if (project.kotlin) { -%> // Buildscript is evaluated before everything else so we can't use getExtOrDefault def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["<%- project.name -%>_kotlinVersion"] +<% } -%> repositories { google() mavenCentral() @@ -9,8 +11,10 @@ buildscript { dependencies { classpath "com.android.tools.build:gradle:7.2.1" +<% if (project.kotlin) { -%> // noinspection DifferentKotlinGradleVersion classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" +<% } -%> } } @@ -24,7 +28,9 @@ def isNewArchitectureEnabled() { } apply plugin: "com.android.library" +<% if (project.kotlin) { -%> apply plugin: "kotlin-android" +<% } -%> if (isNewArchitectureEnabled()) { apply plugin: "com.facebook.react" @@ -143,14 +149,18 @@ repositories { google() } +<% if (project.kotlin) { -%> def kotlin_version = getExtOrDefault("kotlinVersion") +<% } -%> dependencies { // For < 0.71, this will be from the local maven repo // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" +<% if (project.kotlin) { -%> implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" +<% } -%> } <% if (project.arch === "new" || project.arch === "mixed") { -%> diff --git a/packages/create-react-native-library/templates/native-view-library-legacy/src/index.tsx b/packages/create-react-native-library/templates/native-view-library-legacy/src/index.tsx deleted file mode 100644 index 0619f4994..000000000 --- a/packages/create-react-native-library/templates/native-view-library-legacy/src/index.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import { <%- project.name -%> } from './<%- project.name -%>'; - -export function multiply(a: number, b: number): Promise { - return <%- project.name -%>.multiply(a, b); -} - -export * from './<%- project.name -%>View'; diff --git a/packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}.ts b/packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}.ts deleted file mode 100644 index 220e70cd2..000000000 --- a/packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}.ts +++ /dev/null @@ -1,18 +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'; - -export const <%- project.name -%> = NativeModules.<%- project.name %> - ? NativeModules.<%- project.name %> - : new Proxy( - {}, - { - get() { - throw new Error(LINKING_ERROR); - }, - } - ); diff --git a/packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}View.ts b/packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}View.ts deleted file mode 100644 index 055016821..000000000 --- a/packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}View.ts +++ /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/native-view-library-mixed/src/Native{%- project.name %}.ts b/packages/create-react-native-library/templates/native-view-library-mixed/src/Native{%- project.name %}.ts deleted file mode 100644 index 166b44ed7..000000000 --- a/packages/create-react-native-library/templates/native-view-library-mixed/src/Native{%- project.name %}.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { TurboModule } from 'react-native'; -import { TurboModuleRegistry } from 'react-native'; - -export interface Spec extends TurboModule { - multiply(a: number, b: number): Promise; -} - -export default TurboModuleRegistry.getEnforcing('<%- project.name -%>'); diff --git a/packages/create-react-native-library/templates/native-view-library-mixed/src/index.tsx b/packages/create-react-native-library/templates/native-view-library-mixed/src/index.tsx deleted file mode 100644 index d4979707a..000000000 --- a/packages/create-react-native-library/templates/native-view-library-mixed/src/index.tsx +++ /dev/null @@ -1,32 +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'; - -// @ts-expect-error -const isTurboModuleEnabled = global.__turboModuleProxy != null; - -const <%- project.name -%>Module = isTurboModuleEnabled - ? require('./Native<%- project.name -%>').default - : NativeModules.<%- project.name -%>; - -const <%- project.name -%> = <%- project.name -%>Module - ? <%- project.name -%>Module - : new Proxy( - {}, - { - get() { - throw new Error(LINKING_ERROR); - }, - } - ); - -export function multiply(a: number, b: number): Promise { - return <%- project.name -%>.multiply(a, b); -} - -export { default as <%- project.name -%>View } from './<%- project.name -%>NativeComponent'; -export * from './<%- project.name -%>NativeComponent'; diff --git a/packages/create-react-native-library/templates/native-view-library-new/src/Native{%- project.name %}.ts b/packages/create-react-native-library/templates/native-view-library-new/src/Native{%- project.name %}.ts deleted file mode 100644 index b6f84feb8..000000000 --- a/packages/create-react-native-library/templates/native-view-library-new/src/Native{%- project.name %}.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { TurboModule } from 'react-native'; -import { TurboModuleRegistry } from 'react-native'; - -export interface Spec extends TurboModule { - multiply(a: number, b: number): number; -} - -export default TurboModuleRegistry.getEnforcing('<%- project.name -%>'); diff --git a/packages/create-react-native-library/templates/native-view-library-new/src/index.tsx b/packages/create-react-native-library/templates/native-view-library-new/src/index.tsx deleted file mode 100644 index d98e51a06..000000000 --- a/packages/create-react-native-library/templates/native-view-library-new/src/index.tsx +++ /dev/null @@ -1,8 +0,0 @@ -const <%- project.name -%> = require('./Native<%- project.name -%>').default; - -export function multiply(a: number, b: number): number { - return <%- project.name -%>.multiply(a, b); -} - -export { default as <%- project.name -%>View } from './<%- project.name -%>NativeComponent'; -export * from './<%- project.name -%>NativeComponent'; diff --git a/packages/create-react-native-library/templates/native-view-mixed/src/index.tsx b/packages/create-react-native-library/templates/native-view-mixed/src/index.tsx new file mode 100644 index 000000000..7a2bfbdc2 --- /dev/null +++ b/packages/create-react-native-library/templates/native-view-mixed/src/index.tsx @@ -0,0 +1,2 @@ +export { default as <%- project.name -%>View } from './<%- project.name -%>ViewNativeComponent'; +export * from './<%- project.name -%>ViewNativeComponent'; diff --git a/packages/create-react-native-library/templates/native-view-library-mixed/src/{%- project.name %}NativeComponent.ts b/packages/create-react-native-library/templates/native-view-mixed/src/{%- project.name %}ViewNativeComponent.ts similarity index 100% rename from packages/create-react-native-library/templates/native-view-library-mixed/src/{%- project.name %}NativeComponent.ts rename to packages/create-react-native-library/templates/native-view-mixed/src/{%- project.name %}ViewNativeComponent.ts diff --git a/packages/create-react-native-library/templates/native-view-new/src/index.tsx b/packages/create-react-native-library/templates/native-view-new/src/index.tsx new file mode 100644 index 000000000..7a2bfbdc2 --- /dev/null +++ b/packages/create-react-native-library/templates/native-view-new/src/index.tsx @@ -0,0 +1,2 @@ +export { default as <%- project.name -%>View } from './<%- project.name -%>ViewNativeComponent'; +export * from './<%- project.name -%>ViewNativeComponent'; diff --git a/packages/create-react-native-library/templates/native-view-library-new/src/{%- project.name %}NativeComponent.ts b/packages/create-react-native-library/templates/native-view-new/src/{%- project.name %}ViewNativeComponent.ts similarity index 100% rename from packages/create-react-native-library/templates/native-view-library-new/src/{%- project.name %}NativeComponent.ts rename to packages/create-react-native-library/templates/native-view-new/src/{%- project.name %}ViewNativeComponent.ts diff --git a/packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}ViewManager.m b/packages/create-react-native-library/templates/objc-view-legacy/ios/{%- project.name %}ViewManager.m similarity index 100% rename from packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}ViewManager.m rename to packages/create-react-native-library/templates/objc-view-legacy/ios/{%- project.name %}ViewManager.m diff --git a/packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.h b/packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.h deleted file mode 100644 index 99f7c846b..000000000 --- a/packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.h +++ /dev/null @@ -1,6 +0,0 @@ -#import - -@interface <%- project.name -%> : NSObject -#endif - -@end diff --git a/packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.mm b/packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.mm deleted file mode 100644 index 5289baf7b..000000000 --- a/packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.mm +++ /dev/null @@ -1,18 +0,0 @@ -#import "<%- project.name -%>.h" - -@implementation <%- project.name -%> - -RCT_EXPORT_MODULE() - -// 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) -{ - NSNumber *result = @(a * b); - resolve(result); -} - -@end diff --git a/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.h b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.h deleted file mode 100644 index 32ed3c4b5..000000000 --- a/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.h +++ /dev/null @@ -1,17 +0,0 @@ -<% if (project.cpp) { -%> -#ifdef __cplusplus -#import "<%- project.identifier -%>.h" -#endif -<% } -%> - -#ifdef RCT_NEW_ARCH_ENABLED -#import "RN<%- project.name -%>Spec.h" - -@interface <%- project.name -%> : NSObject Spec> -#else -#import - -@interface <%- project.name -%> : NSObject -#endif - -@end diff --git a/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.mm b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.mm deleted file mode 100644 index 7650a9fe4..000000000 --- a/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.mm +++ /dev/null @@ -1,48 +0,0 @@ -#import "<%- project.name -%>.h" - -@implementation <%- project.name -%> - -RCT_EXPORT_MODULE() - -<% if (project.arch === 'legacy' || project.arch === 'mixed') { -%> -// 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' || project.arch === 'mixed') { -%> -// Don't compile this code when we build for the old architecture. -#ifdef RCT_NEW_ARCH_ENABLED -<% 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; -} - -<% } -%> -- (std::shared_ptr)getTurboModule: - (const facebook::react::ObjCTurboModule::InitParams &)params -{ - return std::make_sharedSpecJSI>(params); -} -#endif -<% } -%> - -@end diff --git a/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.h b/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.h deleted file mode 100644 index 32ed3c4b5..000000000 --- a/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.h +++ /dev/null @@ -1,17 +0,0 @@ -<% if (project.cpp) { -%> -#ifdef __cplusplus -#import "<%- project.identifier -%>.h" -#endif -<% } -%> - -#ifdef RCT_NEW_ARCH_ENABLED -#import "RN<%- project.name -%>Spec.h" - -@interface <%- project.name -%> : NSObject Spec> -#else -#import - -@interface <%- project.name -%> : NSObject -#endif - -@end diff --git a/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.mm b/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.mm deleted file mode 100644 index 7650a9fe4..000000000 --- a/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.mm +++ /dev/null @@ -1,48 +0,0 @@ -#import "<%- project.name -%>.h" - -@implementation <%- project.name -%> - -RCT_EXPORT_MODULE() - -<% if (project.arch === 'legacy' || project.arch === 'mixed') { -%> -// 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' || project.arch === 'mixed') { -%> -// Don't compile this code when we build for the old architecture. -#ifdef RCT_NEW_ARCH_ENABLED -<% 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; -} - -<% } -%> -- (std::shared_ptr)getTurboModule: - (const facebook::react::ObjCTurboModule::InitParams &)params -{ - return std::make_sharedSpecJSI>(params); -} -#endif -<% } -%> - -@end diff --git a/packages/create-react-native-library/templates/objc-view-library-mixed/ios/Utils.h b/packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.h similarity index 100% rename from packages/create-react-native-library/templates/objc-view-library-mixed/ios/Utils.h rename to packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.h diff --git a/packages/create-react-native-library/templates/objc-view-library-mixed/ios/Utils.m b/packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.m similarity index 100% rename from packages/create-react-native-library/templates/objc-view-library-mixed/ios/Utils.m rename to packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.m diff --git a/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}View.h b/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.h similarity index 100% rename from packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}View.h rename to packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.h diff --git a/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}View.mm b/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.mm similarity index 81% rename from packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}View.mm rename to packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.mm index fb815ff30..ff8ae754c 100644 --- a/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}View.mm +++ b/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.mm @@ -1,10 +1,10 @@ #ifdef RCT_NEW_ARCH_ENABLED #import "<%- project.name -%>View.h" -#import Spec/ComponentDescriptors.h> -#import Spec/EventEmitters.h> -#import Spec/Props.h> -#import Spec/RCTComponentViewHelpers.h> +#import ViewSpec/ComponentDescriptors.h> +#import ViewSpec/EventEmitters.h> +#import ViewSpec/Props.h> +#import ViewSpec/RCTComponentViewHelpers.h> #import "RCTFabricComponentsPlugins.h" #import "Utils.h" diff --git a/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}ViewManager.mm b/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}ViewManager.mm similarity index 100% rename from packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}ViewManager.mm rename to packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}ViewManager.mm diff --git a/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}View.h b/packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}View.h similarity index 100% rename from packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}View.h rename to packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}View.h diff --git a/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}View.mm b/packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}View.mm similarity index 84% rename from packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}View.mm rename to packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}View.mm index 0b73c7b1d..46e92936f 100644 --- a/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}View.mm +++ b/packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}View.mm @@ -1,9 +1,9 @@ #import "<%- project.name -%>View.h" -#import Spec/ComponentDescriptors.h> -#import Spec/EventEmitters.h> -#import Spec/Props.h> -#import Spec/RCTComponentViewHelpers.h> +#import ViewSpec/ComponentDescriptors.h> +#import ViewSpec/EventEmitters.h> +#import ViewSpec/Props.h> +#import ViewSpec/RCTComponentViewHelpers.h> #import "RCTFabricComponentsPlugins.h" diff --git a/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}ViewManager.mm b/packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}ViewManager.mm similarity index 100% rename from packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}ViewManager.mm rename to packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}ViewManager.mm