diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index 67c3788ff..e35746602 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -31,10 +31,8 @@ jobs: - macos-14 # macos latest defaults to macos 12 at the moment. type: - module-legacy - - module-mixed - module-new - view-legacy - - view-mixed - view-new language: - kotlin-objc @@ -44,41 +42,17 @@ jobs: exclude: - type: module-new language: kotlin-swift - - type: module-mixed - language: kotlin-swift - type: view-new language: kotlin-swift - - type: view-mixed - language: kotlin-swift include: - os: ubuntu-latest type: library language: js arch: auto - - os: ubuntu-latest - type: module-mixed - language: kotlin-objc - arch: new - - os: macos-14 - type: module-mixed - language: kotlin-objc - arch: new - - os: ubuntu-latest - type: view-mixed - language: kotlin-objc - arch: new - - os: macos-14 - type: view-mixed - language: kotlin-objc - arch: new - os: ubuntu-latest type: module-legacy language: cpp arch: auto - - os: ubuntu-latest - type: module-mixed - language: cpp - arch: auto - os: ubuntu-latest type: module-new language: cpp @@ -87,10 +61,6 @@ jobs: type: module-legacy language: cpp arch: auto - - os: macos-14 - type: module-mixed - language: cpp - arch: auto - os: macos-14 type: module-new language: cpp diff --git a/packages/create-react-native-library/src/exampleApp/generateExampleApp.ts b/packages/create-react-native-library/src/exampleApp/generateExampleApp.ts index 64001742c..1fb4d76a1 100644 --- a/packages/create-react-native-library/src/exampleApp/generateExampleApp.ts +++ b/packages/create-react-native-library/src/exampleApp/generateExampleApp.ts @@ -51,7 +51,7 @@ export default async function generateExampleApp({ }: { type: ExampleApp; dest: string; - arch: 'new' | 'mixed' | 'legacy'; + arch: 'new' | 'legacy'; project: { slug: string; name: string; diff --git a/packages/create-react-native-library/src/input.ts b/packages/create-react-native-library/src/input.ts index 98c03f8a1..97fe9057e 100644 --- a/packages/create-react-native-library/src/input.ts +++ b/packages/create-react-native-library/src/input.ts @@ -21,11 +21,9 @@ export type ArgName = export type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js'; export type ProjectType = - | 'module-legacy' | 'module-new' - | 'module-mixed' - | 'view-mixed' | 'view-new' + | 'module-legacy' | 'view-legacy' | 'library'; @@ -37,14 +35,7 @@ const LANGUAGE_CHOICES: { { title: 'Kotlin & Objective-C', value: 'kotlin-objc', - types: [ - 'module-legacy', - 'module-new', - 'module-mixed', - 'view-mixed', - 'view-new', - 'view-legacy', - ], + types: ['module-new', 'view-new', 'module-legacy', 'view-legacy'], }, { title: 'Kotlin & Swift', @@ -54,7 +45,7 @@ const LANGUAGE_CHOICES: { { title: 'C++ for Android & iOS', value: 'cpp', - types: ['module-legacy', 'module-mixed', 'module-new'], + types: ['module-new', 'module-legacy'], }, { title: 'JavaScript for Android, iOS & Web', @@ -88,9 +79,6 @@ const EXAMPLE_CHOICES = ( ] as const ).filter((choice) => !choice.disabled); -const NEWARCH_DESCRIPTION = 'requires new arch (experimental)'; -const BACKCOMPAT_DESCRIPTION = 'supports new arch (experimental)'; - const TYPE_CHOICES: { title: string; value: ProjectType; @@ -101,35 +89,25 @@ const TYPE_CHOICES: { value: 'library', description: 'supports Expo Go and Web', }, - { - title: 'Native module', - value: 'module-legacy', - description: 'bridge for native APIs to JS', - }, - { - title: 'Native view', - value: 'view-legacy', - description: 'bridge for native views to JS', - }, - { - title: 'Turbo module with backward compat', - value: 'module-mixed', - description: BACKCOMPAT_DESCRIPTION, - }, { title: 'Turbo module', value: 'module-new', - description: NEWARCH_DESCRIPTION, - }, - { - title: 'Fabric view with backward compat', - value: 'view-mixed', - description: BACKCOMPAT_DESCRIPTION, + description: 'integration for native APIs to JS', }, { title: 'Fabric view', value: 'view-new', - description: NEWARCH_DESCRIPTION, + description: 'integration for native views to JS', + }, + { + title: 'Legacy Native module', + value: 'module-legacy', + description: 'bridge for native APIs to JS (old architecture)', + }, + { + title: 'Legacy Native view', + value: 'view-legacy', + description: 'bridge for native views to JS (old architecture)', }, ]; @@ -190,7 +168,7 @@ export const acceptedArgs: Record = { } as const; export type Args = Record; -export type SupportedArchitecture = 'new' | 'mixed' | 'legacy'; +export type SupportedArchitecture = 'new' | 'legacy'; export type ExampleApp = 'none' | 'test-app' | 'expo' | 'vanilla'; export type Answers = { diff --git a/packages/create-react-native-library/src/template.ts b/packages/create-react-native-library/src/template.ts index 9800ebc8d..94d440db7 100644 --- a/packages/create-react-native-library/src/template.ts +++ b/packages/create-react-native-library/src/template.ts @@ -40,11 +40,21 @@ const BINARIES = [ ]; const COMMON_FILES = path.resolve(__dirname, '../templates/common'); -const COMMON_EXAMPLE_FILES = path.resolve( +const COMMON_LOCAL_FILES = path.resolve(__dirname, '../templates/common-local'); +const EXAMPLE_COMMON_FILES = path.resolve( __dirname, - '../templates/common-example' + '../templates/example-common' ); -const COMMON_LOCAL_FILES = path.resolve(__dirname, '../templates/common-local'); +const EXAMPLE_MODULE_LEGACY_FILES = path.resolve( + __dirname, + '../templates/example-module-legacy' +); +const EXAMPLE_MODULE_NEW_FILES = path.resolve( + __dirname, + '../templates/example-module-new' +); +const EXAMPLE_VIEW_FILES = path.resolve(__dirname, '../templates/example-view'); + const JS_FILES = path.resolve(__dirname, '../templates/js-library'); const EXPO_FILES = path.resolve(__dirname, '../templates/expo-library'); const CPP_FILES = path.resolve(__dirname, '../templates/cpp-library'); @@ -60,25 +70,20 @@ 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_mixed: path.resolve(__dirname, '../templates/native-view-mixed'), view_new: path.resolve(__dirname, '../templates/native-view-new'), } as const; const OBJC_FILES = { 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_mixed: path.resolve(__dirname, '../templates/kotlin-view-mixed'), view_new: path.resolve(__dirname, '../templates/kotlin-view-new'), } as const; @@ -99,11 +104,7 @@ export function generateTemplateConfiguration({ const { slug, languages, type } = answers; const arch = - type === 'module-new' || type === 'view-new' - ? 'new' - : type === 'module-mixed' || type === 'view-mixed' - ? 'mixed' - : 'legacy'; + type === 'module-legacy' || type === 'view-legacy' ? 'legacy' : 'new'; const project = slug.replace(/^(react-native-|@[^/]+\/)/, ''); let namespace: string | undefined; @@ -169,7 +170,17 @@ export async function applyTemplates( await applyTemplate(config, COMMON_FILES, folder); if (config.example !== 'none') { - await applyTemplate(config, COMMON_EXAMPLE_FILES, folder); + await applyTemplate(config, EXAMPLE_COMMON_FILES, folder); + + if (config.project.view) { + await applyTemplate(config, EXAMPLE_VIEW_FILES, folder); + } else { + if (config.project.arch === 'legacy') { + await applyTemplate(config, EXAMPLE_MODULE_LEGACY_FILES, folder); + } else { + await applyTemplate(config, EXAMPLE_MODULE_NEW_FILES, folder); + } + } } } 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 deleted file mode 100644 index acc5c7d17..000000000 --- a/packages/create-react-native-library/templates/common-example/example/src/App.tsx +++ /dev/null @@ -1,57 +0,0 @@ -<% if (project.view) { -%> -import { StyleSheet, View } from 'react-native'; -import { <%- project.name -%>View } from '<%- project.slug -%>'; -<% } else { -%> -<% if (project.arch !== 'new') { -%> -import { useState, useEffect } from 'react'; -<% } -%> -import { StyleSheet, View, Text } from 'react-native'; -import { multiply } from '<%- project.slug -%>'; -<% } -%> - -<% 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() { - return ( - - Result: {result} - - ); -} -<% } else { -%> -export default function App() { - const [result, setResult] = useState(); - - useEffect(() => { - multiply(3, 7).then(setResult); - }, []); - - return ( - - Result: {result} - - ); -} -<% } -%> - -const styles = StyleSheet.create({ - container: { - flex: 1, - alignItems: 'center', - justifyContent: 'center', - }, - box: { - width: 60, - height: 60, - marginVertical: 20, - }, -}); diff --git a/packages/create-react-native-library/templates/common/CONTRIBUTING.md b/packages/create-react-native-library/templates/common/CONTRIBUTING.md index 6d2908914..ed89cd2d2 100644 --- a/packages/create-react-native-library/templates/common/CONTRIBUTING.md +++ b/packages/create-react-native-library/templates/common/CONTRIBUTING.md @@ -49,31 +49,6 @@ To run the example app on iOS: yarn example ios ``` -<% if (project.arch === 'mixed') { -%> -By default, the example is configured to build with the old architecture. To run the example with the new architecture, you can do the following: - -1. For Android, run: - - ```sh - ORG_GRADLE_PROJECT_newArchEnabled=true yarn example android - ``` - -2. For iOS, run: - - ```sh - cd example/ios - RCT_NEW_ARCH_ENABLED=1 pod install - cd - - yarn example ios - ``` - -If you are building for a different architecture than your previous build, make sure to remove the build folders first. You can run the following command to cleanup all build folders: - -```sh -yarn clean -``` - -<% } -%> <% if (project.arch !== 'legacy') { -%> To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this: diff --git a/packages/create-react-native-library/templates/common-example/example/metro.config.js b/packages/create-react-native-library/templates/example-common/example/metro.config.js similarity index 100% rename from packages/create-react-native-library/templates/common-example/example/metro.config.js rename to packages/create-react-native-library/templates/example-common/example/metro.config.js diff --git a/packages/create-react-native-library/templates/example-module-legacy/example/src/App.tsx b/packages/create-react-native-library/templates/example-module-legacy/example/src/App.tsx new file mode 100644 index 000000000..cbf4dc6c7 --- /dev/null +++ b/packages/create-react-native-library/templates/example-module-legacy/example/src/App.tsx @@ -0,0 +1,25 @@ +import { useState, useEffect } from 'react'; +import { Text, View, StyleSheet } from 'react-native'; +import { multiply } from '<%- project.slug -%>'; + +export default function App() { + const [result, setResult] = useState(); + + useEffect(() => { + multiply(3, 7).then(setResult); + }, []); + + return ( + + Result: {result} + + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + alignItems: 'center', + justifyContent: 'center', + }, +}); diff --git a/packages/create-react-native-library/templates/example-module-new/example/src/App.tsx b/packages/create-react-native-library/templates/example-module-new/example/src/App.tsx new file mode 100644 index 000000000..2f2745848 --- /dev/null +++ b/packages/create-react-native-library/templates/example-module-new/example/src/App.tsx @@ -0,0 +1,20 @@ +import { Text, View, StyleSheet } from 'react-native'; +import { multiply } from '<%- project.slug -%>'; + +const result = multiply(3, 7); + +export default function App() { + return ( + + Result: {result} + + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + alignItems: 'center', + justifyContent: 'center', + }, +}); diff --git a/packages/create-react-native-library/templates/example-view/example/src/App.tsx b/packages/create-react-native-library/templates/example-view/example/src/App.tsx new file mode 100644 index 000000000..4993e4270 --- /dev/null +++ b/packages/create-react-native-library/templates/example-view/example/src/App.tsx @@ -0,0 +1,23 @@ +import { View, StyleSheet } from 'react-native'; +import { <%- project.name -%>View } from '<%- project.slug -%>'; + +export default function App() { + return ( + + <<%- project.name -%>View color="#32a852" style={styles.box} /> + + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + alignItems: 'center', + justifyContent: 'center', + }, + box: { + width: 60, + height: 60, + marginVertical: 20, + }, +}); diff --git a/packages/create-react-native-library/templates/js-library/src/index.tsx b/packages/create-react-native-library/templates/js-library/src/index.tsx index 9e42cf312..14289fe2e 100644 --- a/packages/create-react-native-library/templates/js-library/src/index.tsx +++ b/packages/create-react-native-library/templates/js-library/src/index.tsx @@ -1,3 +1,3 @@ -export function multiply(a: number, b: number): Promise { - return Promise.resolve(a * b); +export function multiply(a: number, b: number): number { + return a * b; } diff --git a/packages/create-react-native-library/templates/kotlin-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt b/packages/create-react-native-library/templates/kotlin-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-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-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt deleted file mode 100644 index 93368013b..000000000 --- a/packages/create-react-native-library/templates/kotlin-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.TurboReactPackage -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 java.util.HashMap - -class <%- project.name -%>Package : TurboReactPackage() { - 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 - } - } -} diff --git a/packages/create-react-native-library/templates/kotlin-library-mixed/android/src/newarch/{%- project.name %}Spec.kt b/packages/create-react-native-library/templates/kotlin-library-mixed/android/src/newarch/{%- project.name %}Spec.kt deleted file mode 100644 index 3711dacb2..000000000 --- a/packages/create-react-native-library/templates/kotlin-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-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt b/packages/create-react-native-library/templates/kotlin-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt deleted file mode 100644 index ef0259618..000000000 --- a/packages/create-react-native-library/templates/kotlin-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-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 deleted file mode 100644 index 9f3ab9124..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.ReactPackage -import com.facebook.react.bridge.NativeModule -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.uimanager.ViewManager -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-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 deleted file mode 100644 index 6f7bfc565..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.<%- project.package %> - -import android.content.Context -import android.util.AttributeSet -import android.view.View - -class <%- project.name -%>View : View { - constructor(context: Context?) : super(context) - constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) - constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super( - context, - attrs, - defStyleAttr - ) -} diff --git a/packages/create-react-native-library/templates/kotlin-view-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 deleted file mode 100644 index eab57a0bf..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.<%- project.package %> - -import android.graphics.Color -import com.facebook.react.module.annotations.ReactModule -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.uimanager.ThemedReactContext -import com.facebook.react.uimanager.annotations.ReactProp - -@ReactModule(name = <%- project.name -%>ViewManager.NAME) -class <%- project.name -%>ViewManager : - <%- project.name -%>ViewManagerSpec<<%- project.name -%>View>() { - override fun getName(): String { - return NAME - } - - public override fun createViewInstance(context: ThemedReactContext): <%- project.name -%>View { - return <%- project.name -%>View(context) - } - - @ReactProp(name = "color") - override fun setColor(view: <%- project.name -%>View?, color: String?) { - view?.setBackgroundColor(Color.parseColor(color)) - } - - companion object { - const val NAME = "<%- project.name -%>View" - } -} diff --git a/packages/create-react-native-library/templates/kotlin-view-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 deleted file mode 100644 index 6bfe32f36..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.<%- project.package %> - -import android.view.View - -import com.facebook.react.bridge.ReactApplicationContext -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 - -abstract class <%- project.name -%>ViewManagerSpec : SimpleViewManager(), <%- project.name -%>ViewManagerInterface { - private val mDelegate: ViewManagerDelegate - - init { - mDelegate = <%- project.name -%>ViewManagerDelegate(this) - } - - override fun getDelegate(): ViewManagerDelegate? { - return mDelegate - } -} diff --git a/packages/create-react-native-library/templates/kotlin-view-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 deleted file mode 100644 index e3c897541..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.<%- project.package %> - -import android.view.View -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.uimanager.SimpleViewManager - -abstract class <%- project.name -%>ViewManagerSpec : SimpleViewManager() { - abstract fun setColor(view: T?, value: String?) -} 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 d9ad185bd..b7f96cdf4 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 @@ -66,7 +66,7 @@ android { defaultConfig { minSdkVersion getExtOrIntegerDefault("minSdkVersion") targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") -<% if (project.arch === "new" || project.arch === "mixed") { -%> +<% if (project.arch === "new") { -%> buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() <% } -%> @@ -87,7 +87,7 @@ android { } } <% } -%> -<% if (project.arch === "new" || project.arch === "mixed") { -%> +<% if (project.arch === "new") { -%> buildFeatures { buildConfig true @@ -120,22 +120,6 @@ android { } } } -<% } else if (project.arch === "mixed") { -%> - - sourceSets { - main { - if (isNewArchitectureEnabled()) { - java.srcDirs += [ - "src/newarch", - // Codegen specs - "generated/java", - "generated/jni" - ] - } else { - java.srcDirs += ["src/oldarch"] - } - } - } <% } -%> } @@ -154,7 +138,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } -<% if (project.arch === "new" || project.arch === "mixed") { -%> +<% if (project.arch === "new") { -%> if (isNewArchitectureEnabled()) { react { jsRootDir = file("../src/") diff --git a/packages/create-react-native-library/templates/native-library-mixed/react-native.config.js b/packages/create-react-native-library/templates/native-library-mixed/react-native.config.js deleted file mode 100644 index 01104a6b5..000000000 --- a/packages/create-react-native-library/templates/native-library-mixed/react-native.config.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @type {import('@react-native-community/cli-types').UserDependencyConfig} - */ -module.exports = { - dependency: { - platforms: { - android: { - <%_ if (example === 'vanilla') { -%> - cmakeListsPath: 'generated/jni/CMakeLists.txt', - <%_ } else { -%> - cmakeListsPath: 'build/generated/source/codegen/jni/CMakeLists.txt', - <%_ } -%> - }, - }, - }, -}; diff --git a/packages/create-react-native-library/templates/native-library-mixed/src/Native{%- project.name %}.ts b/packages/create-react-native-library/templates/native-library-mixed/src/Native{%- project.name %}.ts deleted file mode 100644 index 166b44ed7..000000000 --- a/packages/create-react-native-library/templates/native-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-library-mixed/src/index.tsx b/packages/create-react-native-library/templates/native-library-mixed/src/index.tsx deleted file mode 100644 index c583391a5..000000000 --- a/packages/create-react-native-library/templates/native-library-mixed/src/index.tsx +++ /dev/null @@ -1,29 +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); -} diff --git a/packages/create-react-native-library/templates/native-view-mixed/react-native.config.js b/packages/create-react-native-library/templates/native-view-mixed/react-native.config.js deleted file mode 100644 index 01104a6b5..000000000 --- a/packages/create-react-native-library/templates/native-view-mixed/react-native.config.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @type {import('@react-native-community/cli-types').UserDependencyConfig} - */ -module.exports = { - dependency: { - platforms: { - android: { - <%_ if (example === 'vanilla') { -%> - cmakeListsPath: 'generated/jni/CMakeLists.txt', - <%_ } else { -%> - cmakeListsPath: 'build/generated/source/codegen/jni/CMakeLists.txt', - <%_ } -%> - }, - }, - }, -}; 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 deleted file mode 100644 index 7a2bfbdc2..000000000 --- a/packages/create-react-native-library/templates/native-view-mixed/src/index.tsx +++ /dev/null @@ -1,2 +0,0 @@ -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-mixed/src/{%- project.name %}ViewNativeComponent.ts b/packages/create-react-native-library/templates/native-view-mixed/src/{%- project.name %}ViewNativeComponent.ts deleted file mode 100644 index db1ff171e..000000000 --- a/packages/create-react-native-library/templates/native-view-mixed/src/{%- project.name %}ViewNativeComponent.ts +++ /dev/null @@ -1,8 +0,0 @@ -import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; -import type { ViewProps } from 'react-native'; - -interface NativeProps extends ViewProps { - color?: string; -} - -export default codegenNativeComponent('<%- project.name -%>View'); diff --git a/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.h b/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.h index 32ed3c4b5..ec63832a9 100644 --- a/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.h +++ b/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.h @@ -5,7 +5,7 @@ <% } -%> #ifdef RCT_NEW_ARCH_ENABLED -#import "RN<%- project.name -%>Spec.h" +#import "generated/RN<%- project.name -%>Spec/RN<%- project.name -%>Spec.h" @interface <%- project.name -%> : NSObject Spec> #else diff --git a/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.mm b/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.mm index 7650a9fe4..5b8d840cc 100644 --- a/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.mm +++ b/packages/create-react-native-library/templates/objc-library/ios/{%- project.name %}.mm @@ -1,10 +1,10 @@ -#import "<%- project.name -%>.h" +#import "generated/RN<%- project.name -%>Spec/<%- project.name -%>.h" @implementation <%- project.name -%> RCT_EXPORT_MODULE() -<% if (project.arch === 'legacy' || project.arch === 'mixed') { -%> +<% if (project.arch === 'legacy') { -%> // Example method // See // https://reactnative.dev/docs/native-modules-ios RCT_EXPORT_METHOD(multiply:(double)a @@ -22,10 +22,9 @@ @implementation <%- project.name -%> } <% } -%> -<% if (project.arch === 'new' || project.arch === 'mixed') { -%> +<% if (project.arch === 'new') { -%> // 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)); @@ -36,7 +35,6 @@ - (NSNumber *)multiply:(double)a b:(double)b { return result; } -<% } -%> - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { diff --git a/packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.h b/packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.h deleted file mode 100644 index 1be34dba4..000000000 --- a/packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef Utils_h -#define Utils_h - -@interface Utils : NSObject -+ hexStringToColor:(NSString *)stringToConvert; -@end - -#endif /* Utils_h */ diff --git a/packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.m b/packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.m deleted file mode 100644 index bc9f8b9bd..000000000 --- a/packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.m +++ /dev/null @@ -1,26 +0,0 @@ -#import -#import "Utils.h" -#import - -@implementation Utils - -+ hexStringToColor:(NSString *)stringToConvert -{ - NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""]; - NSScanner *stringScanner = [NSScanner scannerWithString:noHashString]; - - unsigned hex; - if (![stringScanner scanHexInt:&hex]) return nil; - int r = (hex >> 16) & 0xFF; - int g = (hex >> 8) & 0xFF; - int b = (hex) & 0xFF; - - return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f]; -} - -+ (id)alloc { - [NSException raise:@"Cannot be instantiated!" format:@"Static class 'Utils' cannot be instantiated!"]; - return nil; -} - -@end diff --git a/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.h b/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.h deleted file mode 100644 index 0760d8a54..000000000 --- a/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.h +++ /dev/null @@ -1,17 +0,0 @@ -// This guard prevent this file to be compiled in the old architecture. -#ifdef RCT_NEW_ARCH_ENABLED -#import -#import - -#ifndef <%- project.name -%>ViewNativeComponent_h -#define <%- project.name -%>ViewNativeComponent_h - -NS_ASSUME_NONNULL_BEGIN - -@interface <%- project.name -%>View : RCTViewComponentView -@end - -NS_ASSUME_NONNULL_END - -#endif /* <%- project.name -%>ViewNativeComponent_h */ -#endif /* RCT_NEW_ARCH_ENABLED */ diff --git a/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.mm b/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.mm deleted file mode 100644 index 24aff36c2..000000000 --- a/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.mm +++ /dev/null @@ -1,60 +0,0 @@ -#ifdef RCT_NEW_ARCH_ENABLED -#import "<%- project.name -%>View.h" - -#import "ComponentDescriptors.h" -#import "EventEmitters.h" -#import "Props.h" -#import "RCTComponentViewHelpers.h" - -#import "RCTFabricComponentsPlugins.h" -#import "Utils.h" - -using namespace facebook::react; - -@interface <%- project.name -%>View () ViewViewProtocol> - -@end - -@implementation <%- project.name -%>View { - UIView * _view; -} - -+ (ComponentDescriptorProvider)componentDescriptorProvider -{ - return concreteComponentDescriptorProvider<<%- project.name -%>ViewComponentDescriptor>(); -} - -- (instancetype)initWithFrame:(CGRect)frame -{ - if (self = [super initWithFrame:frame]) { - static const auto defaultProps = std::make_sharedViewProps>(); - _props = defaultProps; - - _view = [[UIView alloc] init]; - - self.contentView = _view; - } - - return self; -} - -- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps -{ - const auto &oldViewProps = *std::static_pointer_cast<<%- project.name -%>ViewProps const>(_props); - const auto &newViewProps = *std::static_pointer_cast<<%- project.name -%>ViewProps const>(props); - - if (oldViewProps.color != newViewProps.color) { - NSString * colorToConvert = [[NSString alloc] initWithUTF8String: newViewProps.color.c_str()]; - [_view setBackgroundColor: [Utils hexStringToColor:colorToConvert]]; - } - - [super updateProps:props oldProps:oldProps]; -} - -Class <%- project.name -%>ViewCls(void) -{ - return <%- project.name -%>View.class; -} - -@end -#endif diff --git a/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}ViewManager.mm b/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}ViewManager.mm deleted file mode 100644 index 2f63c5e69..000000000 --- a/packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}ViewManager.mm +++ /dev/null @@ -1,23 +0,0 @@ -#import -#import -#import "RCTBridge.h" -#import "Utils.h" - -@interface <%- project.name -%>ViewManager : RCTViewManager -@end - -@implementation <%- project.name -%>ViewManager - -RCT_EXPORT_MODULE(<%- project.name -%>View) - -- (UIView *)view -{ - return [[UIView alloc] init]; -} - -RCT_CUSTOM_VIEW_PROPERTY(color, NSString, UIView) -{ - [view setBackgroundColor: [Utils hexStringToColor:json]]; -} - -@end diff --git a/packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}View.mm b/packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}View.mm index e2aca3f20..8387be445 100644 --- a/packages/create-react-native-library/templates/objc-view-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 "ComponentDescriptors.h" -#import "EventEmitters.h" -#import "Props.h" -#import "RCTComponentViewHelpers.h" +#import "generated/RN<%- project.name -%>ViewSpec/ComponentDescriptors.h" +#import "generated/RN<%- project.name -%>ViewSpec/EventEmitters.h" +#import "generated/RN<%- project.name -%>ViewSpec/Props.h" +#import "generated/RN<%- project.name -%>ViewSpec/RCTComponentViewHelpers.h" #import "RCTFabricComponentsPlugins.h" @@ -58,13 +58,13 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & { NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""]; NSScanner *stringScanner = [NSScanner scannerWithString:noHashString]; - + unsigned hex; if (![stringScanner scanHexInt:&hex]) return nil; int r = (hex >> 16) & 0xFF; int g = (hex >> 8) & 0xFF; int b = (hex) & 0xFF; - + return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f]; }