-
Notifications
You must be signed in to change notification settings - Fork 221
feat: add fabric option #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
8e8e114
d5aec16
dbde595
677b08b
9f1febf
a06282b
3d2482f
98f8e40
795d980
93223d1
d7fa53f
25bb21b
8bd1521
1e3c167
e1aacb6
910769d
8d3e444
3e1548b
2f01afb
a112c16
a0390ea
f7fb47d
950881a
e5a5e8f
0a27b16
6fd32f3
813862f
9e3a313
72097b4
5a23737
bac2efa
881aaf4
6d19ea5
bc926bc
dbfaf38
bdb6dce
8ac7b5d
fc40661
a066c22
1daacea
59d628c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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 = { | ||
|
@@ -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' | ||
|
||
| 'module-mixed' | ||
| 'view' | ||
| 'view-mixed' | ||
| 'library'; | ||
example?: 'expo' | 'native'; | ||
}; | ||
|
||
|
@@ -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'], | ||
|
@@ -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', | ||
|
@@ -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: { | ||
|
@@ -365,10 +391,12 @@ async function create(argv: yargs.Arguments<any>) { | |
native: languages !== 'js', | ||
architecture, | ||
turbomodule, | ||
fabricView, | ||
newArchitecture, | ||
troZee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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, | ||
|
@@ -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') | ||
); | ||
} | ||
|
@@ -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) { | ||
|
@@ -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 | ||
); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"'-%>, | ||
|
||
"commitlint": "^17.0.2", | ||
"eslint": "^8.4.1", | ||
"eslint-config-prettier": "^8.5.0", | ||
|
@@ -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" | ||
} | ||
] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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 -%> \ | ||
|
||
<% } -%> | ||
libreact_debug \ | ||
libreact_nativemodule_core \ | ||
|
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) { | ||
troZee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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)); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.