Summary:
This moves the test script that generates **all outputs using all generators** to a dedicated "generate-all" CLI. This allows us to use it via Buck, at FB and OSS.
Also renamed the target to be more specific: "rn_codegen" => "generate_all_from_schema"
Changelog: [Internal]
Reviewed By: hramos
Differential Revision: D24513995
fbshipit-source-id: 8435d3d065718eb1309c1c61fe28fb592787311a
Summary:
For now, separate the definition of `modules` generator per platform to avoid file output collision. Additionally:
* For Android, produce files under java/ (plus nested subdirs based on packageName) and jni/ (for C++ files) - JavaPoet version already does it
* Allow configuring packageName for Android - JavaPoet version has this
* Avoid tmp directory dance in the CLI script, given the proper modules separation
Changelog: [Internal]
Reviewed By: hramos
Differential Revision: D24410864
fbshipit-source-id: 9bd6bc1d65bec037bfca32ec478f3af50d72e927
Summary:
This adds all the packages we use to the workspace in open source, which means we can change our publish scripts to also publish the packages from the repo every time we publish the main repo. I'll work with somebody from the community on that part.
Note: We do not use `eslint-config-react-native-community` internally and it pulls in a lot of packages we don't need. It is part of the React Native repo because it is used in the RN app template but we may want to choose to move it out into a separate repo at some point.
Changelog: [Internal]
Reviewed By: motiz88
Differential Revision: D23208695
fbshipit-source-id: 02d401721dfdc8bbb2305f8ac3381f1e98c18f1d
Summary:
This diff moves fabric C++ code from ReactCommon/fabric to ReactCommon/react/renderer
As part of this diff I also refactored components, codegen and callsites on CatalystApp, FB4A and venice
Script: P137350694
changelog: [internal] internal refactor
Reviewed By: fkgozali
Differential Revision: D22852139
fbshipit-source-id: f85310ba858b6afd81abfd9cbe6d70b28eca7415
Summary:
Some props must have their default values set by native. To be able to support this, we have to introduce a null as a supported default value for some types. In this diff I'm adding support for null default values for float props. An example of this to be useful is `ReactDrawerLayoutManager`:
```
Override
public void setDrawerWidth(ReactDrawerLayout view, Nullable Float width) {
int widthInPx =
width == null
? LayoutParams.MATCH_PARENT
: Math.round(PixelUtil.toPixelFromDIP(width));
view.setDrawerWidth(widthInPx);
}
```
We need to be able to generate an interface method, that accepts a boxed `Float` value instead of the primitive `float` so that the native code can decide what value to use by default (`LayoutParams.MATCH_PARENT` in this case).
Reviewed By: rickhanlonii
Differential Revision: D17343172
fbshipit-source-id: 7662a4e0e495f58d05a92892f063535a359d09ae
Summary: Some props must have their default values set by native. To be able to support this, we have to introduce a `null` as a supported default value for some types. In this diff I'm adding support for `null` default values for boolean props. Check D17260168 for the example of the usage of the nullable boolean values.
Reviewed By: rickhanlonii, TheSavior
Differential Revision: D17258234
fbshipit-source-id: 63b7864be97856704d5964230526f23c0e395a67
Summary:
** Summary of failures encountered during the build **
Rule //fbandroid/java/com/facebook/catalyst/launcher:app_prod_debug FAILED because Command failed with exit code 1.
stderr: /java/InterfaceOnlyNativeComponentViewManagerDelegate.java:18: error: reference to setAccessibilityHint is ambiguous
mViewManager.setAccessibilityHint(view, value == null ? "" : (String) value);
^
both method setAccessibilityHint(T,java.lang.String) in com.facebook.react.uimanager.BaseViewManagerInterface and method setAccessibilityHint(T,java.lang.String) in com.facebook.react.viewmanagers.InterfaceOnlyNativeComponentViewManagerInterface match
/java/StringPropNativeComponentViewManagerDelegate.java:18: error: reference to setAccessibilityHint is ambiguous
mViewManager.setAccessibilityHint(view, value == null ? "" : (String) value);
^
both method setAccessibilityHint(T,java.lang.String) in com.facebook.react.uimanager.BaseViewManagerInterface and method setAccessibilityHint(T,java.lang.String) in com.facebook.react.viewmanagers.StringPropNativeComponentViewManagerInterface match
/java/StringPropNativeComponentViewManagerDelegate.java:21: error: reference to setAccessibilityRole is ambiguous
mViewManager.setAccessibilityRole(view, value == null ? null : (String) value);
^
both method setAccessibilityRole(T,java.lang.String) in com.facebook.react.uimanager.BaseViewManagerInterface and method setAccessibilityRole(T,java.lang.String) in com.facebook.react.viewmanagers.StringPropNativeComponentViewManagerInterface match
Errors: 3. Warnings: 0.
When running <javac_jar>.
When building rule //xplat/js/react-native-github/packages/react-native-codegen:generated_components_java-codegen_testsAndroid.
```
Reviewed By: mdvacca
Differential Revision: D17107929
fbshipit-source-id: 32bc553d450628c530e22cb13f305e3a3e0f45cd
Summary: Adds e2e tests for the array of object prop types in the codegen
Reviewed By: rubennorte, motiz88
Differential Revision: D16814301
fbshipit-source-id: 613f32a888451c0c1b7359133b7bf88878e36916
Summary:
This diff introduces an interface `ViewManagerDelegate` and its base implementation `BaseViewManagerDelegate`, which is used as a parent class for all view manager delegates generated by the JS codegen. Before the changes in this diff, generated delegates didn't support setting the base view properties such as background color, rotation, opacity, etc. Now it's possible to do by using `BaseViewManagerDelegate.setProperty(...)`, and since all generated delegates extend BaseViewManagerDelegate, they can just call `super.setProperty(...)` for properties they don't want to handle.
This diff also introduced a new method `ViewManager.getDelegate()`. This will allow view managers to return an instance of the delegate generated by JS and ensure that the view properties are set in a type-safe manner. If this method returns null (it does by default), we fall back to the default implementation of setting view properties using Java-generated `$$PropsSetter`
classes.
This is an example of an interface class generated by JS:
```
public interface RCTAxialGradientViewViewManagerInterface<T extends View> {
void setColors(T view, Nullable ReadableArray value);
void setLocations(T view, Nullable ReadableArray value);
void setEndX(T view, Float value);
void setEndY(T view, Float value);
void setStartX(T view, Float value);
void setStartY(T view, Float value);
}
```
This is an example of a delegate class generated by JS:
```
public class RCTAxialGradientViewManagerDelegate<T extends View, U extends BaseViewManager<T, ? extends LayoutShadowNode> & RCTAxialGradientViewManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
public RCTAxialGradientViewManagerDelegate(U viewManager) {
super(viewManager);
}
Override
public void setProperty(T view, String propName, Nullable Object value) {
switch (propName) {
case "colors":
mViewManager.setColors(view, (ReadableArray) value);
break;
case "locations":
mViewManager.setLocations(view, (ReadableArray) value);
break;
case "endX":
mViewManager.setEndX(view, value == null ? Float.NaN : ((Double) value).floatValue());
break;
case "endY":
mViewManager.setEndY(view, value == null ? Float.NaN : ((Double) value).floatValue());
break;
case "startX":
mViewManager.setStartX(view, value == null ? Float.NaN : ((Double) value).floatValue());
break;
case "startY":
mViewManager.setStartY(view, value == null ? Float.NaN : ((Double) value).floatValue());
break;
default:
super.setProperty(view, propName, value);
}
}
}
```
NOTE: What if a view manager, for instance ReactAxialGradientManager, wanted to add support for the borderRadius prop? In the old Java codegen, it would just need to create a method and annotate it with ReactProp (name = ViewProps.BORDER_RADIUS) and $$PropsSetter would call this method when a property with this name must be set. With the new JS codegen, borderRadius is a part of the basic view props, so setBorderRadius is not generated as a part of the ViewManagerInterface, so it’s not possible to set this value. I see two options: 1) add a method boolean setProperty (String propName, Object value) and let the view manager handle it in a non-type safe way (return true if it’s been handled). 2) Generate BaseViewManagerInterface which will include all basic view props and make BaseViewManager implement this interface, leaving all methods empty so that it stays compatible with the current implementation. Override these methods in a view manager that needs to handle a specific property in a custom way (so we would override setBorderRadius in ReactAxialGradientManager).
Reviewed By: mdvacca
Differential Revision: D16667686
fbshipit-source-id: 06a15a92f8af55640b7a53c5a34f40366d1be2a8
Summary:
Following our internal discussion we want to change previously used name convention.
Now it looks like:
```
#import <FBReactNativeTestSpec/FBReactNativeTestSpec.h>
```
Name is a param of `rn_codegen` and `rn_library`. Also, I found it the easiest to move replacing `::_IMPORT_::` into buck rule
Reviewed By: fkgozali
Differential Revision: D16646616
fbshipit-source-id: 2c33c5b4d1c42b0e6f5a42d9a318bd8bda9745f4
Summary: Cpp and Objcpp should not be in the same rules since codegen has different purposes. I split them into into two rules and update tests for new names.
Reviewed By: TheSavior
Differential Revision: D16599257
fbshipit-source-id: 3a8be8c0e289825f9d5db831cc2eec3d2bf9728d
Summary:
This diff contains bunch of minor and straightforward fixes which need to be shipped together. They are all related to integrating objCpp codegen and compiling examples.
#Facebook
I explain in comments my thoughts
Reviewed By: RSNara
Differential Revision: D16520560
fbshipit-source-id: 15392017a92f5a7ec5da71b552ec6c6904625a86
Summary: Add a test to ensure that the generated code is syntactically valid and compiles.
Reviewed By: JoshuaGross, osdnk
Differential Revision: D16518542
fbshipit-source-id: d4fadaeb29194ca38c8a99874ab304a464632894
Summary:
Changes the java props class and file names to include "ViewManager" as in:
- ExampleViewManagerInterface
- ExampleViewManagerDelegate
Reviewed By: JoshuaGross, makovkastar
Differential Revision: D16418965
fbshipit-source-id: f8b2f8fe4145c0ada9dc7c5234fcc41935783374
Summary: This diff adds some basic tests that ensure all of the e2e test components can compile with the interface is implemented (we also have these tests for cxx)
Reviewed By: JoshuaGross, mdvacca
Differential Revision: D16378756
fbshipit-source-id: d0c6dc976c74f6a388068e66b9a2135bc4ce4652
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/25673
This diff add e2e code generator validation. I added proper buck rule which compiles cpp code and test if it really compiles.
While testing I faced few minor issues:
- `getBool` and `getNumber` shouldn't have `rt` param.
- Generators now start considering whole module name instead of sliced part of their name.
- Fixed import structure in generated cpp.
- renamed `jsireact` to `ReactCommon` following D16231697
Reviewed By: rickhanlonii
Differential Revision: D16221277
fbshipit-source-id: aff4011ad52dd5e16546ffdb709d6a751ebfaced
Summary:
This diff switches the native codegen over to the flow parser
It does this by:
- Creating a new e2e directory
- Migrating the schema.js fixtures to flow types in e2e/
- Updating the buck tests to use the flow type fixtures
- Finally, updating the rest of rn_codegen to use *NativeComponent instead of *Schema.js
Removing all of the schemas in the next diff to keep this one clean
Reviewed By: cpojer
Differential Revision: D15960603
fbshipit-source-id: 3df28b31e618491301578ab7f6e28a80f55404b2
Summary:
This diff reorganizes some of the code in react-native-codegen as requested in T44120025
There are two new dirs: `scr/cli` and `src/parsers`
```
buck_tests/
src/
cli/
generators/
parsers/
```
We moved anything cli-ish from `buck_tests` to the `src/cli` directory:
```
src/
cli/
combine/
combine_js_to_schema.sh
combine_js_to_schema-cli.js
combine_js_to_schema.js
viewconfigs/
generate-view-configs-cli.js
generate-view-configs.js
generate-view-configs.sh
```
And we created a new `src/parsers` directory that will contain the flow parser and the current schema parser:
```
src/
parsers/
flow/
index.js
schema/
index.js
```
This should organize the code a little better and make it easier to contribute 👍
Reviewed By: cpojer
Differential Revision: D15414264
fbshipit-source-id: 376af2e91def033855f6ed72a9a9cc4369c33c7d
Summary:
This diff adds a new `--test` option to `js1 build viewconfigs` which will only check that the configs have not changed instead of writing the new/updated files. This will allow us to run sandcastle checks on the view configs
I also improved the output of the script to give better feedback during normal runs including an additional message and a summary of generated files
Reviewed By: TheSavior
Differential Revision: D15372843
fbshipit-source-id: 4988fc2405cc03137b540817e08d4365cb31fc34
Summary: We're going to be incrementally adding these view configs and enforcing that they're up to date in react-native-sanity-test so we need to limit them to what's supported (which is just Slider for now)
Reviewed By: TheSavior
Differential Revision: D15321950
fbshipit-source-id: 22b014db1d9b58553237f571b438c82948f19634
Summary:
This diff adds a new `js1` script `js1 build viewconfigs` which will generate the view configs for generated components in xplat/js
Note that the view configs are not currently valid so I'm not checking them in or adding them to a test, that work will follow
Reviewed By: TheSavior
Differential Revision: D15239656
fbshipit-source-id: d15776f36a7d7684f50beafd783bccb02352afc0
Summary: Adds support for the native type Point to the rn codegen
Reviewed By: TheSavior
Differential Revision: D14462164
fbshipit-source-id: 942b5697d616c6aa6289d01bb56382fd7adac203
Summary: Change the codegen `srcs` to match any `**/*Schema.js`
Reviewed By: TheSavior
Differential Revision: D14401232
fbshipit-source-id: 61e60b1c9ca2f33efacc5caa1903b02a93cc644e
Summary: In some cases the implementation for native modules are more advanced and we cannot currently generate some of the files. We've decided in these cases to only generate the props + events for now, so this flag `interfaceOnly` will only generate those files 👍
Reviewed By: TheSavior
Differential Revision: D14295980
fbshipit-source-id: 1790825143206a84469015e08958bf6f00ffde52
Summary: Re-enables the disabled codegens on android by renaming the test fixtures to something shorter
Reviewed By: TheSavior
Differential Revision: D14258414
fbshipit-source-id: 912c12df039930ec492b5bafc69bc298f913bdcc
Summary:
Updates the combine-js-to-schema to expose a cli and combine all passed files into a single schema output
Note: as far as I could tell, there isn't a way for buck to pass a glob of directories, so instead of accepting a dir and crawling it, this update accepts a list of files and combines them. Which makes sense, since buck is good at crawling already
Reviewed By: TheSavior
Differential Revision: D14007193
fbshipit-source-id: dbc209bb8d1cadd381269e9f70dc71a90f77878e
Summary: This is the first step in organizing React Native slightly differently. This doesn't set up a "monorepo" structure for the GitHub repo yet, it merely moves a few files around and I slightly updated the package.json file for the codegen project.
Reviewed By: rickhanlonii, TheSavior
Differential Revision: D13974180
fbshipit-source-id: f53375f3b6618ef12658064cb1fc690ef1f95299