Commit Graph

195 Commits

Author SHA1 Message Date
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
Oleksandr Melnykov 9d5d2549e3 Add copyright header and @generated annotation to Android view manager interfaces and delegates
Summary: This diff adds a missing copyright header and the `generated` annotation to the Java files generated by the JS codegen. Since we are going to check in the generated classes for the OSS components, we need to make sure the Lint formatter doesn't complain about formatting issues in those files.

Reviewed By: fkgozali

Differential Revision: D17101946

fbshipit-source-id: 1361a294b8c1538c0ea346b43ef623e843d7038d
2019-08-29 16:08:47 -07:00
Logan Daniels b6333f79e1 Final fixes and seal xplat/js/react-native-github
Reviewed By: panagosg7

Differential Revision: D16946423

fbshipit-source-id: 89ca82c955e99a23a14984d51f3c97346c363afd
2019-08-23 08:45:11 -07:00
Joshua Gross cafbf67d0d Fix generated props CPP default values
Summary:
This one is fun.

# What?

Previously, the codegen'd constructor for a prop value in CPP was defined like so: `value(convertRawProp(rawProps, "value", sourceProps.value, value))`.

The fourth argument there is the default value of the result of `convertRawProps`. What that is saying is: the default value of `value` is `value` - the default value is itself.

The assumption was that because value is defined as `T value{someDefaultValue}` in the struct, in other words, because it has a default value in the `.h` file, that it will /start out/ being equal to `someDefaultValue`, and then be overridden later optionally, or be set to itself, which should be `someDefaultValue`.

