Skip to content

Commit

Permalink
fix: remove view and module legacy templates
Browse files Browse the repository at this point in the history
  • Loading branch information
atlj committed Jun 11, 2024
1 parent 94c9964 commit d16092e
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 67 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/build-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
51 changes: 33 additions & 18 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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';

Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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<ArgName, yargs.Options> = {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<String, ReactModuleInfo> = 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<ViewManager<*, *>> {
return mutableListOf(<%- project.name -%>ViewManager());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { <%- project.name -%> } from './<%- project.name -%>'

export function multiply(a: number, b: number): Promise<number> {
return <%- project.name -%>.multiply(a, b);
}

export * from './<%- project.name -%>View';
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{},
Expand All @@ -16,7 +16,3 @@ const <%- project.name -%> = NativeModules.<%- project.name %>
},
}
);

export function multiply(a: number, b: number): Promise<number> {
return <%- project.name -%>.multiply(a, b);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import <React/RCTBridgeModule.h>

@interface <%- project.name -%> : NSObject <RCTBridgeModule>
#endif

@end
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d16092e

Please sign in to comment.