Summary: Ports an internal ESLint rule used at Facebook, `error-subclass-name`, to cover the React Native codebase. This rule enforces that error classes ( = those with PascalCase names ending with `Error`) only extend other error classes, and that regular functions don't have names that could be mistaken for those of error classes.
Reviewed By: rubennorte
Differential Revision: D17829298
fbshipit-source-id: 834e457343034a0897ab394b6a2d941789953d2e
Summary:
We need to migrate to HostComponent instead of the exported type from codegenNativeComponent which is the same type
Changelog:
[Internal] Migrate NativeComponentType from codegenNativeComponent to HostComponent
Reviewed By: rickhanlonii
Differential Revision: D17563307
fbshipit-source-id: 01c8fea8c67b33bed42ae28ffb8c132be87b9a7a
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:
## Motivation
The concept behind JSCallInvoker doesn't necessarily have to apply only to the JS thread. On Android, we need to re-use this abstraction to allow execution of async method calls on the NativeModules thread.
Reviewed By: PeteTheHeat
Differential Revision: D17377313
fbshipit-source-id: 3d9075cbfce0b908d800a366947cfd16a3013d1c
Summary:
I noticed two syntax errors in code gen while using it. This fixes them.
One of them is missing semicolon, the other one is name mismatch.
Reviewed By: TheSavior
Differential Revision: D17226188
fbshipit-source-id: 880dbf4c9b22efa7754de6413d01c04e7abbe411
Summary: This diff adds support for generating native code for arrays of arrays of objects
Reviewed By: JoshuaGross, mdvacca
Differential Revision: D16936272
fbshipit-source-id: 1543f8c1d5d9d4db28e4c7841ff7184ca0e417b3
Summary:
This diff adds a fixture for supporting arrays of arrays of objects, eventually parsable as:
`$ReadOnlyArray<$ReadOnlyArray<$ReadOnly<{|foo: string|}>>`
Reviewed By: JoshuaGross, mdvacca
Differential Revision: D16936233
fbshipit-source-id: 14143522d82ad7d42e81605bb701890ca2731bed
Summary:
## Overview
This diff adds flow parser support for number unions as Int32Enums
The following will be supported as an Int32 enum:
```
interval?: WithDefault<0 | 15 | 30 | 60, 0>,
```
## Number type issues
We assume that all number enums are ints (so far there's not been a valid use case for unions of floats).
If we think there would be a use case for float unions we would need to update this to something like:
```
// Int32
intervalInt?: WithDefault<Int32Enum<0 | 15 | 30 | 60>, 0>,
// Float
intervalInt?: WithDefault<FloatEnum<0.0 | 15.1 | 30.2 | 60.3>, 0.0>,
```
My recommendation is that we default number unions to ints and if a use case arises later for floats, we would add the Float support as:
```
// Int32
intervalInt?: WithDefault<0 | 15 | 30 | 60, 0>,
// Float
intervalInt?: WithDefault<FloatEnum<0.0 | 15.1 | 30.2 | 60.3>, 0.0>,
```
Reviewed By: JoshuaGross
Differential Revision: D17161701
fbshipit-source-id: 4b016eee45bf28bf505afd14a6c1aeea6ca8c04f
Summary: This diff adds more advanced support for Int32 enums by allowing them as object properties in props
Reviewed By: JoshuaGross
Differential Revision: D17161656
fbshipit-source-id: d4377d95961554c83b60ed929f6279291c2d1104
Summary: This diff adds the snapshots for the new Int32 fixture and renames the ENUM_ fixture to STRING_ENUM
Reviewed By: JoshuaGross
Differential Revision: D17158033
fbshipit-source-id: 405b1da5ede16410434a9097ef256f99e4115533
Summary:
Adds schema to allow for Int32Enums in the codegen.
All of the non-schema updates here are flow fixes, the code there is implemented in the next diffs
Reviewed By: JoshuaGross
Differential Revision: D17158026
fbshipit-source-id: b5a6871225771c3c97a43a901d5f8e51c44f35c8
Summary:
Fix flow test case input in react-native-codegen package that has syntax errors.
Missing ";" after export type,
Missing ";" or "," after interface/object type member signature,
Missing ":" in method signature,
etc
## Changelog
[General] [Fixed] - Fix flow test case input in react-native-codegen package
Pull Request resolved: https://github.com/facebook/react-native/pull/26316
Test Plan: Parsed files using flow parser, but some test cases are intended to have syntax error, in this case I fixed unexpected ones.
Reviewed By: rickhanlonii
Differential Revision: D17194969
Pulled By: osdnk
fbshipit-source-id: 262d0af4d9e7e74f7ba3eb30c4fd9753c08f3bf7
Summary:
Our JS codegen assumes that all Android view managers extend `BaseViewManager` which allows generated delegates to set base view props using `BaseViewManagerDelegate`, see and example of the generated delegate for `FbReactTTRCStepRenderFlagManager`:
```
public class TTRCStepRenderFlagManagerDelegate<T extends View, U extends BaseViewManager<T, ? extends LayoutShadowNode> & TTRCStepRenderFlagManagerInterface<T>>{
public TTRCStepRenderFlagManagerDelegate(U viewManager) {
super(viewManager);
}
Override
public void setProperty(T view, String propName, Nullable Object value) {
switch (propName) {
case "traceId":
mViewManager.setTraceId(view, value == null ? null : (String) value);
break;
case "stepName":
mViewManager.setStepName(view, value == null ? null : (String) value);
break;
default:
super.setProperty(view, propName, value);
}
}
}
```
The problem is that `FbReactTTRCStepRenderFlagManager` doesn't extend `BaseViewManager`, but `ViewManager`, which means that we cannot use it with the generated delegate. We cannot use `ViewManager` instead of `BaseViewManager` in our JS codegen either, otherwise we will not be able to set base view props.
This diff makes it possible for delegates generated by JS to be used by Android view managers that do not extend `BaseViewManager`. By having a `BaseViewManagerInterface` we will be able to introduce a no-op base view manager implementation and wrap our original view manager in it so that we can pass as a constructor parameter to `BaseViewManagerDelegate`.
See an example of this approach for `FbReactTTRCStepRenderFlagManager`:
```
public class FbReactTTRCStepRenderFlagManager extends ViewManager<FbReactTTRCStepRenderFlag, ReactShadowNodeImpl> implements TTRCStepRenderFlagManagerInterface<FbReactTTRCStepRenderFlag> {
private final ViewManagerDelegate<FbReactTTRCStepRenderFlag> mDelegate;
public FbReactTTRCStepRenderFlagManager() {
mDelegate = new TTRCStepRenderFlagManagerDelegate<>(new ViewManagerWrapper(this));
}
...
private static class ViewManagerWrapper extends BaseViewManagerAdapter<FbReactTTRCStepRenderFlag> implements TTRCStepRenderFlagManagerInterface<FbReactTTRCStepRenderFlag> {
private final TTRCStepRenderFlagManagerInterface<FbReactTTRCStepRenderFlag> mViewManager;
private FbReactTTRCStepRenderFlagManagerAdapter(TTRCStepRenderFlagManagerInterface<FbReactTTRCStepRenderFlag> viewManager) {
mViewManager = viewManager;
}
Override
public void setTraceId(FbReactTTRCStepRenderFlag view, Nullable String traceId) {
mViewManager.setTraceId(view, traceId);
}
Override
public void setStepName(FbReactTTRCStepRenderFlag view, Nullable String stepName) {
mViewManager.setStepName(view, stepName);
}
}
}
```
Reviewed By: mdvacca
Differential Revision: D16984121
fbshipit-source-id: ea2761dda68a96ff3ba6ac64153bc4e56e396774
Summary: This diff removes the 'RCT' prefix (if it's present) from the names of the generated Java classes. The motivation is that we don't want to have any Java files having this prefix in the RN Android codebase.
Reviewed By: JoshuaGross
Differential Revision: D17123804
fbshipit-source-id: 31905d3141e0f58ea47cdbdb0cf77d2d105de9a9
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: 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
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
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
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
Summary: This catches some errors about hooks being used at the top level in a module
Reviewed By: gaearon
Differential Revision: D16945591
fbshipit-source-id: 116ed24b4394b1f516a2ebcd75977d2ba5c57afb
Summary:
Updates the babel parser to support exports that include flow types
Changelog:
[Internal]
Reviewed By: cpojer
Differential Revision: D16927086
fbshipit-source-id: 526efd911c2492a67f618d2d8ad199a7a5a235ff
Summary: Give a more explicit message about why `number` isn't supported
Reviewed By: rickhanlonii
Differential Revision: D16926698
fbshipit-source-id: 292cb13aa11205e1350209178bde1977a2a7ad4c
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
Summary: Adds support for generating structs for object properties that are objects or arrays
Reviewed By: TheSavior
Differential Revision: D16896143
fbshipit-source-id: 6682d047e218fc774c8d0593dc2c66fe73615be7
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
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
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
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
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
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
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
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