However, that is not how initialization of class members in C++ constructors work. If a class member is in the member initializer list, [then the default value is not set](https://en.cppreference.com/w/cpp/language/initializer_list). That means that if the `defaultValue` as passed is /ever/ used, we incur undefined behavior.

# When is the defaultValue used?

The defaultValue is only used when no prop or a null value is sent from JS to C++: https://our.intern.facebook.com/intern/diffusion/FBS/browse/master/xplat/js/react-native-github/ReactCommon/fabric/core/propsConversions.h?commit=becfded106d706e6028e705d7883483051061e9f&lines=60

In most cases, the `sourceProps.value` is actually used as a fallback (the previous props value). The first time props are ever constructed, `sourceProps` should have valid values since it goes through a different path where only the defaultValues from props.h are used.

# Why wasn't this crashing before?

Most codegen'd properties are ints, floats, doubles, and bools. They might get wacky values, but they won't crash. I wouldn't be surprised if this diff solves some subtle visual or layout bugs, but I have no evidence of this yet.

# How do non-codegen'd props.cpp initialize default values?

Same as this diff does: defaultValue should be explicit everywhere: https://our.intern.facebook.com/intern/diffusion/FBS/browse/master/xplat/js/react-native-github/ReactCommon/fabric/components/scrollview/ScrollViewProps.cpp?commit=2813789c292dfdf1220b88f203af6b33ba9e42de&lines=51

# So... what have we learned?

C++ is tricky!

Reviewed By: yungsters, shergin

Differential Revision: D16955421

fbshipit-source-id: 75bb3f22822299e17df1c36abecdb6ce49012406
2019-08-22 14:05:09 -07:00
Eli White 3b7eb7ed85 Fix Flowtype for Command refs
Summary:
The types we were using before weren't very strict and it had been on my list to fix this. I *think* this is the right type. With Flow's type first project having these exported types will be necessary anyways so we can just use that for the ref.

Changelog:
[Internal]

Reviewed By: JoshuaGross

Differential Revision: D16930573

fbshipit-source-id: 05c1e097794633a2cefa7384c9d81ab15a63d8af
2019-08-22 12:07:50 -07:00
Michał Osadnik 17381f197f Add tests for comparing old and new codegen
Summary:
add script which proves that new codegen gives a similar code as old one.

How it works?

While creating a rule, it generates file which is bash script returning 1 or 0 depending if result of new and old codegen are the same (it's done by redirecting output of buck's cmd).

How js script works:
1. remove empty lines
2. remove comments
3. remove imports
4. sort lines (cause order of structs might be different so let's sort everything!)
5. remove namespaces (I grouped them in new codegen)

Reviewed By: RSNara

Differential Revision: D16827988

fbshipit-source-id: 0432144161e2dcf8ed4cbe2eeea712d062e3721d
2019-08-21 18:12:22 -07:00
Joshua Gross 11dc847ec9 Give a more explicit message about why number isn't supported
Summary: Give a more explicit message about why `number` isn't supported

Reviewed By: rickhanlonii

Differential Revision: D16926698

fbshipit-source-id: 292cb13aa11205e1350209178bde1977a2a7ad4c
2019-08-20 22:28:55 -07:00
Joshua Gross b26acae6dd Flow type and codegen RCTFbMap
Summary:
Flow type for Android-only RCTFbMap component.

ViewManager in Java here: https://our.intern.facebook.com/intern/diffusion/FBS/browse/master/fbandroid/java/com/facebook/catalyst/views/maps/ReactFbMapViewManager.java

View in Java here: https://our.intern.facebook.com/intern/diffusion/FBS/browse/master/fbandroid/java/com/facebook/catalyst/views/maps/ReactFbMapView.java

Reviewed By: TheSavior

Differential Revision: D16811331

fbshipit-source-id: 210d80143b4826fc2ffb3402066c8fd0653e6794
2019-08-20 15:51:58 -07:00
Rick Hanlon f0600e00dc Also add in converstion imports for arrays of objects
Summary: Fixes an issue where we weren't traversing all the way into object properties to find imports we may need

Reviewed By: TheSavior

Differential Revision: D16896674

fbshipit-source-id: f95a4f84e51265962ddfd2aeea9da717df033879
2019-08-19 15:24:47 -07:00
Rick Hanlon 4bf5e63138 Recursively visit all object properties to generate structs
Summary: Adds support for generating structs for object properties that are objects or arrays

Reviewed By: TheSavior

Differential Revision: D16896143

fbshipit-source-id: 6682d047e218fc774c8d0593dc2c66fe73615be7
2019-08-19 15:24:47 -07:00
Rick Hanlon 5f09a1733b Add broken fixture for objects with array props
Summary: Adds a broken fixture for arrays nested inside of objects (fixed in the next diffs)

Reviewed By: TheSavior

Differential Revision: D16896138

fbshipit-source-id: 355a71352a78ca076c1de56304908e664772c200
2019-08-19 15:24:46 -07:00
Rick Hanlon 3050ac2d2d Fix nested array object structs
Summary: Fixes some issues with generating deeply nested objects and arrays

Reviewed By: TheSavior

Differential Revision: D16858639

fbshipit-source-id: f9ca90da4fcef7f4fe795b38888c66ffef45c06b
2019-08-19 15:24:46 -07:00
Rick Hanlon 8c995a2a0d Add broken generator fixtures for nested array props
Summary: Adds a fixture for generating nested array objects (fix is on the next diff)

Reviewed By: TheSavior

Differential Revision: D16858626

fbshipit-source-id: c9543f4f8ecc073fd840edd94d47bdc911eaa69e
2019-08-19 15:24:46 -07:00
Rick Hanlon 1c67a94af9 Add new parser fixture for nested array objects
Summary: This diff adds parser fixtures for nested array objects

Reviewed By: TheSavior

Differential Revision: D16858619

fbshipit-source-id: 22ce2f4c37c62032c768e149e8a1527df52857cd
2019-08-19 15:24:45 -07:00
Eli White 0df5e5016d Cast double to float instead of .getFloat
Summary: ReadableArray doesn't have a .getFloat, so casting double to floats instead. This is consistent with how the prop conversion happens as well.

Reviewed By: makovkastar

Differential Revision: D16897600

fbshipit-source-id: e8c76558f030d291960b5790a262fa49a9f358e7
2019-08-19 11:53:27 -07:00
Eli White cddc2c6c72 Fix Java compile errors in JS-generated receiveCommand method
Summary: This diff adds a missing `switch` statement

Reviewed By: makovkastar

Differential Revision: D16892042

fbshipit-source-id: c162655445f3c0891d2377595a9389d419713bdf
2019-08-19 11:53:27 -07:00
Eli White b9899222a3 Fix naming of nested structs
Summary: The names weren't matching and c++ wasn't compiling

Reviewed By: rickhanlonii, JoshuaGross

Differential Revision: D16852438

fbshipit-source-id: 9fa72aaec4e3071232b026ff99ba632a0834d50e
2019-08-19 11:26:46 -07:00
Eli White e9ef560e87 Add fixture for nested objects
Summary: Adding this fixture in a standalone diff so it is easier to see the change on the next one.

Reviewed By: JoshuaGross

Differential Revision: D16852439

fbshipit-source-id: 3f167509b78ebb95f31e44fbf40e9551d4a5500b
2019-08-19 11:26:45 -07:00
Eli White 685a25ca2e Add recursive imports for Array types
Summary: Supporting the native primitives fixture added in the previous diff

Reviewed By: JoshuaGross

Differential Revision: D16846289

fbshipit-source-id: 4c6afdabba0fe4b55990d25adec21cf65d8beff3
2019-08-19 11:26:45 -07:00
Eli White 6ee5679582 Add Fixture for Array with Primitives
Summary: The codegen has a bug with arrays that have objects that contain native primitives. This diff adds a fixture to demonstrate that bug. I don't change any behavior in this diff. This is just to make the change in the next diff easier to read.

Reviewed By: JoshuaGross

Differential Revision: D16846290

fbshipit-source-id: 06f477b9e3b77cbc1faee11c78d031b45c094d31
2019-08-19 11:26:45 -07:00
Eli White 2d937c63e4 Add recursive types for Object types
Summary: We weren't adding the local imports recursively as well. This is a similar change as was made when creating the CppHelpers.getImports in D16759170.

Reviewed By: rickhanlonii, JoshuaGross

Differential Revision: D16840667

fbshipit-source-id: 1090a774c9e96798d5900bc0b4bf1be29b3ba090
2019-08-19 11:26:45 -07:00
Eli White 6c3b01d07f Add support for spread with ReadOnlyArray
Summary: The new support for ReadOnlyArray needs to call this new function for spreads too.

Reviewed By: JoshuaGross

Differential Revision: D16823796

fbshipit-source-id: 9de94b41cdead7ce5238c77a9e39b5daf760dfe2
2019-08-15 11:29:20 -07:00
Joshua Gross c8b9a3f8e2 Support Double in when generating props for .h files, in parsing component props, and for commands and events
Summary: I realized my previous diff was incomplete. Adding parsing and generation code for Double for props, commands, and events.

Reviewed By: rickhanlonii

Differential Revision: D16823540

fbshipit-source-id: fbed9897bb84b789c502cf4153e81060590152b8
2019-08-15 10:18:16 -07:00
Michał Osadnik 269ea48822 Split buck rules for component and modules
Summary: Split buck rules for component and modules for our further convenience

Reviewed By: rickhanlonii

Differential Revision: D16803703

fbshipit-source-id: c01fb97875b43be4020edd054cad538ec8ed6861
2019-08-15 07:54:34 -07:00
Michał Osadnik 996ea88dc3 Add error message for paring unnamed params
Summary:
We're currently not supporting this kind of params

```
+sample(string):void
````

and here's special exception for it.

Reviewed By: RSNara

Differential Revision: D16708583

fbshipit-source-id: 809f9808b77108857c8363536b896089e9cb957f
2019-08-15 07:54:34 -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 86eb4c7f62 Parse $ReadOnlyArray<$ReadOnly{}> props
Summary: Add flow type parsing for `$ReadOnlyArray<$ReadOnly<{}>>`

Reviewed By: TheSavior

Differential Revision: D16814261

fbshipit-source-id: 9442916f5d31f6d27f560332aee311b3ad8f0864
2019-08-15 06:38:15 -07:00
Rick Hanlon 243ccc541e Generate array<object> props
Summary: Adds the cxx generators for arrays of object props

Reviewed By: JoshuaGross, TheSavior

Differential Revision: D16814136

fbshipit-source-id: fa4600f60c063bfb460033f5fde43e26c04b5a3b
2019-08-15 06:38:15 -07:00
Rick Hanlon bc1c7b1096 Add array<object> props to schema
Summary: Adds arrays of objects to the codegen schema

Reviewed By: motiz88

Differential Revision: D16814117

fbshipit-source-id: 10b20446f7aac5dccc3d2cb148891a134d136d3f
2019-08-15 06:38:14 -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
Rick Hanlon 56f9eb35da Add Object props support for cxx
Summary: Adds ability to codegen object props to cxx by generating the cxx structs and conversion functions |

Reviewed By: JoshuaGross

Differential Revision: D16759170

fbshipit-source-id: 7437421e59f4be42fbcd4cddc2e0ed513ae71d08
2019-08-15 06:38:14 -07:00
Oleksandr Melnykov a206e91907 Generate super call to BaseViewManagerDelegate if delegate has no props
Summary: This diff adds a super call to `BaseViewManagerDelegate` if the current delegate doesn't have any props. We still want to set base view props, so we need `BaseViewManagerDelegate` to take care of this.

Reviewed By: rickhanlonii

Differential Revision: D16806648

fbshipit-source-id: 61963f2211cc7b2e7f5822c48bb0a7f50d909221
2019-08-15 03:27:13 -07:00
Eli White 51133235e0 Add failure tests for duplicate props with the same name
Summary: There are a couple of cases where props can conflict which would cause undefined behavior. We'll throw to protect against that. Now that we support type spread this is more possible without someone realizing.

Reviewed By: JoshuaGross

Differential Revision: D16813884

fbshipit-source-id: 1a8fce365ab315198abdff0de6006cfe34e84fb9
2019-08-14 16:11:05 -07:00
Eli White ac6c747aac Support deeply nested spreads
Summary: Apparently I missed one more edge case. Thanks Josh for flagging!

Reviewed By: JoshuaGross

Differential Revision: D16813354

fbshipit-source-id: 6b59bc7b18184e3aa437c3b038ffd22b0fc0ba6a
2019-08-14 16:11:04 -07:00
Eli White 9ae866c072 Support spreading locally defined types deeply
Summary: We want to be able to spread props at any level, not just the top level

Reviewed By: JoshuaGross

Differential Revision: D16812884

fbshipit-source-id: 2e710141f833a7cc7ea25a91a1523a5c43b4e02c
2019-08-14 16:11:04 -07:00
Eli White 0a3967480e Support spreading locally defined types
Summary: We want to be able to spread types that are defined in the same file.

Reviewed By: JoshuaGross

Differential Revision: D16812171

fbshipit-source-id: 7cda9869ea25f0357b3f8a3b28443407b219f04b
2019-08-14 16:11:04 -07:00
Joshua Gross a02176e2ec Add support for Double prop type
Summary: Support a prop-type `Double`, in addition to `Float`, for flow typing and codegen of components.

Reviewed By: TheSavior

Differential Revision: D16812812

fbshipit-source-id: b5588b3218636283a4e9c5d17212dd0b92986eb9
2019-08-14 15:33:41 -07:00
Michał Osadnik a5ea7200da Omit getConstants for codegening if object is empty
Summary: Old codegen was omitting `getConstants` if it was empty. So do our. There's no point in providing this getter in this case.

Reviewed By: RSNara

Differential Revision: D16762230

fbshipit-source-id: 721df13a00848d23108329b152115c0f0aee8eb9
2019-08-14 05:00:09 -07:00
Michał Osadnik c0304aaa9b Add setMethodArgConversionSelector
Summary: `setMethodArgConversionSelector` is method for provinding generated structs for methods' params. It was exactly how in old codegen.

Reviewed By: RSNara

Differential Revision: D16784403

fbshipit-source-id: d35bc8160be62385527299a6b8e68c1159002853
2019-08-14 05:00:09 -07:00
Michał Osadnik 40dd48c6bd Fix name of key obtaining from dictionary in inline method in generated objcpp
Summary: It was a mistake. We should obtain value by proper key always. Previously by a mistake I hardcoded 'a'. I wasn't break anything because it wasn't used in Internationalization. However, it was a bug

Reviewed By: RSNara

Differential Revision: D16782132

fbshipit-source-id: 59f7910f2be7753c07f16f00a201de856d57e29e
2019-08-14 05:00:09 -07:00
Michał Osadnik 024ce5d1d4 Change type of params in methods' protocols to nongeneric
Summary:
It was mistake which I fix here. Type of param in protocols should be generated struct.

See generated struct in snap. It's exactly how it was in previous codegen

Reviewed By: RSNara

Differential Revision: D16770579

fbshipit-source-id: dac9c15c5d91a41ab2d06aea416f64bd7deb4476
2019-08-14 05:00:08 -07:00
Michał Osadnik d3c30cdfe1 fix optional key in structs in new codegen
Summary: Property should be marked as optional not only when value is optional, but also key.

Reviewed By: RSNara

Differential Revision: D16764332

fbshipit-source-id: d56944ef263da3aa1fce3482151c761574a83be6
2019-08-14 05:00:08 -07:00
Michał Osadnik 99614497f4 Remove multiple RTCConvert import
Summary: RTCConvert was previously imported on each protocol. It was redundant. It's enough to import it once per file

Reviewed By: RSNara

Differential Revision: D16764834

fbshipit-source-id: 9e5dcd52e38dfefa675e3e2c9f2a8f414da1a02c
2019-08-14 05:00:08 -07:00
Michał Osadnik 4a9035aa65 hadle nullable params in generated objcpp
Summary: Param of function can be optional and it should have impact on native code. Inspired by old codegen

Reviewed By: RSNara

Differential Revision: D16763884

fbshipit-source-id: dab50275f902dbe4af25824bb6128d3b37fc43cd
2019-08-14 05:00:08 -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
Joshua Gross 825e1c087c Commands: support Float arguments
Summary: Support codegen'ing commands with Float arguments.

Reviewed By: mdvacca

Differential Revision: D16785534

fbshipit-source-id: 8174ae40762c1114b87a023cb2b69b2515dc6e23
2019-08-13 13:37:24 -07:00
Rick Hanlon a60e581267 Better error message for invalid type annotation
Summary: Just a minor error message improvement

Reviewed By: TheSavior, osdnk

Differential Revision: D16759233

fbshipit-source-id: c53c54535eca683353085a8d2272c60596b52b54
2019-08-12 13:52:39 -07:00
Rick Hanlon e110f0450a Add support for parsing object props
Summary:
This diff adds support to the flow parser to parse object props to the codegen schema

This handles required and optional props, as well as required and optional object properties, WithDefault, enums, etc. Basically everything is supported that is supported at the top level

Reviewed By: TheSavior, osdnk

Differential Revision: D16759198

fbshipit-source-id: 6f501f4738f84f20a940235ba74f7bae93e64eef
2019-08-12 13:52:39 -07:00
Rick Hanlon e6c1e81c60 Move generateStructName to CppHelpers
Summary: We'll need this helper in the prop files now so let's move it over to the generic cpp helpers

Reviewed By: TheSavior

Differential Revision: D16759164

fbshipit-source-id: 8765ffee3bd8219b5f0dc8677362ec45f0a8e2c5
2019-08-12 13:52:39 -07:00
Rick Hanlon ebb412ab00 Add Object props support for Java
Summary: This diff adds Java handling for object props

Reviewed By: TheSavior

Differential Revision: D16759139

fbshipit-source-id: e47956dc43cd1eb4abd58636bf111dde8d7244cc
2019-08-12 13:52:38 -07:00