Граф коммитов

36 Коммитов

Автор SHA1 Сообщение Дата
Kevin Gozali 2a634f452c Codegen BUCK: moved generate-test.sh to be general-purpose generate-all CLI
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
2020-10-24 14:02:47 -07:00
Kevin Gozali 13d9927a48 Codegen: separate Android/Cxx/iOS modules codegen outputs
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
2020-10-20 14:11:45 -07:00
Christoph Nakazawa 3967635632 Add a proper "monorepo" setup for React Native
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
2020-08-21 02:54:24 -07:00
David Vacca 3093010ea5 move fabric to ReactCommon/react/renderer
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
2020-07-31 13:34:29 -07:00
Andres Suarez aee88b6843 Tidy up license headers [3/n]
Summary: Changelog: [General] [Fixed] - License header cleanup

Reviewed By: yungsters

Differential Revision: D17952693

fbshipit-source-id: 8fcb8e58a2e04e7a3169f4d525bffc00835768e6
2019-10-16 10:06:34 -07:00
Samuel Susla 845cbec5cf Add codegen support for EdgeInsets
Summary: Add codegen support for `EdgeInsets`.

Reviewed By: rickhanlonii

Differential Revision: D17500509

fbshipit-source-id: b2909fe296c51d3a47cc961c45294eead7707853
2019-09-23 09:12:51 -07:00
Oleksandr Melnykov 92f3b4a27f Allow null as default value for float props
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
2019-09-23 07:18:09 -07:00
Oleksandr Melnykov bf89d1d536 Allow null as default value for boolean props
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
2019-09-23 07:18:08 -07:00
Rick Hanlon c232b5ae3b Add e2e tests for int enums
Summary: This diff adds e2e tests for int enums

Reviewed By: JoshuaGross

Differential Revision: D17161728

fbshipit-source-id: 25003d9472d1df53931e9df8d42d5a68e9d11632
2019-09-06 05:33:08 -07:00
Oleksandr Melnykov 38089753ef Fix tests for JS codegen by renaming conflicting props
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
2019-08-30 09:40:48 -07:00
Rick Hanlon 958b7aa9aa Add e2e tests for array object props
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
2019-08-15 06:38:15 -07:00
Rick Hanlon 70fc54a20b Add e2e test for object props
Summary: Adds e2e tests for cxx and java object props

Reviewed By: JoshuaGross

Differential Revision: D16759242

fbshipit-source-id: 2307dc4b3ba26222de510cf5876c582d35fc665c
2019-08-15 06:38:14 -07:00
Oleksandr Melnykov a5aaca7d4f Migrate RCTAxialGradientView to JS codegen
Summary:
This diff migrates `RCTAxialGradientView` to use generated `RCTAxialGradientViewManagerDelegate` for setting its props. The following base properties have been added to `BaseViewManager`:

```
  protected void setBorderRadius(T view, float borderRadius) {}

  protected void setBorderBottomLeftRadius(T view, float borderRadius) {}

  protected void setBorderBottomRightRadius(T view, float borderRadius) {}

  protected void setBorderTopLeftRadius(T view, float borderRadius) {}

  protected void setBorderTopRightRadius(T view, float borderRadius) {}
```

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D16784173

fbshipit-source-id: f3971985efee2b6e0a5fb248b89c4809305e670c
2019-08-14 04:44:12 -07:00
Oleksandr Melnykov 50fe8119de Use ViewManagerDelegate if provided instead of $$PropsSetter to update view props
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
2019-08-12 06:36:24 -07:00
Michał Osadnik 0da4612f03 change name convention for modules
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
2019-08-08 11:18:08 -07:00
Michał Osadnik 32c7e3a1aa Split module codegen buck rules for cpp and objcpp
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
2019-08-02 07:24:31 -07:00
Michał Osadnik 094a9b585d Add e2e tests and bunch of improvements for codegen
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
2019-08-01 04:23:05 -07:00
Eli White f22a7c67bd Validate objc command header compiles
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
2019-07-29 14:41:32 -07:00
Rick Hanlon e9af5726c5 Update java prop file names to include ViewManager
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
2019-07-24 10:36:24 -07:00
Michał Osadnik d143edc298 Add test determining if ObjC files are compiling
Summary: Add compilation rule for objC emptyFile which includes generated objC files generated from fixtures.

