From 1970c98b447679fa6b256ebc2f9d6e12c55dfd3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Mon, 10 Jun 2024 20:07:18 +0300 Subject: [PATCH 01/31] feat: create kotlin part --- .../{%- project.name %}Module.kt | 24 +++++++++++ .../{%- project.name %}Package.kt | 40 +++++++++++++++++++ .../{%- project.name %}View.kt | 15 +++++++ .../{%- project.name %}ViewManager.kt | 28 +++++++++++++ .../src/newarch/{%- project.name %}Spec.kt | 7 ++++ .../{%- project.name %}ViewManagerSpec.kt | 21 ++++++++++ .../src/oldarch/{%- project.name %}Spec.kt | 11 +++++ .../{%- project.name %}ViewManagerSpec.kt | 9 +++++ 8 files changed, 155 insertions(+) create mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt create mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt create mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt create mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt create mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/newarch/{%- project.name %}Spec.kt create mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.kt create mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt create mode 100644 packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.kt 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 new file mode 100644 index 000000000..2cf84d752 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt @@ -0,0 +1,24 @@ +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 new file mode 100644 index 000000000..fae83afe0 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt @@ -0,0 +1,40 @@ +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/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt new file mode 100644 index 000000000..6f7bfc565 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt @@ -0,0 +1,15 @@ +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-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt new file mode 100644 index 000000000..eab57a0bf --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt @@ -0,0 +1,28 @@ +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-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 new file mode 100644 index 000000000..3711dacb2 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/newarch/{%- project.name %}Spec.kt @@ -0,0 +1,7 @@ +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/newarch/{%- project.name %}ViewManagerSpec.kt b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.kt new file mode 100644 index 000000000..6bfe32f36 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.kt @@ -0,0 +1,21 @@ +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-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 new file mode 100644 index 000000000..ef0259618 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt @@ -0,0 +1,11 @@ +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-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.kt b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.kt new file mode 100644 index 000000000..e3c897541 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-library-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.kt @@ -0,0 +1,9 @@ +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?) +} From 9d0a89e3227e82fa7e737e66d31200054d443efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Mon, 10 Jun 2024 20:10:42 +0300 Subject: [PATCH 02/31] feat: create ts part --- .../src/Native{%- project.name %}.ts | 8 +++++ .../native-view-library-mixed/src/index.tsx | 32 +++++++++++++++++++ .../src/{%- project.name %}NativeComponent.ts | 8 +++++ 3 files changed, 48 insertions(+) create mode 100644 packages/create-react-native-library/templates/native-view-library-mixed/src/Native{%- project.name %}.ts create mode 100644 packages/create-react-native-library/templates/native-view-library-mixed/src/index.tsx create mode 100644 packages/create-react-native-library/templates/native-view-library-mixed/src/{%- project.name %}NativeComponent.ts 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 new file mode 100644 index 000000000..166b44ed7 --- /dev/null +++ b/packages/create-react-native-library/templates/native-view-library-mixed/src/Native{%- project.name %}.ts @@ -0,0 +1,8 @@ +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 new file mode 100644 index 000000000..d4979707a --- /dev/null +++ b/packages/create-react-native-library/templates/native-view-library-mixed/src/index.tsx @@ -0,0 +1,32 @@ +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-mixed/src/{%- project.name %}NativeComponent.ts b/packages/create-react-native-library/templates/native-view-library-mixed/src/{%- project.name %}NativeComponent.ts new file mode 100644 index 000000000..db1ff171e --- /dev/null +++ b/packages/create-react-native-library/templates/native-view-library-mixed/src/{%- project.name %}NativeComponent.ts @@ -0,0 +1,8 @@ +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'); From 1ba688a7581c91b20bd6b375cf666855d0a6729d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Mon, 10 Jun 2024 20:22:27 +0300 Subject: [PATCH 03/31] feat: create objc part --- .../objc-view-library-mixed/ios/Utils.h | 8 +++ .../objc-view-library-mixed/ios/Utils.m | 26 ++++++++ .../ios/{%- project.name %}.h | 17 ++++++ .../ios/{%- project.name %}.mm | 48 +++++++++++++++ .../ios/{%- project.name %}View.h | 17 ++++++ .../ios/{%- project.name %}View.mm | 60 +++++++++++++++++++ .../ios/{%- project.name %}ViewManager.mm | 23 +++++++ 7 files changed, 199 insertions(+) create mode 100644 packages/create-react-native-library/templates/objc-view-library-mixed/ios/Utils.h create mode 100644 packages/create-react-native-library/templates/objc-view-library-mixed/ios/Utils.m create mode 100644 packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.h create mode 100644 packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.mm create mode 100644 packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}View.h create mode 100644 packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}View.mm create mode 100644 packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}ViewManager.mm 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-library-mixed/ios/Utils.h new file mode 100644 index 000000000..1be34dba4 --- /dev/null +++ b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/Utils.h @@ -0,0 +1,8 @@ +#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-library-mixed/ios/Utils.m b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/Utils.m new file mode 100644 index 000000000..bc9f8b9bd --- /dev/null +++ b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/Utils.m @@ -0,0 +1,26 @@ +#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-library-mixed/ios/{%- project.name %}.h b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.h new file mode 100644 index 000000000..32ed3c4b5 --- /dev/null +++ b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.h @@ -0,0 +1,17 @@ +<% 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 new file mode 100644 index 000000000..7650a9fe4 --- /dev/null +++ b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}.mm @@ -0,0 +1,48 @@ +#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/{%- project.name %}View.h b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}View.h new file mode 100644 index 000000000..0760d8a54 --- /dev/null +++ b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}View.h @@ -0,0 +1,17 @@ +// 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-library-mixed/ios/{%- project.name %}View.mm b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}View.mm new file mode 100644 index 000000000..ff8ae754c --- /dev/null +++ b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}View.mm @@ -0,0 +1,60 @@ +#ifdef RCT_NEW_ARCH_ENABLED +#import "<%- project.name -%>View.h" + +#import ViewSpec/ComponentDescriptors.h> +#import ViewSpec/EventEmitters.h> +#import ViewSpec/Props.h> +#import ViewSpec/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-library-mixed/ios/{%- project.name %}ViewManager.mm b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}ViewManager.mm new file mode 100644 index 000000000..2f63c5e69 --- /dev/null +++ b/packages/create-react-native-library/templates/objc-view-library-mixed/ios/{%- project.name %}ViewManager.mm @@ -0,0 +1,23 @@ +#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 From 44ce26be80d7bb48099d54bd7b5e689208e86447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Mon, 10 Jun 2024 22:22:22 +0300 Subject: [PATCH 04/31] feat: handle view+module template on CLI --- .../create-react-native-library/src/index.ts | 78 +++++++++++++------ 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index 18350a22e..98eb104fe 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -44,6 +44,10 @@ const NATIVE_FILES = { 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'), + view_module_mixed: path.resolve( + __dirname, + '../templates/native-view-library-mixed' + ), } as const; const JAVA_FILES = { @@ -60,6 +64,10 @@ const OBJC_FILES = { 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'), + view_module_mixed: path.resolve( + __dirname, + '../templates/objc-view-library-mixed' + ), } as const; const KOTLIN_FILES = { @@ -69,6 +77,10 @@ const KOTLIN_FILES = { 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'), + view_module_mixed: path.resolve( + __dirname, + '../templates/kotlin-view-library-mixed' + ), } as const; const SWIFT_FILES = { @@ -104,7 +116,8 @@ type ProjectType = | 'view-mixed' | 'view-new' | 'view-legacy' - | 'library'; + | 'library' + | 'view-module-mixed'; type Answers = { slug: string; @@ -134,6 +147,7 @@ const LANGUAGE_CHOICES: { 'view-mixed', 'view-new', 'view-legacy', + 'view-module-mixed', ], }, { @@ -178,6 +192,11 @@ const TYPE_CHOICES: { value: ProjectType; description: string; }[] = [ + { + title: 'Fabric view and Turbo module with backward compat', + value: 'view-module-mixed', + description: NEWARCH_DESCRIPTION, + }, { title: 'JavaScript library', value: 'library', @@ -210,7 +229,7 @@ const TYPE_CHOICES: { }, { title: 'Fabric view', - value: 'view-new', + value: 'view-module-mixed', description: NEWARCH_DESCRIPTION, }, ]; @@ -561,11 +580,17 @@ async function create(argv: yargs.Arguments) { version = FALLBACK_BOB_VERSION; } - const moduleType = type.startsWith('view-') ? 'view' : 'module'; + const moduleType = type.startsWith('view-module') + ? 'view_module' + : type.startsWith('view') + ? 'view' + : 'module'; const arch = type === 'module-new' || type === 'view-new' ? 'new' - : type === 'module-mixed' || type === 'view-mixed' + : type === 'module-mixed' || + type === 'view-mixed' || + type === 'view-module-mixed' ? 'mixed' : 'legacy'; @@ -612,8 +637,8 @@ async function create(argv: yargs.Arguments) { cpp: languages === 'cpp', kotlin: languages === 'kotlin-objc' || languages === 'kotlin-swift', swift: languages === 'java-swift' || languages === 'kotlin-swift', - view: moduleType === 'view', - module: moduleType === 'module', + view: moduleType === 'view' || moduleType === 'view_module', + module: moduleType === 'module' || moduleType === 'view_module', }, author: { name: authorName, @@ -714,33 +739,36 @@ async function create(argv: yargs.Arguments) { await copyDir(NATIVE_COMMON_EXAMPLE_FILES, folder); } - if (moduleType === 'module') { - await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder); + if (moduleType === 'view_module') { + // View module doesn't have legacy or a new arch only version. + await copyDir(NATIVE_FILES['view_module_mixed'], folder); + await copyDir(OBJC_FILES['view_module_mixed'], folder); + await copyDir(KOTLIN_FILES['view_module_mixed'], folder); } else { await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder); - } - if (options.project.swift) { - await copyDir(SWIFT_FILES[`${moduleType}_legacy`], folder); - } else { - if (moduleType === 'module') { - await copyDir(OBJC_FILES[`${moduleType}_common`], folder); + if (options.project.swift) { + await copyDir(SWIFT_FILES[`${moduleType}_legacy`], folder); } else { - await copyDir(OBJC_FILES[`view_${arch}`], folder); + if (moduleType === 'module') { + await copyDir(OBJC_FILES[`${moduleType}_common`], folder); + } else { + await copyDir(OBJC_FILES[`view_${arch}`], folder); + } } - } - const templateType = `${moduleType}_${arch}` as const; + 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.kotlin) { + await copyDir(KOTLIN_FILES[templateType], folder); + } else { + await copyDir(JAVA_FILES[templateType], folder); + } - if (options.project.cpp) { - await copyDir(CPP_FILES, folder); - await fs.remove(path.join(folder, 'ios', `${options.project.name}.m`)); + if (options.project.cpp) { + await copyDir(CPP_FILES, folder); + await fs.remove(path.join(folder, 'ios', `${options.project.name}.m`)); + } } } From 8efcf933bdcb832407c5dcc0b1e0e42cde466989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Mon, 10 Jun 2024 22:44:53 +0300 Subject: [PATCH 05/31] feat: handle example app --- .../common-example/example/src/App.tsx | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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 38db6fe50..838d5750a 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,6 +1,9 @@ import * as React from 'react'; -<% if (project.view) { -%> +<% if (project.view && project.module) { -%> +import { StyleSheet, View, Text } from 'react-native'; +import { <%- project.name -%>View, multiply } from '<%- project.slug -%>'; +<% } else if (project.view) { -%> import { StyleSheet, View } from 'react-native'; import { <%- project.name -%>View } from '<%- project.slug -%>'; <% } else { -%> @@ -8,7 +11,22 @@ import { StyleSheet, View, Text } from 'react-native'; import { multiply } from '<%- project.slug -%>'; <% } -%> -<% if (project.view) { -%> +<% if (project.view && project.module) { -%> +export default function App() { + const [result, setResult] = React.useState(); + + React.useEffect(() => { + multiply(3, 7).then(setResult); + }, []); + + return ( + + Result: {result} + <<%- project.name -%>View color="#32a852" style={styles.box} /> + + ); +} +<% } else if (project.view) { -%> export default function App() { return ( From 2a9cc9e8a5ac8fa31877dda08dd81ecc4775afcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 12:53:18 +0300 Subject: [PATCH 06/31] feat: pass codegen type all for view+module libraries --- .../create-react-native-library/templates/common/$package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-react-native-library/templates/common/$package.json b/packages/create-react-native-library/templates/common/$package.json index 5cf2ca060..90c434167 100644 --- a/packages/create-react-native-library/templates/common/$package.json +++ b/packages/create-react-native-library/templates/common/$package.json @@ -170,7 +170,7 @@ }, "codegenConfig": { "name": "RN<%- project.name -%><%- project.view ? 'View': '' -%>Spec", - "type": <%- project.view ? '"components"': '"modules"' %>, + "type": <%- project.view && project.module ? '"all"' : project.view ? '"components"': '"modules"' %>, "jsSrcsDir": "src" <% } -%> } From 5e20c864b34af1839d4b19bc9c72dbf03b1823d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 12:54:20 +0300 Subject: [PATCH 07/31] feat: remove the `View` prefix from view codegens --- .../templates/common/$package.json | 2 +- .../ios/{%- project.name %}View.mm | 8 ++++---- .../objc-view-mixed/ios/{%- project.name %}View.mm | 8 ++++---- .../objc-view-new/ios/{%- project.name %}View.mm | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/create-react-native-library/templates/common/$package.json b/packages/create-react-native-library/templates/common/$package.json index 90c434167..e86a80224 100644 --- a/packages/create-react-native-library/templates/common/$package.json +++ b/packages/create-react-native-library/templates/common/$package.json @@ -169,7 +169,7 @@ <% if (project.arch !== 'legacy') { -%> }, "codegenConfig": { - "name": "RN<%- project.name -%><%- project.view ? 'View': '' -%>Spec", + "name": "RN<%- project.name -%>Spec", "type": <%- project.view && project.module ? '"all"' : project.view ? '"components"': '"modules"' %>, "jsSrcsDir": "src" <% } -%> 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-library-mixed/ios/{%- project.name %}View.mm index ff8ae754c..fb815ff30 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-library-mixed/ios/{%- project.name %}View.mm @@ -1,10 +1,10 @@ #ifdef RCT_NEW_ARCH_ENABLED #import "<%- project.name -%>View.h" -#import ViewSpec/ComponentDescriptors.h> -#import ViewSpec/EventEmitters.h> -#import ViewSpec/Props.h> -#import ViewSpec/RCTComponentViewHelpers.h> +#import Spec/ComponentDescriptors.h> +#import Spec/EventEmitters.h> +#import Spec/Props.h> +#import Spec/RCTComponentViewHelpers.h> #import "RCTFabricComponentsPlugins.h" #import "Utils.h" 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 index ff8ae754c..fb815ff30 100644 --- 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 @@ -1,10 +1,10 @@ #ifdef RCT_NEW_ARCH_ENABLED #import "<%- project.name -%>View.h" -#import ViewSpec/ComponentDescriptors.h> -#import ViewSpec/EventEmitters.h> -#import ViewSpec/Props.h> -#import ViewSpec/RCTComponentViewHelpers.h> +#import Spec/ComponentDescriptors.h> +#import Spec/EventEmitters.h> +#import Spec/Props.h> +#import Spec/RCTComponentViewHelpers.h> #import "RCTFabricComponentsPlugins.h" #import "Utils.h" 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 46e92936f..0b73c7b1d 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 ViewSpec/ComponentDescriptors.h> -#import ViewSpec/EventEmitters.h> -#import ViewSpec/Props.h> -#import ViewSpec/RCTComponentViewHelpers.h> +#import Spec/ComponentDescriptors.h> +#import Spec/EventEmitters.h> +#import Spec/Props.h> +#import Spec/RCTComponentViewHelpers.h> #import "RCTFabricComponentsPlugins.h" From ba16dd64b74792bee7b590913f7536b6738bdc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 16:47:59 +0300 Subject: [PATCH 08/31] fix: view-new type is ignored --- packages/create-react-native-library/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index 98eb104fe..3c02132db 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -229,7 +229,7 @@ const TYPE_CHOICES: { }, { title: 'Fabric view', - value: 'view-module-mixed', + value: 'view-new', description: NEWARCH_DESCRIPTION, }, ]; 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 09/31] 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") { -%> From 6b638e37bccbcd2655a331f03fff33f4f1e02243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 17:06:41 +0300 Subject: [PATCH 10/31] fix: remove java from CI --- .github/workflows/build-templates.yml | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index c7d2be9b0..658c11e70 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -31,32 +31,21 @@ jobs: - view-legacy - view-mixed - view-new + - view-module-mixed language: - - java-objc - - java-swift - kotlin-objc - kotlin-swift exclude: - - os: macos-14 - language: kotlin-objc - - os: macos-14 - language: kotlin-swift - - type: module-new - language: java-swift - type: module-new language: kotlin-swift - - type: module-mixed - language: java-swift - type: module-mixed language: kotlin-swift - - type: view-new - language: java-swift - type: view-new language: kotlin-swift - - type: view-mixed - language: java-swift - type: view-mixed language: kotlin-swift + - type: view-module-mixed + language: kotlin-swift include: - os: ubuntu-latest type: library @@ -146,9 +135,7 @@ jobs: # Build iOS for only some matrices to skip redundant builds 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 + echo "ios_build=1" >> $GITHUB_ENV fi - name: Cache turborepo From d46f0e1c8614a1c0b60cdd23dd1064f0580bfb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 17:17:24 +0300 Subject: [PATCH 11/31] feat: remove module and view mixed templates --- .github/workflows/build-templates.yml | 3 - .../create-react-native-library/src/index.ts | 28 ++------- .../templates/common/CONTRIBUTING.md | 2 +- .../{%- project.name %}Module.kt | 24 -------- .../{%- project.name %}Package.kt | 35 ----------- .../src/newarch/{%- project.name %}Spec.kt | 7 --- .../src/oldarch/{%- project.name %}Spec.kt | 11 ---- .../{%- project.name %}Package.kt | 19 ------ .../{%- project.name %}View.kt | 15 ----- .../{%- project.name %}ViewManager.kt | 28 --------- .../{%- project.name %}ViewManagerSpec.kt | 21 ------- .../{%- project.name %}ViewManagerSpec.kt | 9 --- .../src/Native{%- project.name %}.ts | 8 --- .../native-library-mixed/src/index.tsx | 29 --------- .../templates/native-view-mixed/src/index.tsx | 2 - .../{%- project.name %}ViewNativeComponent.ts | 8 --- .../templates/objc-view-mixed/ios/Utils.h | 8 --- .../templates/objc-view-mixed/ios/Utils.m | 26 -------- .../ios/{%- project.name %}View.h | 17 ------ .../ios/{%- project.name %}View.mm | 60 ------------------- .../ios/{%- project.name %}ViewManager.mm | 23 ------- 21 files changed, 5 insertions(+), 378 deletions(-) delete mode 100644 packages/create-react-native-library/templates/kotlin-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-library-mixed/android/src/newarch/{%- project.name %}Spec.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-mixed/android/src/newarch/{%- project.name %}ViewManagerSpec.kt delete mode 100644 packages/create-react-native-library/templates/kotlin-view-mixed/android/src/oldarch/{%- project.name %}ViewManagerSpec.kt delete mode 100644 packages/create-react-native-library/templates/native-library-mixed/src/Native{%- project.name %}.ts delete mode 100644 packages/create-react-native-library/templates/native-library-mixed/src/index.tsx delete mode 100644 packages/create-react-native-library/templates/native-view-mixed/src/index.tsx delete mode 100644 packages/create-react-native-library/templates/native-view-mixed/src/{%- project.name %}ViewNativeComponent.ts delete mode 100644 packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.h delete mode 100644 packages/create-react-native-library/templates/objc-view-mixed/ios/Utils.m delete mode 100644 packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.h delete mode 100644 packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}View.mm delete mode 100644 packages/create-react-native-library/templates/objc-view-mixed/ios/{%- project.name %}ViewManager.mm diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index 658c11e70..051780ccb 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -29,7 +29,6 @@ jobs: - module-mixed - module-new - view-legacy - - view-mixed - view-new - view-module-mixed language: @@ -39,11 +38,9 @@ jobs: - type: module-new language: kotlin-swift - type: module-mixed - language: kotlin-swift - type: view-new language: kotlin-swift - type: view-mixed - language: kotlin-swift - type: view-module-mixed language: kotlin-swift include: diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index 92b08f7c6..ecae4f4c2 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -40,9 +40,7 @@ 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'), view_module_mixed: path.resolve( __dirname, @@ -53,7 +51,6 @@ const NATIVE_FILES = { 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'), view_module_mixed: path.resolve( __dirname, @@ -64,9 +61,7 @@ const OBJC_FILES = { 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'), view_module_mixed: path.resolve( __dirname, @@ -98,7 +93,6 @@ type ProjectType = | 'module-legacy' | 'module-new' | 'module-mixed' - | 'view-mixed' | 'view-new' | 'view-legacy' | 'library' @@ -128,8 +122,6 @@ const LANGUAGE_CHOICES: { types: [ 'module-legacy', 'module-new', - 'module-mixed', - 'view-mixed', 'view-new', 'view-legacy', 'view-module-mixed', @@ -163,7 +155,7 @@ const TYPE_CHOICES: { { title: 'Fabric view and Turbo module with backward compat', value: 'view-module-mixed', - description: NEWARCH_DESCRIPTION, + description: BACKCOMPAT_DESCRIPTION, }, { title: 'JavaScript library', @@ -180,21 +172,11 @@ const TYPE_CHOICES: { 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, - }, { title: 'Fabric view', value: 'view-new', @@ -488,7 +470,7 @@ async function create(argv: yargs.Arguments) { authorEmail, authorUrl, repoUrl, - type = 'module-mixed', + type = 'view-module-mixed', languages = type === 'library' ? 'js' : 'kotlin-objc', example: hasExample, reactNativeVersion, @@ -556,9 +538,7 @@ async function create(argv: yargs.Arguments) { const arch = type === 'module-new' || type === 'view-new' ? 'new' - : type === 'module-mixed' || - type === 'view-mixed' || - type === 'view-module-mixed' + : type === 'module-mixed' || type === 'view-module-mixed' ? 'mixed' : 'legacy'; @@ -706,7 +686,7 @@ async function create(argv: yargs.Arguments) { await copyDir(NATIVE_COMMON_EXAMPLE_FILES, folder); } - if (moduleType === 'view_module') { + if (arch === 'mixed') { // View module doesn't have legacy or a new arch only version. await copyDir(NATIVE_FILES['view_module_mixed'], folder); await copyDir(OBJC_FILES['view_module_mixed'], folder); diff --git a/packages/create-react-native-library/templates/common/CONTRIBUTING.md b/packages/create-react-native-library/templates/common/CONTRIBUTING.md index 6d2908914..303a6b326 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 Java or Kotlin files, open `example/android` in Android studio and find the source files at `<%- project.identifier -%>` under `Android`. +To edit the the 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/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-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/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-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 fb815ff30..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 Spec/ComponentDescriptors.h> -#import Spec/EventEmitters.h> -#import Spec/Props.h> -#import Spec/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 From 94c996495c7e7d746dfd269afc8f4c41ee08ade6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 18:00:23 +0300 Subject: [PATCH 12/31] fix: remove view and module new templates --- .github/workflows/build-templates.yml | 6 +-- .../create-react-native-library/src/index.ts | 26 ++++------ .../{%- project.name %}Module.kt | 0 .../{%- project.name %}Package.kt | 16 +++++-- .../{%- project.name %}View.kt | 0 .../{%- project.name %}ViewManager.kt | 0 .../{%- project.name %}Package.kt | 19 -------- .../src/Native{%- project.name %}.ts | 0 .../src/index.tsx | 3 ++ .../{%- project.name %}NativeComponent.ts} | 0 .../templates/native-view-new/src/index.tsx | 2 - .../ios/{%- project.name %}.h | 17 +++++++ .../ios/{%- project.name %}.mm | 48 +++++++++++++++++++ .../ios/{%- project.name %}View.h | 0 .../ios/{%- project.name %}View.mm | 0 .../ios/{%- project.name %}ViewManager.mm | 0 16 files changed, 90 insertions(+), 47 deletions(-) rename packages/create-react-native-library/templates/{kotlin-library-new => kotlin-view-library-new}/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt (100%) rename packages/create-react-native-library/templates/{kotlin-library-new => kotlin-view-library-new}/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt (70%) rename packages/create-react-native-library/templates/{kotlin-view-new => kotlin-view-library-new}/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt (100%) rename packages/create-react-native-library/templates/{kotlin-view-new => kotlin-view-library-new}/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt (100%) delete 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/{native-library-new => native-view-library-new}/src/Native{%- project.name %}.ts (100%) rename packages/create-react-native-library/templates/{native-library-new => native-view-library-new}/src/index.tsx (55%) rename packages/create-react-native-library/templates/{native-view-new/src/{%- project.name %}ViewNativeComponent.ts => native-view-library-new/src/{%- project.name %}NativeComponent.ts} (100%) delete mode 100644 packages/create-react-native-library/templates/native-view-new/src/index.tsx create mode 100644 packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.h create 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-new => objc-view-library-new}/ios/{%- project.name %}View.h (100%) rename packages/create-react-native-library/templates/{objc-view-new => objc-view-library-new}/ios/{%- project.name %}View.mm (100%) rename packages/create-react-native-library/templates/{objc-view-new => objc-view-library-new}/ios/{%- project.name %}ViewManager.mm (100%) diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index 051780ccb..028c76d55 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -29,18 +29,14 @@ jobs: - module-mixed - module-new - view-legacy - - view-new - view-module-mixed + - view-module-new language: - kotlin-objc - kotlin-swift exclude: - type: module-new - language: kotlin-swift - type: module-mixed - - type: view-new - language: kotlin-swift - - type: view-mixed - type: view-module-mixed language: kotlin-swift include: diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index ecae4f4c2..b96718275 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -39,9 +39,7 @@ const NATIVE_COMMON_EXAMPLE_FILES = path.resolve( const NATIVE_FILES = { module_legacy: path.resolve(__dirname, '../templates/native-library-legacy'), - module_new: path.resolve(__dirname, '../templates/native-library-new'), view_legacy: path.resolve(__dirname, '../templates/native-view-legacy'), - view_new: path.resolve(__dirname, '../templates/native-view-new'), view_module_mixed: path.resolve( __dirname, '../templates/native-view-library-mixed' @@ -51,7 +49,6 @@ const NATIVE_FILES = { const OBJC_FILES = { module_common: path.resolve(__dirname, '../templates/objc-library'), view_legacy: path.resolve(__dirname, '../templates/objc-view-legacy'), - view_new: path.resolve(__dirname, '../templates/objc-view-new'), view_module_mixed: path.resolve( __dirname, '../templates/objc-view-library-mixed' @@ -60,9 +57,7 @@ const OBJC_FILES = { const KOTLIN_FILES = { module_legacy: path.resolve(__dirname, '../templates/kotlin-library-legacy'), - module_new: path.resolve(__dirname, '../templates/kotlin-library-new'), view_legacy: path.resolve(__dirname, '../templates/kotlin-view-legacy'), - view_new: path.resolve(__dirname, '../templates/kotlin-view-new'), view_module_mixed: path.resolve( __dirname, '../templates/kotlin-view-library-mixed' @@ -93,10 +88,10 @@ type ProjectType = | 'module-legacy' | 'module-new' | 'module-mixed' - | 'view-new' | 'view-legacy' | 'library' - | 'view-module-mixed'; + | 'view-module-mixed' + | 'view-module-new'; type Answers = { slug: string; @@ -121,10 +116,9 @@ const LANGUAGE_CHOICES: { value: 'kotlin-objc', types: [ 'module-legacy', - 'module-new', - 'view-new', 'view-legacy', 'view-module-mixed', + 'view-module-new' ], }, { @@ -157,6 +151,11 @@ const TYPE_CHOICES: { value: 'view-module-mixed', description: BACKCOMPAT_DESCRIPTION, }, + { + title: 'Fabric view and Turbo module', + value: 'view-module-mixed', + description: NEWARCH_DESCRIPTION, + }, { title: 'JavaScript library', value: 'library', @@ -176,12 +175,7 @@ const TYPE_CHOICES: { title: 'Turbo module', value: 'module-new', description: NEWARCH_DESCRIPTION, - }, - { - title: 'Fabric view', - value: 'view-new', - description: NEWARCH_DESCRIPTION, - }, + } ]; const args: Record = { @@ -536,7 +530,7 @@ async function create(argv: yargs.Arguments) { ? 'view' : 'module'; const arch = - type === 'module-new' || type === 'view-new' + type === 'module-new' || type === 'view-module-new' ? 'new' : type === 'module-mixed' || type === 'view-module-mixed' ? 'mixed' diff --git a/packages/create-react-native-library/templates/kotlin-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 similarity index 100% rename from packages/create-react-native-library/templates/kotlin-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt rename to packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt diff --git a/packages/create-react-native-library/templates/kotlin-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 similarity index 70% rename from packages/create-react-native-library/templates/kotlin-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt rename to packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt index 599cf307c..fae83afe0 100644 --- a/packages/create-react-native-library/templates/kotlin-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 @@ -1,13 +1,14 @@ package com.<%- project.package %> -import com.facebook.react.TurboReactPackage -import com.facebook.react.bridge.NativeModule +import com.facebook.react.BaseReactPackage import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.module.model.ReactModuleInfo +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 : TurboReactPackage() { +class <%- project.name -%>Package : BaseReactPackage() { override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { return if (name == <%- project.name -%>Module.NAME) { <%- project.name -%>Module(reactContext) @@ -19,6 +20,7 @@ class <%- project.name -%>Package : TurboReactPackage() { 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, @@ -26,9 +28,13 @@ class <%- project.name -%>Package : TurboReactPackage() { false, // needsEagerInit true, // hasConstants false, // isCxxModule - true // isTurboModule + 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-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt b/packages/create-react-native-library/templates/kotlin-view-library-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-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt rename to packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}View.kt diff --git a/packages/create-react-native-library/templates/kotlin-view-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt b/packages/create-react-native-library/templates/kotlin-view-library-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-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt rename to packages/create-react-native-library/templates/kotlin-view-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.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 deleted file mode 100644 index 9f3ab9124..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-new/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/native-library-new/src/Native{%- project.name %}.ts b/packages/create-react-native-library/templates/native-view-library-new/src/Native{%- project.name %}.ts similarity index 100% rename from packages/create-react-native-library/templates/native-library-new/src/Native{%- project.name %}.ts rename to packages/create-react-native-library/templates/native-view-library-new/src/Native{%- project.name %}.ts diff --git a/packages/create-react-native-library/templates/native-library-new/src/index.tsx b/packages/create-react-native-library/templates/native-view-library-new/src/index.tsx similarity index 55% rename from packages/create-react-native-library/templates/native-library-new/src/index.tsx rename to packages/create-react-native-library/templates/native-view-library-new/src/index.tsx index adc8b3076..d98e51a06 100644 --- a/packages/create-react-native-library/templates/native-library-new/src/index.tsx +++ b/packages/create-react-native-library/templates/native-view-library-new/src/index.tsx @@ -3,3 +3,6 @@ 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-new/src/{%- project.name %}ViewNativeComponent.ts b/packages/create-react-native-library/templates/native-view-library-new/src/{%- project.name %}NativeComponent.ts similarity index 100% rename from packages/create-react-native-library/templates/native-view-new/src/{%- project.name %}ViewNativeComponent.ts rename to packages/create-react-native-library/templates/native-view-library-new/src/{%- project.name %}NativeComponent.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 deleted file mode 100644 index 7a2bfbdc2..000000000 --- a/packages/create-react-native-library/templates/native-view-new/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/objc-view-library-new/ios/{%- project.name %}.h b/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.h new file mode 100644 index 000000000..32ed3c4b5 --- /dev/null +++ b/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.h @@ -0,0 +1,17 @@ +<% 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 new file mode 100644 index 000000000..7650a9fe4 --- /dev/null +++ b/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}.mm @@ -0,0 +1,48 @@ +#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-new/ios/{%- project.name %}View.h b/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}View.h similarity index 100% rename from packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}View.h rename to packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}View.h 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-library-new/ios/{%- project.name %}View.mm similarity index 100% rename from packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}View.mm rename to packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}View.mm diff --git a/packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}ViewManager.mm b/packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}ViewManager.mm similarity index 100% rename from packages/create-react-native-library/templates/objc-view-new/ios/{%- project.name %}ViewManager.mm rename to packages/create-react-native-library/templates/objc-view-library-new/ios/{%- project.name %}ViewManager.mm From d16092e7b2d65ba0f1f85ba4bf3208a5194df948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 18:43:02 +0300 Subject: [PATCH 13/31] fix: remove view and module legacy templates --- .github/workflows/build-templates.yml | 16 +++--- .../create-react-native-library/src/index.ts | 51 ++++++++++++------- .../{%- project.name %}Package.kt | 17 ------- .../{%- project.name %}Package.kt | 17 ------- .../{%- project.name %}Module.kt | 0 .../{%- project.name %}Package.kt | 39 ++++++++++++++ .../{%- project.name %}ViewManager.kt | 0 .../native-view-library-legacy/src/index.tsx | 7 +++ .../src/{%- project.name %}.ts} | 6 +-- .../src/{%- project.name %}View.ts} | 0 .../ios/{%- project.name %}.h | 6 +++ .../ios/{%- project.name %}.mm | 18 +++++++ .../ios/{%- project.name %}ViewManager.m | 0 13 files changed, 110 insertions(+), 67 deletions(-) delete mode 100644 packages/create-react-native-library/templates/kotlin-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-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt rename packages/create-react-native-library/templates/{kotlin-library-legacy => kotlin-view-library-legacy}/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt (100%) create mode 100644 packages/create-react-native-library/templates/kotlin-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt rename packages/create-react-native-library/templates/{kotlin-view-legacy => kotlin-view-library-legacy}/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt (100%) create mode 100644 packages/create-react-native-library/templates/native-view-library-legacy/src/index.tsx rename packages/create-react-native-library/templates/{native-library-legacy/src/index.tsx => native-view-library-legacy/src/{%- project.name %}.ts} (73%) rename packages/create-react-native-library/templates/{native-view-legacy/src/index.tsx => native-view-library-legacy/src/{%- project.name %}View.ts} (100%) create mode 100644 packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.h create mode 100644 packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.mm rename packages/create-react-native-library/templates/{objc-view-legacy => objc-view-library-legacy}/ios/{%- project.name %}ViewManager.m (100%) diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index 028c76d55..e9716a7af 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -35,10 +35,15 @@ jobs: - kotlin-objc - kotlin-swift exclude: - - type: module-new + - type: module-legacy - type: module-mixed + - type: module-new + - type: view-module-legacy + language: kotlin-swift - type: view-module-mixed language: kotlin-swift + - type: view-module-new + language: kotlin-swift include: - os: ubuntu-latest type: library @@ -52,15 +57,6 @@ jobs: - 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 }} diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index b96718275..a3d3af5fc 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -38,30 +38,49 @@ const NATIVE_COMMON_EXAMPLE_FILES = path.resolve( ); const NATIVE_FILES = { - module_legacy: path.resolve(__dirname, '../templates/native-library-legacy'), - 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' + ), } as const; const OBJC_FILES = { module_common: path.resolve(__dirname, '../templates/objc-library'), - view_legacy: path.resolve(__dirname, '../templates/objc-view-legacy'), + 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' + ), } as const; const KOTLIN_FILES = { - module_legacy: path.resolve(__dirname, '../templates/kotlin-library-legacy'), - 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' + ), } as const; const SWIFT_FILES = { @@ -86,10 +105,11 @@ type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js'; type ProjectType = | 'module-legacy' - | 'module-new' | 'module-mixed' + | 'module-new' | 'view-legacy' | 'library' + | 'view-module-legacy' | 'view-module-mixed' | 'view-module-new'; @@ -114,12 +134,7 @@ const LANGUAGE_CHOICES: { { title: 'Kotlin & Objective-C', value: 'kotlin-objc', - types: [ - 'module-legacy', - 'view-legacy', - 'view-module-mixed', - 'view-module-new' - ], + types: ['view-module-legacy', 'view-module-mixed', 'view-module-new'], }, { title: 'Kotlin & Swift', @@ -156,6 +171,11 @@ const TYPE_CHOICES: { value: 'view-module-mixed', 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', @@ -166,16 +186,11 @@ const TYPE_CHOICES: { 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', value: 'module-new', description: NEWARCH_DESCRIPTION, - } + }, ]; const args: Record = { diff --git a/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt deleted file mode 100644 index d34649aee..000000000 --- a/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.ReactPackage -import com.facebook.react.bridge.NativeModule -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.uimanager.ViewManager - - -class <%- project.name -%>Package : ReactPackage { - override fun createNativeModules(reactContext: ReactApplicationContext): List { - return listOf(<%- project.name -%>Module(reactContext)) - } - - override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return emptyList() - } -} diff --git a/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt deleted file mode 100644 index 67e778677..000000000 --- a/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.<%- project.package %> - -import com.facebook.react.ReactPackage -import com.facebook.react.bridge.NativeModule -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.uimanager.ViewManager - - -class <%- project.name -%>Package : ReactPackage { - override fun createNativeModules(reactContext: ReactApplicationContext): List { - return emptyList() - } - - override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return listOf(<%- project.name -%>ViewManager()) - } -} diff --git a/packages/create-react-native-library/templates/kotlin-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 similarity index 100% rename from packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt rename to packages/create-react-native-library/templates/kotlin-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt 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 new file mode 100644 index 000000000..dbd7eec4e --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt @@ -0,0 +1,39 @@ +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-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 similarity index 100% rename from packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt rename to packages/create-react-native-library/templates/kotlin-view-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt 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 new file mode 100644 index 000000000..29d88c9eb --- /dev/null +++ b/packages/create-react-native-library/templates/native-view-library-legacy/src/index.tsx @@ -0,0 +1,7 @@ +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-library-legacy/src/index.tsx b/packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}.ts similarity index 73% rename from packages/create-react-native-library/templates/native-library-legacy/src/index.tsx rename to packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}.ts index 651971c33..220e70cd2 100644 --- a/packages/create-react-native-library/templates/native-library-legacy/src/index.tsx +++ b/packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}.ts @@ -6,7 +6,7 @@ const LINKING_ERROR = '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; -const <%- project.name -%> = NativeModules.<%- project.name %> +export const <%- project.name -%> = NativeModules.<%- project.name %> ? NativeModules.<%- project.name %> : new Proxy( {}, @@ -16,7 +16,3 @@ const <%- project.name -%> = NativeModules.<%- project.name %> }, } ); - -export function multiply(a: number, b: number): Promise { - return <%- project.name -%>.multiply(a, b); -} diff --git a/packages/create-react-native-library/templates/native-view-legacy/src/index.tsx b/packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}View.ts similarity index 100% rename from packages/create-react-native-library/templates/native-view-legacy/src/index.tsx rename to packages/create-react-native-library/templates/native-view-library-legacy/src/{%- project.name %}View.ts 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 new file mode 100644 index 000000000..99f7c846b --- /dev/null +++ b/packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.h @@ -0,0 +1,6 @@ +#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 new file mode 100644 index 000000000..5289baf7b --- /dev/null +++ b/packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}.mm @@ -0,0 +1,18 @@ +#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-legacy/ios/{%- project.name %}ViewManager.m b/packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}ViewManager.m similarity index 100% rename from packages/create-react-native-library/templates/objc-view-legacy/ios/{%- project.name %}ViewManager.m rename to packages/create-react-native-library/templates/objc-view-library-legacy/ios/{%- project.name %}ViewManager.m From 84b38fa7bf4f72d91a48b4a79394d88c6639c803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 18:47:54 +0300 Subject: [PATCH 14/31] fix: fabric option type --- packages/create-react-native-library/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index a3d3af5fc..819904102 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -168,7 +168,7 @@ const TYPE_CHOICES: { }, { title: 'Fabric view and Turbo module', - value: 'view-module-mixed', + value: 'view-module-new', description: NEWARCH_DESCRIPTION, }, { From fcab6b36d446d3c0f53fb9ec74bcb4572e0fbd5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 18:50:38 +0300 Subject: [PATCH 15/31] fix: readd native view option --- packages/create-react-native-library/src/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index 819904102..cf5d1a2c6 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -186,6 +186,11 @@ const TYPE_CHOICES: { 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', value: 'module-new', From ea78ef655b450be5b73b8f2f131ed37f92d5825e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 18:54:59 +0300 Subject: [PATCH 16/31] fix: bring back backward compatible turbo module --- packages/create-react-native-library/src/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index cf5d1a2c6..bad83fcdf 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -191,6 +191,11 @@ const TYPE_CHOICES: { 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', From 759e510aa16e9c2fe983c01c7446df734f314ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Tue, 11 Jun 2024 19:04:39 +0300 Subject: [PATCH 17/31] fix: CI types --- .github/workflows/build-templates.yml | 24 +++++++------------ .../create-react-native-library/src/index.ts | 2 +- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index e9716a7af..2778972e3 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -25,29 +25,21 @@ jobs: - ubuntu-latest - macos-14 # macos latest defaults to macos 12 at the moment. type: - - module-legacy - - module-mixed - - module-new - - view-legacy - view-module-mixed - view-module-new + - view-module-legacy language: - kotlin-objc - - kotlin-swift - exclude: - - type: module-legacy - - type: module-mixed - - type: module-new - - type: view-module-legacy - language: kotlin-swift - - type: view-module-mixed - language: kotlin-swift - - type: view-module-new - language: kotlin-swift include: - os: ubuntu-latest type: library language: js + - os: macos-latest + type: view-legacy + language: kotlin-swift + - os: macos-latest + type: module-legacy + language: kotlin-swift - os: ubuntu-latest type: module-legacy language: cpp @@ -124,7 +116,7 @@ jobs: # Build iOS for only some matrices to skip redundant builds if [[ ${{ matrix.os }} == macos-14 ]]; then - echo "ios_build=1" >> $GITHUB_ENV + echo "ios_build=1" >> $GITHUB_ENV 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 bad83fcdf..af3a74d53 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -104,11 +104,11 @@ type ArgName = type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js'; type ProjectType = + | 'library' | 'module-legacy' | 'module-mixed' | 'module-new' | 'view-legacy' - | 'library' | 'view-module-legacy' | 'view-module-mixed' | 'view-module-new'; From dc7e2f8364b40a9bf235255f12c52dd741247a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 12:42:13 +0300 Subject: [PATCH 18/31] feat: readd templates for cpp and swift --- .../native-library-legacy/src/index.tsx | 22 ++++++++++++++ .../src/Native{%- project.name %}.ts | 8 +++++ .../native-library-mixed/src/index.tsx | 29 +++++++++++++++++++ .../src/Native{%- project.name %}.ts | 8 +++++ .../native-library-new/src/index.tsx | 5 ++++ .../native-view-legacy/src/index.tsx | 26 +++++++++++++++++ 6 files changed, 98 insertions(+) create mode 100644 packages/create-react-native-library/templates/native-library-legacy/src/index.tsx create mode 100644 packages/create-react-native-library/templates/native-library-mixed/src/Native{%- project.name %}.ts create mode 100644 packages/create-react-native-library/templates/native-library-mixed/src/index.tsx create mode 100644 packages/create-react-native-library/templates/native-library-new/src/Native{%- project.name %}.ts create mode 100644 packages/create-react-native-library/templates/native-library-new/src/index.tsx create mode 100644 packages/create-react-native-library/templates/native-view-legacy/src/index.tsx diff --git a/packages/create-react-native-library/templates/native-library-legacy/src/index.tsx b/packages/create-react-native-library/templates/native-library-legacy/src/index.tsx new file mode 100644 index 000000000..651971c33 --- /dev/null +++ b/packages/create-react-native-library/templates/native-library-legacy/src/index.tsx @@ -0,0 +1,22 @@ +import { NativeModules, Platform } from 'react-native'; + +const LINKING_ERROR = + `The package '<%- project.slug -%>' doesn't seem to be linked. Make sure: \n\n` + + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + + '- You rebuilt the app after installing the package\n' + + '- You are not using Expo Go\n'; + +const <%- project.name -%> = NativeModules.<%- project.name %> + ? NativeModules.<%- project.name %> + : new Proxy( + {}, + { + get() { + throw new Error(LINKING_ERROR); + }, + } + ); + +export function multiply(a: number, b: number): Promise { + return <%- project.name -%>.multiply(a, b); +} diff --git a/packages/create-react-native-library/templates/native-library-mixed/src/Native{%- project.name %}.ts b/packages/create-react-native-library/templates/native-library-mixed/src/Native{%- project.name %}.ts new file mode 100644 index 000000000..166b44ed7 --- /dev/null +++ b/packages/create-react-native-library/templates/native-library-mixed/src/Native{%- project.name %}.ts @@ -0,0 +1,8 @@ +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 new file mode 100644 index 000000000..c583391a5 --- /dev/null +++ b/packages/create-react-native-library/templates/native-library-mixed/src/index.tsx @@ -0,0 +1,29 @@ +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-library-new/src/Native{%- project.name %}.ts b/packages/create-react-native-library/templates/native-library-new/src/Native{%- project.name %}.ts new file mode 100644 index 000000000..b6f84feb8 --- /dev/null +++ b/packages/create-react-native-library/templates/native-library-new/src/Native{%- project.name %}.ts @@ -0,0 +1,8 @@ +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-library-new/src/index.tsx b/packages/create-react-native-library/templates/native-library-new/src/index.tsx new file mode 100644 index 000000000..adc8b3076 --- /dev/null +++ b/packages/create-react-native-library/templates/native-library-new/src/index.tsx @@ -0,0 +1,5 @@ +const <%- project.name -%> = require('./Native<%- project.name -%>').default; + +export function multiply(a: number, b: number): number { + return <%- project.name -%>.multiply(a, b); +} diff --git a/packages/create-react-native-library/templates/native-view-legacy/src/index.tsx b/packages/create-react-native-library/templates/native-view-legacy/src/index.tsx new file mode 100644 index 000000000..055016821 --- /dev/null +++ b/packages/create-react-native-library/templates/native-view-legacy/src/index.tsx @@ -0,0 +1,26 @@ +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); + }; From b805ce9d52b822e09bc5e8a2b15e5d16ae6d5e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 14:00:06 +0300 Subject: [PATCH 19/31] refactor: rename files --- .../create-react-native-library/src/index.ts | 88 ++++++++++--------- .../{%- project.name %}Module.kt | 25 ++++++ .../{%- project.name %}Package.kt | 17 ++++ .../{%- project.name %}Module.kt | 24 +++++ .../{%- project.name %}Package.kt | 35 ++++++++ .../src/newarch/{%- project.name %}Spec.kt | 7 ++ .../src/oldarch/{%- project.name %}Spec.kt | 11 +++ .../{%- project.name %}Module.kt | 23 +++++ .../{%- project.name %}Package.kt | 34 +++++++ .../{%- project.name %}Package.kt | 17 ++++ .../{%- project.name %}ViewManager.kt | 20 +++++ 11 files changed, 260 insertions(+), 41 deletions(-) create mode 100644 packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt create mode 100644 packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt create mode 100644 packages/create-react-native-library/templates/kotlin-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt create mode 100644 packages/create-react-native-library/templates/kotlin-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt create mode 100644 packages/create-react-native-library/templates/kotlin-library-mixed/android/src/newarch/{%- project.name %}Spec.kt create mode 100644 packages/create-react-native-library/templates/kotlin-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt create mode 100644 packages/create-react-native-library/templates/kotlin-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt create mode 100644 packages/create-react-native-library/templates/kotlin-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-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt create mode 100644 packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index af3a74d53..2aa0767bd 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -38,54 +38,70 @@ const NATIVE_COMMON_EXAMPLE_FILES = path.resolve( ); const NATIVE_FILES = { - view_module_legacy: path.resolve( + '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( + 'view-module-mixed': path.resolve( __dirname, '../templates/native-view-library-mixed' ), - view_module_new: path.resolve( + 'view-module-new': path.resolve( __dirname, '../templates/native-view-library-new' ), } as const; const OBJC_FILES = { - module_common: path.resolve(__dirname, '../templates/objc-library'), - view_module_legacy: path.resolve( + '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( + 'view-module-mixed': path.resolve( __dirname, '../templates/objc-view-library-mixed' ), - view_module_new: path.resolve( + 'view-module-new': path.resolve( __dirname, '../templates/objc-view-library-new' ), } as const; const KOTLIN_FILES = { - view_module_legacy: path.resolve( + 'view-module-legacy': path.resolve( __dirname, '../templates/kotlin-view-library-legacy' ), - view_module_mixed: path.resolve( + 'view-module-mixed': path.resolve( __dirname, '../templates/kotlin-view-library-mixed' ), - view_module_new: path.resolve( + 'view-module-new': path.resolve( __dirname, '../templates/kotlin-view-library-new' ), + 'view-legacy': path.resolve(__dirname, '../templates/kotlin-view-legacy'), + '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'), } 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 = @@ -549,9 +565,9 @@ async function create(argv: yargs.Arguments) { version = FALLBACK_BOB_VERSION; } - const moduleType = type.startsWith('view-module') - ? 'view_module' - : type.startsWith('view') + const moduleType = type.startsWith('view-module-') + ? 'view-module' + : type.startsWith('view-') ? 'view' : 'module'; const arch = @@ -603,8 +619,8 @@ async function create(argv: yargs.Arguments) { arch, cpp: languages === 'cpp', swift: languages === 'kotlin-swift', - view: moduleType === 'view' || moduleType === 'view_module', - module: moduleType === 'module' || moduleType === 'view_module', + view: moduleType === 'view' || moduleType === 'view-module', + module: moduleType === 'module' || moduleType === 'view-module', }, author: { name: authorName, @@ -688,7 +704,7 @@ async function create(argv: yargs.Arguments) { } } - if (languages === 'js') { + if (type === 'library') { await copyDir(JS_FILES, folder); await copyDir(EXPO_FILES, folder); } else { @@ -705,32 +721,22 @@ async function create(argv: yargs.Arguments) { await copyDir(NATIVE_COMMON_EXAMPLE_FILES, folder); } - if (arch === 'mixed') { - // View module doesn't have legacy or a new arch only version. - await copyDir(NATIVE_FILES['view_module_mixed'], folder); - await copyDir(OBJC_FILES['view_module_mixed'], folder); - await copyDir(KOTLIN_FILES['view_module_mixed'], folder); - } else { - await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder); - - if (options.project.swift) { - await copyDir(SWIFT_FILES[`${moduleType}_legacy`], folder); - } else { - if (moduleType === 'module') { - await copyDir(OBJC_FILES[`${moduleType}_common`], folder); - } else { - await copyDir(OBJC_FILES[`view_${arch}`], folder); - } - } + await copyDir(NATIVE_FILES[type], folder); - const templateType = `${moduleType}_${arch}` as const; + if ( + type === 'view-legacy' || + (type === 'module-legacy' && options.project.swift) + ) { + await copyDir(SWIFT_FILES[type], folder); + } else { + await copyDir(OBJC_FILES[type], folder); + } - await copyDir(KOTLIN_FILES[templateType], folder); + await copyDir(KOTLIN_FILES[type], folder); - if (options.project.cpp) { - await copyDir(CPP_FILES, folder); - await fs.remove(path.join(folder, 'ios', `${options.project.name}.m`)); - } + if (options.project.cpp) { + await copyDir(CPP_FILES, folder); + await fs.remove(path.join(folder, 'ios', `${options.project.name}.m`)); } } diff --git a/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt b/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt new file mode 100644 index 000000000..392956228 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt @@ -0,0 +1,25 @@ +package com.<%- project.package %> + +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.bridge.ReactContextBaseJavaModule +import com.facebook.react.bridge.ReactMethod +import com.facebook.react.bridge.Promise + +class <%- project.name -%>Module(reactContext: ReactApplicationContext) : + ReactContextBaseJavaModule(reactContext) { + + override fun getName(): String { + return NAME + } + + // Example method + // See https://reactnative.dev/docs/native-modules-android + @ReactMethod + fun multiply(a: Double, b: Double, promise: Promise) { + promise.resolve(a * b) + } + + companion object { + const val NAME = "<%- project.name -%>" + } +} diff --git a/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt new file mode 100644 index 000000000..d34649aee --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-library-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt @@ -0,0 +1,17 @@ +package com.<%- project.package %> + +import com.facebook.react.ReactPackage +import com.facebook.react.bridge.NativeModule +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.uimanager.ViewManager + + +class <%- project.name -%>Package : ReactPackage { + override fun createNativeModules(reactContext: ReactApplicationContext): List { + return listOf(<%- project.name -%>Module(reactContext)) + } + + override fun createViewManagers(reactContext: ReactApplicationContext): List> { + return emptyList() + } +} diff --git a/packages/create-react-native-library/templates/kotlin-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 new file mode 100644 index 000000000..2cf84d752 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt @@ -0,0 +1,24 @@ +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 new file mode 100644 index 000000000..93368013b --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-library-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt @@ -0,0 +1,35 @@ +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 new file mode 100644 index 000000000..3711dacb2 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-library-mixed/android/src/newarch/{%- project.name %}Spec.kt @@ -0,0 +1,7 @@ +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 new file mode 100644 index 000000000..ef0259618 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt @@ -0,0 +1,11 @@ +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-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt b/packages/create-react-native-library/templates/kotlin-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt new file mode 100644 index 000000000..5da133031 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt @@ -0,0 +1,23 @@ +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-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt new file mode 100644 index 000000000..599cf307c --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-library-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt @@ -0,0 +1,34 @@ +package com.<%- project.package %> + +import com.facebook.react.TurboReactPackage +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 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() + moduleInfos[<%- project.name -%>Module.NAME] = ReactModuleInfo( + <%- project.name -%>Module.NAME, + <%- project.name -%>Module.NAME, + false, // canOverrideExistingModule + false, // needsEagerInit + true, // hasConstants + false, // isCxxModule + true // isTurboModule + ) + moduleInfos + } + } +} diff --git a/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt b/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt new file mode 100644 index 000000000..67e778677 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt @@ -0,0 +1,17 @@ +package com.<%- project.package %> + +import com.facebook.react.ReactPackage +import com.facebook.react.bridge.NativeModule +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.uimanager.ViewManager + + +class <%- project.name -%>Package : ReactPackage { + override fun createNativeModules(reactContext: ReactApplicationContext): List { + return emptyList() + } + + override fun createViewManagers(reactContext: ReactApplicationContext): List> { + return listOf(<%- project.name -%>ViewManager()) + } +} diff --git a/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt b/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt new file mode 100644 index 000000000..f52229f97 --- /dev/null +++ b/packages/create-react-native-library/templates/kotlin-view-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt @@ -0,0 +1,20 @@ +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)) + } +} From 1282d0a3bef84d6ae0ce6e2fd9a3f42832056ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 14:03:13 +0300 Subject: [PATCH 20/31] feat: test swift and kotlin templates' android counterparts --- .github/workflows/build-templates.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index 2778972e3..5942775c0 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -40,6 +40,12 @@ jobs: - os: macos-latest type: module-legacy language: kotlin-swift + - os: ubuntu-latest + type: view-legacy + language: kotlin-swift + - os: ubuntu-latest + type: module-legacy + language: kotlin-swift - os: ubuntu-latest type: module-legacy language: cpp From cc2d0fe8d731f9a1b13cca5e4d54f4e97f42e8fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 14:22:25 +0300 Subject: [PATCH 21/31] fix: app template tries then on new arch templates --- .../common-example/example/src/App.tsx | 42 ++++--------------- 1 file changed, 9 insertions(+), 33 deletions(-) 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 838d5750a..9bb518bb6 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 @@ -11,54 +11,30 @@ import { StyleSheet, View, Text } from 'react-native'; import { multiply } from '<%- project.slug -%>'; <% } -%> -<% if (project.view && project.module) { -%> -export default function App() { - const [result, setResult] = React.useState(); - - React.useEffect(() => { - multiply(3, 7).then(setResult); - }, []); - - return ( - - Result: {result} - <<%- project.name -%>View color="#32a852" style={styles.box} /> - - ); -} -<% } else if (project.view) { -%> -export default function App() { - return ( - - <<%- project.name -%>View color="#32a852" style={styles.box} /> - - ); -} -<% } else if (project.arch === 'new' && project.module) { -%> +<% if (project.arch === 'new' && project.module) { -%> const result = multiply(3, 7); +<% } -%> export default function App() { - return ( - - Result: {result} - - ); -} -<% } else { -%> -export default function App() { +<% if (project.arch !== 'new' && project.module) { -%> const [result, setResult] = React.useState(); React.useEffect(() => { multiply(3, 7).then(setResult); }, []); +<% } -%> return ( +<% if (project.module) { -%> Result: {result} +<% } -%> +<% if (project.view) { -%> + <<%- project.name -%>View color="#32a852" style={styles.box} /> +<% } -%> ); } -<% } -%> const styles = StyleSheet.create({ container: { From f17577850b284f96691f58623f856b424dc67d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 14:28:26 +0300 Subject: [PATCH 22/31] chore: dont skip any builds on ci --- .github/workflows/build-templates.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index 5942775c0..0d51c8840 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -115,9 +115,7 @@ jobs: run: | # Build Android for only some matrices to skip redundant builds 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 From 56e443f486210050ec36f91ae00552d9625afdb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 14:35:59 +0300 Subject: [PATCH 23/31] fix: prettier issue on view-module-legacy --- .../templates/native-view-library-legacy/src/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 29d88c9eb..0619f4994 100644 --- 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 @@ -1,4 +1,4 @@ -import { <%- project.name -%> } from './<%- project.name -%>' +import { <%- project.name -%> } from './<%- project.name -%>'; export function multiply(a: number, b: number): Promise { return <%- project.name -%>.multiply(a, b); From 850a115a18bfd623333ea5b96759c7315775ad29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 14:46:09 +0300 Subject: [PATCH 24/31] chore: update build matrix --- .github/workflows/build-templates.yml | 37 +++++++++++++++------------ 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index 0d51c8840..0dacee562 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -25,36 +25,41 @@ jobs: - ubuntu-latest - macos-14 # macos latest defaults to macos 12 at the moment. type: + - module-legacy + - module-mixed + - module-new + - view-module-legacy - view-module-mixed - view-module-new - - view-module-legacy language: - kotlin-objc + - cpp + exclude: + - type: viw-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 + language: kotlin-objc + - type: module-new + language: kotlin-objc include: - os: ubuntu-latest - type: library - language: js - - os: macos-latest type: view-legacy language: kotlin-swift - - os: macos-latest - type: module-legacy - language: kotlin-swift - - os: ubuntu-latest + - os: macos-14 type: view-legacy language: kotlin-swift - os: ubuntu-latest type: module-legacy language: kotlin-swift - - os: ubuntu-latest + - os: macos-14 type: module-legacy - language: cpp - - os: ubuntu-latest - type: module-mixed - language: cpp - - os: ubuntu-latest - type: module-new - language: cpp + language: kotlin-swift concurrency: group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }} From 89b50cf38b7a4db1905323762818b501032a96de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 14:48:29 +0300 Subject: [PATCH 25/31] fix: typo on pipeline --- .github/workflows/build-templates.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index 0dacee562..87e708eb5 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -35,7 +35,7 @@ jobs: - kotlin-objc - cpp exclude: - - type: viw-module-legacy + - type: view-module-legacy language: cpp - type: view-module-mixed language: cpp From f3fcef8983f06cac4f8c36c574880d0268e26c4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 14:50:42 +0300 Subject: [PATCH 26/31] chore: add js type to pipeline --- .github/workflows/build-templates.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index 87e708eb5..a704d3bbc 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -60,6 +60,9 @@ jobs: - os: macos-14 type: module-legacy language: kotlin-swift + - os: ubuntu-latest + type: library + language: js concurrency: group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }} From b418fc2913bc9282b2e4258c63c4113d16629d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 14:56:21 +0300 Subject: [PATCH 27/31] refactor: remove moduleType var --- .../create-react-native-library/src/index.ts | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index 2aa0767bd..6cb9d1867 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -565,17 +565,11 @@ async function create(argv: yargs.Arguments) { version = FALLBACK_BOB_VERSION; } - const moduleType = type.startsWith('view-module-') - ? 'view-module' - : type.startsWith('view-') - ? 'view' - : 'module'; - const arch = - type === 'module-new' || type === 'view-module-new' - ? 'new' - : type === 'module-mixed' || type === 'view-module-mixed' - ? 'mixed' - : 'legacy'; + const arch = type.endsWith('new') + ? 'new' + : type.endsWith('mixed') + ? 'mixed' + : 'legacy'; const example = hasExample && !local ? (type === 'library' ? 'expo' : 'native') : 'none'; @@ -619,8 +613,8 @@ async function create(argv: yargs.Arguments) { arch, cpp: languages === 'cpp', swift: languages === 'kotlin-swift', - view: moduleType === 'view' || moduleType === 'view-module', - module: moduleType === 'module' || moduleType === 'view-module', + view: type.includes('view'), + module: type.includes('module'), }, author: { name: authorName, From 23d67d58d44800f3aa56d837d18cac391e1504be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 15:07:16 +0300 Subject: [PATCH 28/31] refactor: make ordering better --- packages/create-react-native-library/src/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index 6cb9d1867..ae39abb47 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -78,6 +78,13 @@ const OBJC_FILES = { } 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' @@ -90,13 +97,6 @@ const KOTLIN_FILES = { __dirname, '../templates/kotlin-view-library-new' ), - 'view-legacy': path.resolve(__dirname, '../templates/kotlin-view-legacy'), - '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'), } as const; const SWIFT_FILES = { From f672ff6fd76c0ff01f25c16ac52fc1df2996fedd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 15:13:22 +0300 Subject: [PATCH 29/31] chore: skip native builds for js libs --- .github/workflows/build-templates.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index a704d3bbc..e21002541 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -122,12 +122,12 @@ jobs: working-directory: ${{ env.work_dir }} run: | # Build Android for only some matrices to skip redundant builds - if [[ ${{ matrix.os }} == ubuntu-latest ]]; then + if [[ ${{ matrix.os }} == ubuntu-latest ]] && [[ ${{ matrix.language }} != js ]] ; then echo "android_build=1" >> $GITHUB_ENV fi # Build iOS for only some matrices to skip redundant builds - if [[ ${{ matrix.os }} == macos-14 ]]; then + if [[ ${{ matrix.os }} == macos-14 ]] && [[ ${{ matrix.language }} != js ]]; then echo "ios_build=1" >> $GITHUB_ENV fi From ad401915b0dffddfd6e62ec675e8468980c02789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Wed, 12 Jun 2024 15:18:46 +0300 Subject: [PATCH 30/31] fix: js example doesn't use the method --- .../templates/common-example/example/src/App.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 9bb518bb6..55ebf1f82 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 @@ -16,7 +16,7 @@ const result = multiply(3, 7); <% } -%> export default function App() { -<% if (project.arch !== 'new' && project.module) { -%> +<% if ((project.arch !== 'new' && project.module) || !project.native) { -%> const [result, setResult] = React.useState(); React.useEffect(() => { @@ -26,7 +26,7 @@ export default function App() { <% } -%> return ( -<% if (project.module) { -%> +<% if (project.module || !project.native) { -%> Result: {result} <% } -%> <% if (project.view) { -%> From a710562aa5aa18736c939b3f277d6a03c316a704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Thu, 13 Jun 2024 16:25:21 +0300 Subject: [PATCH 31/31] feat: update README ot have view+module templates --- .../create-react-native-library/templates/common/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/create-react-native-library/templates/common/README.md b/packages/create-react-native-library/templates/common/README.md index ea2b491f0..d42a79cb3 100644 --- a/packages/create-react-native-library/templates/common/README.md +++ b/packages/create-react-native-library/templates/common/README.md @@ -18,7 +18,8 @@ import { <%- project.name -%>View } from "<%- project.slug -%>"; <<%- project.name -%>View color="tomato" /> ``` -<% } else if (project.arch === 'new' && project.module) { -%> +<% } -%> +<% if (project.module && project.arch === 'new') { -%> ```js import { multiply } from '<%- project.slug -%>'; @@ -27,7 +28,7 @@ import { multiply } from '<%- project.slug -%>'; const result = multiply(3, 7); ``` -<% } else { -%> +<% } else if (project.module) { -%> ```js import { multiply } from '<%- project.slug -%>';