Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8e8e114
feat: initial fabric cli
MateWW Aug 25, 2022
d5aec16
feat: fabric root directory
MateWW Aug 25, 2022
dbde595
feat: fabric src dir
MateWW Aug 25, 2022
677b08b
feat: fabric ios dir
MateWW Aug 25, 2022
9f1febf
feat: generate example app via `react-native init`
atlj Sep 6, 2022
a06282b
chore(example template): remove android files
atlj Sep 6, 2022
3d2482f
chore(example template): remove unused root files
atlj Sep 6, 2022
98f8e40
chore(example template): remove ios files
atlj Sep 6, 2022
795d980
chore(example template): remove android buildscripts
atlj Sep 6, 2022
93223d1
refactor: move rn example app generator to utils
atlj Sep 6, 2022
d7fa53f
feat: tbc
MateWW Sep 6, 2022
25bb21b
chore(example template): rename index.tsx to index.ts
atlj Sep 6, 2022
8bd1521
feat: enable new architecture on turbo module libraries
atlj Sep 6, 2022
1e3c167
feat: rename to new_arch
Sep 6, 2022
e1aacb6
refactor: rename app exampleAppGenerators to generateRNApp
atlj Sep 6, 2022
910769d
refactor: don't specify RN version for example apps
atlj Sep 6, 2022
8d3e444
refactor(example generator): extract files to delete to constant
atlj Sep 6, 2022
3e1548b
refactor(rn example generator): extract packages to add and remove
atlj Sep 6, 2022
2f01afb
fix: native example code is generated on expo projects
atlj Sep 6, 2022
a112c16
fix: example
Sep 6, 2022
a0390ea
fix: MainComponentsRegistry headers
Sep 6, 2022
f7fb47d
refactor(example generator): change isTurbomodule flag as isNewArch
atlj Sep 6, 2022
950881a
docs(example generator): remove version param from init command
atlj Sep 6, 2022
e5a5e8f
chore: revert naming
Sep 7, 2022
0a27b16
feat: implement fabric native view
Sep 7, 2022
6fd32f3
feat: set root package's react and react native versions from example…
atlj Sep 7, 2022
813862f
fix: lint
Sep 7, 2022
9e3a313
chore: add a patch for react-native 0.70.0 for codegen on ios
atlj Sep 7, 2022
72097b4
fix(example template): tests cant import `App.tsx`
atlj Sep 7, 2022
5a23737
fix(example generator): react-test-renderer and react-native types ar…
atlj Sep 8, 2022
bac2efa
chore: unify filenames
Sep 8, 2022
881aaf4
Merge branch '@atlj/integrate-react-native-init' into MateWW/fabric-t…
Sep 8, 2022
6d19ea5
fix: java view mixed path
Sep 13, 2022
bc926bc
fix: App.tsx template
Sep 13, 2022
dbfaf38
chore: bump react native version
Sep 13, 2022
bdb6dce
fix: App.tsx new arch
Sep 14, 2022
8ac7b5d
chore: bump @types/react-native to 0.70.0
Sep 14, 2022
fc40661
Merge branch 'main' into MateWW/fabric-template
Oct 24, 2022
a066c22
remove patch-package
Oct 24, 2022
1daacea
add fix flag
Oct 24, 2022
59d628c
- Remove commands
Oct 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 60 additions & 19 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const JS_FILES = path.resolve(__dirname, '../templates/js-library');
const EXPO_FILES = path.resolve(__dirname, '../templates/expo-library');
const CPP_FILES = path.resolve(__dirname, '../templates/cpp-library');
const EXAMPLE_FILES = path.resolve(__dirname, '../templates/example');
const EXAMPLE_TURBO_FILES = path.resolve(
const EXAMPLE_NEW_ARCH_FILES = path.resolve(
__dirname,
'../templates/example-turbo'
'../templates/example-new-arch'
);
const NATIVE_COMMON_FILES = path.resolve(
__dirname,
Expand All @@ -29,21 +29,30 @@ const NATIVE_COMMON_FILES = path.resolve(

const NATIVE_FILES = {
module_legacy: path.resolve(__dirname, '../templates/native-library-legacy'),
module_turbo: path.resolve(__dirname, '../templates/native-library-turbo'),
module_new_arch: path.resolve(
__dirname,
'../templates/native-library-new-arch'
),
module_mixed: path.resolve(__dirname, '../templates/native-library-mixed'),
view: path.resolve(__dirname, '../templates/native-view-library'),
view_mixed: path.resolve(__dirname, '../templates/native-view-mixed-library'),
};

const JAVA_FILES = {
module_legacy: path.resolve(__dirname, '../templates/java-library-legacy'),
module_turbo: path.resolve(__dirname, '../templates/java-library-turbo'),
module_new_arch: path.resolve(
__dirname,
'../templates/java-library-new-arch'
),
module_mixed: path.resolve(__dirname, '../templates/java-library-mixed'),
view: path.resolve(__dirname, '../templates/java-view-library'),
view_mixed: path.resolve(__dirname, '../templates/java-view-mixed-library'),
};

const OBJC_FILES = {
module: path.resolve(__dirname, '../templates/objc-library'),
view: path.resolve(__dirname, '../templates/objc-view-library'),
view_mixed: path.resolve(__dirname, '../templates/objc-view-mixed-library'),
};

const KOTLIN_FILES = {
Expand Down Expand Up @@ -80,7 +89,13 @@ type Answers = {
| 'kotlin-objc'
| 'kotlin-swift'
| 'cpp';
type?: 'module-legacy' | 'module-turbo' | 'module-mixed' | 'view' | 'library';
type?:
| 'module-legacy'
| 'module-new-arch'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satya164 , I changed 'xxx-turbo' => 'xxx-new-arch' to avoid any confusion.
Fabric will refer to view, turbomodule will refer to module. Since the fact fabric is a new renderer, I would like to use new-arch postfix for the new arch

| 'module-mixed'
| 'view'
| 'view-mixed'
| 'library';
example?: 'expo' | 'native';
};

Expand Down Expand Up @@ -120,6 +135,7 @@ const args: Record<ArgName, yargs.Options> = {
'js',
],
},
// TODO: update those types
'type': {
description: 'Type of library you want to develop',
choices: ['module', 'view'],
Expand Down Expand Up @@ -246,21 +262,26 @@ async function create(argv: yargs.Arguments<any>) {
},
{
title: 'Turbo module (experimental)',
value: 'module-turbo',
value: 'module-new-arch',
},
{
title: 'Native module',
value: 'module-legacy',
},
{ title: 'Native view', value: 'view' },
{
title: 'Native fabric view with backward compat (experimental)',
value: 'view-mixed',
},
{ title: 'JavaScript library', value: 'library' },
],
},
'languages': {
type: (_, values) =>
values.type === 'library' ||
values.type === 'module-turbo' ||
values.type === 'module-mixed'
values.type === 'module-new-arch' ||
values.type === 'module-mixed' ||
values.type === 'view-mixed'
? null
: 'select',
name: 'languages',
Expand Down Expand Up @@ -339,16 +360,21 @@ async function create(argv: yargs.Arguments<any>) {
version = FALLBACK_BOB_VERSION;
}

const moduleType = type === 'view' ? 'view' : 'module';
const moduleType = type.startsWith('view') ? 'view' : 'module';

const architecture =
type === 'module-turbo'
? 'turbo'
: type === 'module-mixed'
type === 'module-new-arch'
? 'new_arch'
: type === 'module-mixed' || type === 'view-mixed'
? 'mixed'
: 'legacy';

const turbomodule = architecture === 'turbo' || architecture === 'mixed';
const newArchitecture =
architecture === 'new_arch' || architecture === 'mixed';
const turbomodule =
(architecture === 'new_arch' || architecture === 'mixed') &&
moduleType === 'module';
const fabricView = architecture === 'mixed' && moduleType === 'view';

const options = {
bob: {
Expand All @@ -365,10 +391,12 @@ async function create(argv: yargs.Arguments<any>) {
native: languages !== 'js',
architecture,
turbomodule,
fabricView,
newArchitecture,
cpp: languages === 'cpp',
kotlin: languages === 'kotlin-objc' || languages === 'kotlin-swift',
swift: languages === 'java-swift' || languages === 'kotlin-swift',
view: type === 'view',
view: moduleType === 'view',
},
author: {
name: authorName,
Expand Down Expand Up @@ -426,9 +454,9 @@ async function create(argv: yargs.Arguments<any>) {
path.join(folder, 'example')
);

if (turbomodule) {
if (newArchitecture) {
await copyDir(
path.join(EXAMPLE_TURBO_FILES, 'example'),
path.join(EXAMPLE_NEW_ARCH_FILES, 'example'),
path.join(folder, 'example')
);
}
Expand All @@ -438,13 +466,23 @@ async function create(argv: yargs.Arguments<any>) {
if (moduleType === 'module') {
await copyDir(NATIVE_FILES[`${moduleType}_${architecture}`], folder);
} else {
await copyDir(NATIVE_FILES[moduleType], folder);
await copyDir(
NATIVE_FILES[`${moduleType}${newArchitecture ? '_mixed' : ''}`],
folder
);
}

if (options.project.swift) {
await copyDir(SWIFT_FILES[moduleType], folder);
} else {
await copyDir(OBJC_FILES[moduleType], folder);
if (moduleType === 'module') {
await copyDir(OBJC_FILES[moduleType], folder);
} else {
await copyDir(
OBJC_FILES[`${moduleType}${newArchitecture ? '_mixed' : ''}`],
folder
);
}
}

if (options.project.kotlin) {
Expand All @@ -453,7 +491,10 @@ async function create(argv: yargs.Arguments<any>) {
if (moduleType === 'module') {
await copyDir(JAVA_FILES[`${moduleType}_${architecture}`], folder);
} else {
await copyDir(JAVA_FILES[moduleType], folder);
await copyDir(
JAVA_FILES[`${moduleType}${newArchitecture ? '_mixed' : ''}`],
folder
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@release-it/conventional-changelog": "^5.0.0",
"@types/jest": "^28.1.2",
"@types/react": "~17.0.21",
"@types/react-native": "0.68.0",
"@types/react-native": <%-/* TODO: bump version of rn to 0.69.0 */ project.newArchitecture ? '"0.69.5"':'"0.68.0"'-%>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will adjust this todo after merge #271

"commitlint": "^17.0.2",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.5.0",
Expand Down Expand Up @@ -147,13 +147,13 @@
}
]
]
<% if (project.turbomodule) { -%>
<% if (project.newArchitecture) { -%>
},
"codegenConfig": {
"libraries": [
{
"name": "RN<%- project.name -%>Spec",
"type": "modules",
"name": "RN<%- project.name -%><%- project.view ? 'View': '' -%>Spec",
"type": <%- project.view ? '"components"': '"modules"' %>,
"jsSrcsDir": "src"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { <%- project.name -%>View } from "<%- project.slug -%>";

<<%- project.name -%>View color="tomato" />
```
<% } else if (project.architecture == 'turbo') { -%>
<% } else if (project.architecture == 'new_arch') { -%>
```js
import { multiply } from "<%- project.slug -%>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function App() {
</View>
);
}
<% } else if (project.architecture == 'turbo') { -%>
<% } else if (project.architecture === "new_arch" && project.turbomodule) { -%>
const result = multiply(3, 7);

export default function App() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
# If you wish to add a custom TurboModule or Fabric component in your app you
# will have to include the following autogenerated makefile.
# include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk
<% if (project.turbomodule) { -%>
<% if (project.newArchitecture) { -%>
include $(THIS_DIR)/../../../../../../android//build/generated/source/codegen/jni/Android.mk
<% } -%>
include $(CLEAR_VARS)
Expand Down Expand Up @@ -36,8 +36,8 @@ LOCAL_SHARED_LIBRARIES := \
libglog \
libjsi \
libreact_codegen_rncore \
<% if (project.turbomodule) { -%>
libreact_codegen_<%- project.name -%> \
<% if (project.newArchitecture) { -%>
libreact_codegen_<%- project.view ? project.name+'View': project.name -%> \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not be needed in RN 70

<% } -%>
libreact_debug \
libreact_nativemodule_core \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <fbjni/fbjni.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <react/renderer/components/rncore/ComponentDescriptors.h>
<% if (project.fabricView) { -%>
#include <react/renderer/components/<%- project.name -%>View/ComponentDescriptors.h>
<% } -%>

namespace facebook {
namespace react {
Expand All @@ -19,6 +22,9 @@ MainComponentsRegistry::sharedProviderRegistry() {
//
// providerRegistry->add(concreteComponentDescriptorProvider<
// AocViewerComponentDescriptor>());
<% if (project.fabricView) { -%>
providerRegistry->add(concreteComponentDescriptorProvider<<%- project.name -%>ViewComponentDescriptor>());
<% } -%>
return providerRegistry;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=<%- project.turbomodule ? true : false -%>
newArchEnabled=<%- project.newArchitecture ? true : false -%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.<%- project.package -%>;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.bridge.ReactApplicationContext;

import java.util.Map;


public class <%- project.name -%>ViewManager extends SimpleViewManager<<%- project.name -%>View> {

ReactApplicationContext mCallerContext;

public <%- project.name -%>ViewManager(ReactApplicationContext reactContext) {
mCallerContext = reactContext;
}

@Override
public String getName() {
return <%- project.name -%>ViewManagerImpl.NAME;
}

@Override
public <%- project.name -%>View createViewInstance(ThemedReactContext context) {
return <%- project.name -%>ViewManagerImpl.createViewInstance(context);
}

@Override
public Map<String, Integer> getCommandsMap() {
return MapBuilder.of("changeBackgroundColor", 1);
}

@Override
public void receiveCommand(
@NonNull <%- project.name -%>View view,
String commandId,
@Nullable ReadableArray args
) {
super.receiveCommand(view, commandId, args);
String color = args.getString(0);

switch (commandId) {
case "changeBackgroundColor":
setColor(view, color);
break;
default: {}
}
}


@ReactProp(name = "color")
public void setColor(<%- project.name -%>View view, String color) {
<%- project.name -%>ViewManagerImpl.setColor(view, color);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.<%- project.package -%>;

import com.facebook.react.uimanager.ThemedReactContext;
import android.graphics.Color;

public class <%- project.name -%>ViewManagerImpl {

public static final String NAME = "<%- project.name -%>View";

public static <%- project.name -%>View createViewInstance(ThemedReactContext context) {
return new <%- project.name -%>View(context);
}

public static void setColor(<%- project.name -%>View view, String color) {
view.setBackgroundColor(Color.parseColor(color));
}
}
Loading