From 1d3fa60ef53240b15ed5193f1d038ac36a771ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 16:58:32 +0300 Subject: [PATCH] feat: remove all the java templates --- .../create-react-native-library/src/index.ts | 45 ++---------------- .../{%- 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 ---------- .../native-common/android/build.gradle | 10 ---- 20 files changed, 4 insertions(+), 578 deletions(-) delete mode 100644 packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java delete mode 100644 packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java delete mode 100644 packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java delete mode 100644 packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java delete mode 100644 packages/create-react-native-library/templates/java-library-mixed/android/src/newarch/{%- project.name %}Spec.java delete mode 100644 packages/create-react-native-library/templates/java-library-mixed/android/src/oldarch/{%- project.name %}Spec.java delete mode 100644 packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java delete mode 100644 packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java delete mode 100644 packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java delete mode 100644 packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java delete mode 100644 packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java delete mode 100644 packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java delete mode 100644 packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java delete mode 100644 packages/create-react-native-library/templates/java-view-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.java delete mode 100644 packages/create-react-native-library/templates/java-view-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.java delete mode 100644 packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java delete mode 100644 packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java delete mode 100644 packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index 3c02132db..92b08f7c6 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -50,15 +50,6 @@ const NATIVE_FILES = { ), } 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_common: path.resolve(__dirname, '../templates/objc-library'), view_legacy: path.resolve(__dirname, '../templates/objc-view-legacy'), @@ -101,13 +92,7 @@ type ArgName = | 'example' | 'react-native-version'; -type ProjectLanguages = - | 'java-objc' - | 'java-swift' - | 'kotlin-objc' - | 'kotlin-swift' - | 'cpp' - | 'js'; +type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js'; type ProjectType = | 'module-legacy' @@ -150,28 +135,11 @@ const LANGUAGE_CHOICES: { 'view-module-mixed', ], }, - { - 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', @@ -521,7 +489,7 @@ async function create(argv: yargs.Arguments) { authorUrl, repoUrl, type = 'module-mixed', - languages = type === 'library' ? 'js' : 'java-objc', + languages = type === 'library' ? 'js' : 'kotlin-objc', example: hasExample, reactNativeVersion, } = { @@ -635,8 +603,7 @@ async function create(argv: yargs.Arguments) { native: languages !== 'js', arch, cpp: languages === 'cpp', - kotlin: languages === 'kotlin-objc' || languages === 'kotlin-swift', - swift: languages === 'java-swift' || languages === 'kotlin-swift', + swift: languages === 'kotlin-swift', view: moduleType === 'view' || moduleType === 'view_module', module: moduleType === 'module' || moduleType === 'view_module', }, @@ -759,11 +726,7 @@ async function create(argv: yargs.Arguments) { const templateType = `${moduleType}_${arch}` as const; - if (options.project.kotlin) { - await copyDir(KOTLIN_FILES[templateType], folder); - } else { - await copyDir(JAVA_FILES[templateType], folder); - } + await copyDir(KOTLIN_FILES[templateType], folder); if (options.project.cpp) { await copyDir(CPP_FILES, folder); 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 deleted file mode 100644 index 798e50429..000000000 --- a/packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java +++ /dev/null @@ -1,43 +0,0 @@ -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 deleted file mode 100644 index 0a7e05207..000000000 --- a/packages/create-react-native-library/templates/java-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java +++ /dev/null @@ -1,28 +0,0 @@ -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 deleted file mode 100644 index afd27c5c5..000000000 --- a/packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java +++ /dev/null @@ -1,40 +0,0 @@ -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 deleted file mode 100644 index 89e8c71b2..000000000 --- a/packages/create-react-native-library/templates/java-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java +++ /dev/null @@ -1,45 +0,0 @@ -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 deleted file mode 100644 index 4edc2ec82..000000000 --- a/packages/create-react-native-library/templates/java-library-mixed/android/src/newarch/{%- project.name %}Spec.java +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 350d05a34..000000000 --- a/packages/create-react-native-library/templates/java-library-mixed/android/src/oldarch/{%- project.name %}Spec.java +++ /dev/null @@ -1,13 +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 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 deleted file mode 100644 index e9a2e6aaf..000000000 --- a/packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.java +++ /dev/null @@ -1,40 +0,0 @@ -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 deleted file mode 100644 index bcc5307ba..000000000 --- a/packages/create-react-native-library/templates/java-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java +++ /dev/null @@ -1,44 +0,0 @@ -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 deleted file mode 100644 index f8626aab1..000000000 --- a/packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.java +++ /dev/null @@ -1,22 +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.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 deleted file mode 100644 index 9fa0a42bc..000000000 --- a/packages/create-react-native-library/templates/java-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index d053791f8..000000000 --- a/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index 7442a7b44..000000000 --- a/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index c46da2710..000000000 --- a/packages/create-react-native-library/templates/java-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java +++ /dev/null @@ -1,25 +0,0 @@ -<% /* 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 deleted file mode 100644 index 763f28eaa..000000000 --- a/packages/create-react-native-library/templates/java-view-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.java +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index 0962fb3d1..000000000 --- a/packages/create-react-native-library/templates/java-view-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.java +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index d053791f8..000000000 --- a/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.java +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index 6360c1940..000000000 --- a/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.java +++ /dev/null @@ -1,47 +0,0 @@ -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 deleted file mode 100644 index c46da2710..000000000 --- a/packages/create-react-native-library/templates/java-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewPackage.java +++ /dev/null @@ -1,25 +0,0 @@ -<% /* 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/native-common/android/build.gradle b/packages/create-react-native-library/templates/native-common/android/build.gradle index e0e3a6428..fb68eaefe 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,9 +1,7 @@ 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() @@ -11,10 +9,8 @@ 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" -<% } -%> } } @@ -28,9 +24,7 @@ def isNewArchitectureEnabled() { } apply plugin: "com.android.library" -<% if (project.kotlin) { -%> apply plugin: "kotlin-android" -<% } -%> if (isNewArchitectureEnabled()) { apply plugin: "com.facebook.react" @@ -149,18 +143,14 @@ 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") { -%>