Reviewed By: RSNara

Differential Revision: D16439245

fbshipit-source-id: 6529b2232625a72e2430f1d415511196abc08ecb
2019-07-24 08:33:56 -07:00
Rick Hanlon 32b812c05c Add Java buck tests
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
2019-07-19 15:04:06 -07:00
Rick Hanlon 1783780a92 Add buck rule to generate Java library
Summary: Adds buck rule for generated code

Reviewed By: mdvacca, makovkastar

Differential Revision: D16338763

fbshipit-source-id: 6b238b3993cc110f009ad541cfa924d0d06d2fcb
2019-07-19 15:04:06 -07:00
Michał Osadnik d6722477c4 Add e2e tests skeleton for generated cpp code (#25673)
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
2019-07-17 06:21:48 -07:00
Rick Hanlon 98b03fa1b9 Switch native codegen over to flow parser
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
2019-06-27 08:04:13 -07:00
Rick Hanlon 9e97f71579 Organize files
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
2019-05-22 06:02:03 -07:00
Rick Hanlon 3ccfbd6c39 Add test for js1 build viewconfigs
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
2019-05-20 02:52:37 -07:00
Rick Hanlon fb41a836be Only generate supported schemas
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
2019-05-16 10:51:07 -07:00
Rick Hanlon c9d9f8cc2a Add js1 build viewconfigs
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
2019-05-16 10:51:05 -07:00
Rick Hanlon 0827184c60 Add PointPrimitive
Summary: Adds support for the native type Point to the rn codegen

Reviewed By: TheSavior

Differential Revision: D14462164

fbshipit-source-id: 942b5697d616c6aa6289d01bb56382fd7adac203
2019-03-19 06:36:33 -07:00
Rick Hanlon 7723c31329 Add ArrayTypeAnnotation
Summary:
Adds support for `ArrayTypeAnnotation`, usage is as:

```
{
  type: 'ArrayTypeAnnotation',
  items: {
    type: 'BooleanTypeAnnotation',
}

{
  type: 'ArrayTypeAnnotation',
  items: {
    type: 'StringTypeAnnotation',
}

{
  type: 'ArrayTypeAnnotation',
  items: {
    type: 'FloatTypeAnnotation',
}

{
  type: 'ArrayTypeAnnotation',
  items: {
    type: 'Int32TypeAnnotation',
}

{
  type: 'ArrayTypeAnnotation',
  items: {
    type: 'NativePrimitiveTypeAnnotation',
    name: 'ImageSourcePrimitive'
}

{
  type: 'ArrayTypeAnnotation',
  items: {
    type: 'NativePrimitiveTypeAnnotation',
    name: 'ColorPrimitive'
}

{
  type: 'ArrayTypeAnnotation',
  items: {
    type: 'NativePrimitiveTypeAnnotation',
    name: 'PointPrimitive' // added in the next dfif
}
```

Reviewed By: TheSavior

Differential Revision: D14462086

fbshipit-source-id: f0c25f8fe969efc01e5838f3966d910fbbd9c86c
2019-03-19 06:36:33 -07:00
Rick Hanlon bcd259a355 Enable Schema everywhere
Summary: Change the codegen `srcs` to match any `**/*Schema.js`

Reviewed By: TheSavior

Differential Revision: D14401232

fbshipit-source-id: 61e60b1c9ca2f33efacc5caa1903b02a93cc644e
2019-03-13 07:02:32 -07:00
Rick Hanlon f72776e8dc Add inferfaceOnly option to CodegenSchema
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
2019-03-05 11:53:56 -08:00
Rick Hanlon cf3653baac Generate ImageSource
Summary: Generates the ImageSource primitive for components like Slider

Reviewed By: TheSavior

Differential Revision: D14262452

fbshipit-source-id: 29df3d64706633b51c784fa9acf2f054a510de76
2019-03-02 12:56:02 -08:00
Rick Hanlon ba0b52f750 Re-enable catalyst app for android
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
2019-03-02 12:56:02 -08:00
Rick Hanlon 34763bf7f9 Update script to parse all specs in folder
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
2019-02-11 15:18:39 -08:00
Christoph Nakazawa 5ed749e1b2 Move codegen into packages/react-native-codegen
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
2019-02-07 03:09:05 -08:00