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

1384 Коммитов

Автор SHA1 Сообщение Дата
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
Rick Hanlon 6874bade43 Add parser support for number unions as Int32 enums
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
2019-09-06 05:33:08 -07:00
Rick Hanlon e352edebeb Add support for int enum object properties
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
2019-09-06 05:33:07 -07:00
Rick Hanlon f4c6868fc2 Add basic support for Int32Enum in generators
Summary: This diff adds basic (non-object) support for generating Int32 enums

Reviewed By: JoshuaGross

Differential Revision: D17161643

fbshipit-source-id: d91fe70e6086930629c505fb1dab1f6b8555c936
2019-09-06 05:33:07 -07:00
Rick Hanlon c58106344e Update unrelated Int32Enum snapshots
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
2019-09-06 05:33:07 -07:00
Rick Hanlon e906c6f78f Add Int32EnumTypeAnnotation to codegen schema
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
2019-09-06 05:33:07 -07:00
Zihan Chen (MSFT) d63c46de7e Fix flow test case input in react-native-codegen package that has syntax errors. (#26316)
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
2019-09-04 17:23:26 -07:00
Oleksandr Melnykov d38afb4a9d Use interface instead of abstract class to reference view manager in generated delegate
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
2019-09-04 07:04:08 -07:00
Oleksandr Melnykov 26a8d2e03a Remove RCT prefix from names of generated Java classes
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
2019-08-30 10:03:27 -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
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
Eli White 2dbf42b4a3 Bump eslint-plugin-react-hooks to 2.0.1
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
2019-08-21 18:08:26 -07:00
Rick Hanlon 869ddd701b Add support for type exports to babel parser
Summary:
Updates the babel parser to support exports that include flow types

Changelog:
[Internal]

Reviewed By: cpojer

Differential Revision: D16927086

fbshipit-source-id: 526efd911c2492a67f618d2d8ad199a7a5a235ff
2019-08-21 12:58:52 -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
Rick Hanlon 50b821df49 Add view config support for Object props
Summary: This diff adds handling for object prop types in the view config codegen

Reviewed By: TheSavior

Differential Revision: D16759136

fbshipit-source-id: ff4020f9cffe30f14a1356ac95afd7c9a1062c05
2019-08-12 13:52:38 -07:00
Rick Hanlon 76b8b1dc8b Add object prop tests for unchanged fixtures
Summary:
This diff adds snapshot updates for the new object props test fixtures whose implementation does not need to change (e.g. event emitter files will not change when object props are implemented). This is for easier reviewability in later diffs.

Notes that in the files that will change, we're temporarily filtering the OBJECT_PROPS test fixture

Reviewed By: TheSavior

Differential Revision: D16759124

fbshipit-source-id: 8aae063614f762c8bd7bf092b0d274804c38dd14
2019-08-12 13:52:38 -07:00
Rick Hanlon 06259a7575 Add Object type to schema
Summary: This diff adds ObjectTypeAnnotation to the codegen schema, throwing for the missing implementation sites added in the next diffs for easier review-ability. Also adds a schema fixture that is flow checked for review, but does not export it because the tests would fail

Reviewed By: TheSavior

Differential Revision: D16759109

fbshipit-source-id: 75c93623e8c1ae2003c7cc638e8e3447f0e7aa38
2019-08-12 13:52:37 -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
Logan Daniels 91f139b941 xplat/js/react-native-github
Reviewed By: panagosg7

Differential Revision: D16657770

fbshipit-source-id: 4e260842c838a35317515044c54ccf55a083da33
2019-08-09 10:11:15 -07:00
Logan Daniels 9127fb51fc Manual fixes for xplat/js/react-native-github
Summary:
Need to add explicit type annotations in these areas to unblock types-first architecture for Flow. These are locations the codemod could not automatically handle.

I'll call out areas I need a close eye on in the comments.

Reviewed By: panagosg7

Differential Revision: D16659053

fbshipit-source-id: 167dd2abe093019b128676426374c1c62cf71e7f
2019-08-09 10:11:15 -07:00
Kant d2b92fffb1 Use eslint-plugin-prettier recommended config (#25674)
Summary:
I created a new test project today using RN 0.60.3 and saw that prettier is now used with eslint. After looking at the `react-native-community` eslint config, I notice that it wasn't using the [recommended configuration](https://github.com/prettier/eslint-plugin-prettier#recommended-configuration) of `eslint-plugin-prettier`

This PR adds the `eslint-config-prettier` to avoid conflicts between eslint and prettier, it also adds the `prettier/react` config to avoid problems with the `eslint-plugin-react`.

## Changelog

[General] [Changed] - Use eslint-plugin-prettier recommended config
Pull Request resolved: https://github.com/facebook/react-native/pull/25674

Test Plan: -  Ensure there is no difference on this repo (no ESLint errors, same number of warnings, and no changes when running prettier).

Differential Revision: D16666178

Pulled By: cpojer

fbshipit-source-id: 70f81db793866acc88388b7b00a496aab5e0b156
2019-08-09 06:41:41 -07:00
Rick Hanlon 2e32b8c497 Update regex used to check for codegenNativeComponent
Summary: Updates regex to allow for type casts

Reviewed By: TheSavior

Differential Revision: D16717249

fbshipit-source-id: f22561d5cd33ab129fc0af4490692344726d7d71
2019-08-08 18:50:15 -07:00
Michał Osadnik 0dcd57c73c Fix veryfying exports in module codegen
Summary:
If was breaking in cases like
```
export { x as default }
```

Reviewed By: RSNara

Differential Revision: D16689606

fbshipit-source-id: 2583c73c5ac06ea0fa8666d219e739e68fc75b12
2019-08-08 11:18:08 -07:00
Michał Osadnik 28e668e56e Add pointer to generated id<NSObject>
Summary: It should always be a pointer, sorry!

Reviewed By: RSNara

Differential Revision: D16689608

fbshipit-source-id: f67d2606b5bdc169d312c1c75748c390ee5e56ed
2019-08-08 11:18:08 -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 52c86a96b8 fallback not understandable types from methods to object
Summary:
We don't want to make our codegen breaking if type is not existing. In order to it we can always fallback to Object. That's how it currently works in old codegen

#Facebook
Thare're few places in our internal code where we use `Map` or tuple in these cases

Reviewed By: RSNara

Differential Revision: D16687360

fbshipit-source-id: bf8aafd3254fc7e18ad0d58ad1a29e2beeb15bf0
2019-08-08 11:18:07 -07:00
Michał Osadnik 35f81f62c2 Add handling of nullable return value
Summary: Retuned value can be nullable and it need to be handled

Reviewed By: RSNara

Differential Revision: D16687359

fbshipit-source-id: 7869c4e2b1da69b680b6eade3c88e0558077b705
2019-08-08 11:18:07 -07:00
Michał Osadnik b5b6d1d69f Minor improvements in native modules codegens
Summary: Add handling of `$ReadOnly`, $ReadOnlyArray`. Drop handling of params for callback (does not impact native generated node) and promises' types (does not impact native generated node). Remove typo from native codegen.

Reviewed By: RSNara

Differential Revision: D16686886

fbshipit-source-id: 26345978bbbba0cee14d00e7b5b9e5017c89a46c
2019-08-08 11:18:07 -07:00
Rick Hanlon 9b1465b74f Add support for casting codegenNativeComponent
Summary: Adds support for casting the codegenNativeComponent export

Reviewed By: TheSavior

Differential Revision: D16676207

fbshipit-source-id: 5e874bd5a72eb7e67e05b0f671856ae3319a335e
2019-08-08 09:22:08 -07:00
Kevin Gozali 57fe1f4b82 Commands codegen: added RCT prefix for protocols, extern C functions, and file names
Summary:
This will provide consistency with the rest of ObjC/ObjC++ files throughout RN codebase, which is also part of the iOS engineering practice to have a prefix.

Highlights:
* This only affects the `protocol` and extern C functions, and the .h output file name
* Other C++ only file/classes are not affected
* The assumption is that the RCT prefix is only for iOS specific files/names. The JS component name should **NOT** have any prefix in the long term (some of them still have RCT prefix in the name, which was an artifact of legacy inconsistency).
  * The RCT prefix is not relevant to Java/JNI code, since they have their own convention

Reviewed By: TheSavior, mdvacca

Differential Revision: D16661286

fbshipit-source-id: b8dd75fa7f176d6658183f225b27db017b4b55e7
2019-08-08 08:00:49 -07:00
Rodinei Fagundes 76af5f9163 Add ErrorUtils to global variables (#25947)
Summary:
ErrorUtils is giving an error by eslint. ('ErrorUtils is not defined').

## Changelog
[General] [Fixed] - Add ErrorUtils to eslint globals
Pull Request resolved: https://github.com/facebook/react-native/pull/25947

Test Plan: Run eslint on a react native project using ErrorUtils. Eslint verification should pass.

Differential Revision: D16666163

Pulled By: cpojer

fbshipit-source-id: c20c4e21fe06c6863dcfc167d6d03c6217ae1235
2019-08-06 03:49:20 -07:00
Eli White 7c0b73501e Update commands transform to use helper
Summary:
This uses a new helper called `dispatchCommand` that now exists on the renderer. This was added to the renderer here: https://github.com/facebook/react/pull/16085

In Paper it calls UIManager.dispatchViewManagerCommand and in Fabric it calls the c++ Fabric UIManager

Reviewed By: rickhanlonii

Differential Revision: D16578708

fbshipit-source-id: 30f9468a7fd48afb506c0ee49a460b949bc863a1
2019-08-02 16:55:31 -07:00
Eli White 9bc77fadb6 Give better error message for nullable refs
Summary: This gives a better error message when people use nullable refs for the flow type.

Reviewed By: mdvacca

Differential Revision: D16627409

fbshipit-source-id: 9ab1533b41a5a21e7557c0836feefff680e8018c
2019-08-02 13:54:45 -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 6bb41d18a4 Add handling of optionals for generating constants structs
Summary: In this diff I add handling optional values in constants object. Behaviour is slightly different when it comes to string, objects etc., so I add tests for every of these cases.

Reviewed By: RSNara

Differential Revision: D16599254

fbshipit-source-id: 380c5235fefeb70a521733369011e0051e18859a
2019-08-02 07:24:31 -07:00
Eli White b526f66c19 Back out "Back out "[RNCodegen] codegenNativeCommands takes list of supported commands""
Summary:
Original commit changeset: 34a8f8395ca7

The problem with the original commit was the usage of optional chaining. This diff removes the usage of optional chaining with good old fashioned null checks.

Reviewed By: rickhanlonii

Differential Revision: D16593623

fbshipit-source-id: d24cc40c85de9a2e712e5de19e9deb196003ccf2
2019-08-01 15:05:57 -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
Joshua Gross 678d5f7cd1 Back out "[RNCodegen] codegenNativeCommands takes list of supported commands"
Summary: Original commit changeset: 189754a567a3

Reviewed By: rickhanlonii

Differential Revision: D16586885

fbshipit-source-id: 34a8f8395ca73e190ccf0242f02626094f6d87b6
2019-07-31 14:11:06 -07:00
Eli White d6d71810f9 Update ComponentDescriptorH to test all fixtures
Summary: This test didn't get updated to run over all the fixtures like the others

Reviewed By: JoshuaGross

Differential Revision: D16501494

fbshipit-source-id: 4a68d60819701a9de7f1da22a66ccf807cc4490f
2019-07-30 23:59:51 -07:00
Eli White f161583713 codegenNativeCommands takes list of supported commands
Summary:
We want to enable codegenNativeCommands to have a runtime fallback that will work if the babel transform is not enabled. For example, in open source until we turn it on everywhere. By listing the supported commands, we can create the necessary functions at runtime to support what we need.

A follow up diff will add that runtime behavior to codegenNativeCommands.

Reviewed By: JoshuaGross

Differential Revision: D16573450

fbshipit-source-id: 189754a567a3a5ccd34629a8dfedf808e6824e82
2019-07-30 20:28:26 -07:00
Eli White b5f7b42f06 Commands JS output, fix UIManager method name
Summary: This name was incorrect and didn't exist

Reviewed By: JoshuaGross

Differential Revision: D16528973

fbshipit-source-id: 92b874a2b023ff89ddc4312477ab8c91c0ef2cf6
2019-07-30 14:37:06 -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
Eli White 0314305e12 Support string command arguments
Summary: Support command arguments that are strings

Reviewed By: JoshuaGross

Differential Revision: D16509728

fbshipit-source-id: 003aba66231d204071d043c01cb0781150d0edb9
2019-07-29 14:41:32 -07:00
Eli White a174647698 Change fixture
Summary: I want a fixture with all the types, so refactoring this so future diffs in the stack are cleaner

Reviewed By: JoshuaGross

Differential Revision: D16509803

fbshipit-source-id: 1f4873701a8ff842f50976377003e1abff187278
2019-07-29 14:41:32 -07:00
Eli White 88641f850a Generate objc handler for commands
Summary:
These functions will be called by components like this:
```
- (void)handleCommand:(NSString const *)commandName args:(NSArray const *)args
{
  ViewNativeComponentHandleCommand(self, commandName, args);
}
```

Codegen currently supports commands with ints and bools as arguments. Will add more types in follow up diffs.

Reviewed By: JoshuaGross

Differential Revision: D16509123

fbshipit-source-id: c3071ce3b5da215bb8747216e57026a69a89eff0
2019-07-29 14:41:31 -07:00
Eli White 47365da367 Generate ObjC component protocols
Summary: We will be generating protocols for every component even if there are no commands. This is for consistency and our ability to add to them later without changing every native component that doesn't currently have a command. JoshuaGross and I figure this is okay as it appears that empty protocols are very cheap on app size

Reviewed By: zackargyle, JoshuaGross

Differential Revision: D16503773

fbshipit-source-id: 11b78fcd33b68926def909d3ce42f58b9bbee96a
2019-07-29 14:41:31 -07:00
Oleksandr Melnykov 6f4c4b59d1 Include only Java classes in zip archive of generated files
Summary:
Changelog:
[General] [Changed] - Include only Java classes in zip archive of generated files for JS codegen

This diff adds one more Buck rule to copy only Java files to a temporary dir, so that the zip_rule will only package the Java classes and skip C++ files. It makes the generated code more organized and decreases the time to create the ZIP-archive.

Reviewed By: rickhanlonii

Differential Revision: D16540781

fbshipit-source-id: cbc99b5fe28b6af5375a88652cefb30e672ed527
2019-07-29 06:32:14 -07:00
Michał Osadnik 4a969180df Add codegening constants structs
Summary: In this this diff I follow with codegening constants structs.

Reviewed By: RSNara

Differential Revision: D16496128

fbshipit-source-id: e4140d97b378985502911b8dcd1723f153dabf00
2019-07-26 10:44:57 -07:00
Michał Osadnik fe5b17977d Generate inlines and structs for methods (not constants)
Summary: Generate objcpp inlines and struct part not methods (not getConstants!)

Reviewed By: RSNara

Differential Revision: D16494709

fbshipit-source-id: 44ecf6be5031112bf47c44392e375709622ae83b
2019-07-26 10:44:57 -07:00
Jacob Lee e78c01375a Allow jest globals in __mocks__ directories (#25738)
Summary:
The `__mocks__` directories should be treated the same as `__tests__`
for the purpose of linting. See https://jestjs.io/docs/en/manual-mocks

## Changelog

[Internal] [Changed] - eslint: allow jest globals in `__mocks__` directories
Pull Request resolved: https://github.com/facebook/react-native/pull/25738

Test Plan:
I installed the updated package locally in my project and verified
that the `no-undef` rule no longer fires for references to `jest` in
`__mocks__` directories.

Differential Revision: D16515546

Pulled By: osdnk

fbshipit-source-id: ae78b95d33d1b48ffa4aafa7a53c83e152d176b2
2019-07-26 03:37:29 -07:00
Eli White a24a9b9946 Back out "Back out D16434402, D16434634"
Summary: Reverting the revert and fixing the snapshot tests

Reviewed By: JoshuaGross

Differential Revision: D16467242

fbshipit-source-id: 23ed4122da226ea815d3766098da4400e7ad9442
2019-07-24 16:50:13 -07:00
Jason Carreiro 136dde359c Back out D16434402, D16434634
Summary: build-break

fbshipit-source-id: d0786ba78689113be543535bd117c3d7f1de9996
2019-07-24 13:57:46 -07:00
Eli White fbd5dee1e4 Fix commands with no args
Summary: Fixing a typo

Reviewed By: JoshuaGross

Differential Revision: D16434634

fbshipit-source-id: 72a6b698bcd0ba9c10dfbdf264011e0a31ea06b6
2019-07-24 12:45:16 -07:00
Eli White 4eca2e226c Add receiveCommand to the Java Delegate
Summary: Adding support for receiving commands and calling methods defined on the interface in c7ee38149d

Reviewed By: JoshuaGross

Differential Revision: D16434402

fbshipit-source-id: a539050a1a2b2a67f9ba7145ed789de700461589
2019-07-24 12:45:15 -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
Rick Hanlon ac21f04532 Add @Nullable for Java props
Summary: Adds Nullable for object in the java props codegen

Reviewed By: JoshuaGross

Differential Revision: D16418332

fbshipit-source-id: f698eea3d1f920429488d4988068db7e18f5e3cb
2019-07-24 10:36:24 -07:00
Rick Hanlon df0d6e28e5 Add default prop handling
Summary: Adds handling for default props for java props

Reviewed By: JoshuaGross

Differential Revision: D16417825

fbshipit-source-id: 00ad2ace33409e9c204de16970ff0b7f756fda71
2019-07-24 10:36:24 -07:00
Rick Hanlon 34505dba05 Update Java prop casting
Summary: Updates the casting for Java props

Reviewed By: JoshuaGross

Differential Revision: D16417805

fbshipit-source-id: 7881ff984527555a4905b62d83751ed2a43b1070
2019-07-24 10:36:24 -07:00
Rick Hanlon 58d3cb2fff Remove switch statement if there are no props
Summary: Don't generate the switch statement if there are no props

Reviewed By: JoshuaGross

Differential Revision: D16417803

fbshipit-source-id: 87eda785c836f5e406e27d3c2990ec7f69422bdb
2019-07-24 10:36:23 -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
Michał Osadnik 451171acb1 generate bindings for objcpp TM
Summary: In this diff I add generetion of bindings for objcpp TM.

Reviewed By: RSNara

Differential Revision: D16438572

fbshipit-source-id: e92163b1b42306eec931e465b89b176f0fd8a658
2019-07-24 08:33:56 -07:00
Michał Osadnik 69888b0820 Add generating of objcpp headers
Summary: In this diff I add generator for Objcpp headers

Reviewed By: RSNara

Differential Revision: D16438346

fbshipit-source-id: 63a632d4bf40811a8838f3dcd2a92b2f7cf3ce3a
2019-07-24 08:33:56 -07:00
Michał Osadnik 05d3e86244 update name of generated module
Summary: Because of namespace conflicts I add `Cxx` suffix for generated names of modules.

Reviewed By: RSNara

Differential Revision: D16437997

fbshipit-source-id: ef9dbf1a5df9658365546be13f902d2fce5b57d7
2019-07-23 15:19:00 -07:00
Min ho Kim 84f5ebe4f9 Fix typos (#25770)
Summary:
Fix typos mostly in comments and some string literals.

## Changelog

[General] [Fixed] - Fix typos
Pull Request resolved: https://github.com/facebook/react-native/pull/25770

Differential Revision: D16437857

Pulled By: cpojer

fbshipit-source-id: ffeb4d6b175e341381352091134f7c97d78c679f
2019-07-23 03:23:11 -07:00
Eli White c7ee38149d Add command methods to GeneratePropsJavaInterface
Summary: These methods will be called when commands are dispatched.

Reviewed By: JoshuaGross

Differential Revision: D16388806

fbshipit-source-id: a09d257474aa3306b99f8dcdfdd23808f60eb4bd
2019-07-22 12:52:58 -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
Rick Hanlon 9a546f5e9e Add GeneratePropsJavaDelegate
Summary: Add GeneratePropsJavaDelegate to the OSS Java codegen

Reviewed By: makovkastar

Differential Revision: D16281330

fbshipit-source-id: 44ffd5757663b68f84dbefcab70b4ca5282d28ba
2019-07-19 15:04:06 -07:00
Rick Hanlon 9830d0d7b7 Add GeneratePropsJavaInterface
Summary: Adds GeneratePropsJavaInterface to the codegen to init open sourcing the Java codegen

Reviewed By: mdvacca, makovkastar

Differential Revision: D16280966

fbshipit-source-id: e3428285562329a22c1710cc7347c31f7c01d9c0
2019-07-19 15:04:05 -07:00
Michał Osadnik 247fc6774f Accept all types for objects' and arrays' elements
Summary:
Previously we accepted only very limited set of types for schema parser. However, in many cases we want to provide more specific typings e.g. accept enum or touple.

Currently, we don't take any advantages for codegen from specifying type of elements for object or array. All of them fallback to the same cpp code.

That's why I decided not to throw exception if types of arrays' and objects' elements are different than currently supported. Then I want to fallback to `undefined`.

Reviewed By: rickhanlonii

Differential Revision: D16325028

fbshipit-source-id: 3d7990ca0207c31f0ed522e7316a9cb17b6b1bcb
2019-07-17 06:21:51 -07:00
Michał Osadnik a70a8d0e75 Add support for stringish in codegen for modules
Summary: Currently codegen for components supposts stringish. I add it also for components. It fallbacks to StringTypeAnnotation (like in codegen for components).

Reviewed By: rickhanlonii

Differential Revision: D16284381

fbshipit-source-id: 8f03cb79d7e2e1dabbdf4f9353d18dd1daf739fd
2019-07-17 06:21:50 -07:00
Michał Osadnik d1931344b0 Fix support for objects' types defined in file
Summary: By my mistake previosly it was not poossible to return object defined somewhere in file or return promise containing that object. I changed it to consider value which might be takes from `types` object.

Reviewed By: rickhanlonii

Differential Revision: D16283800

fbshipit-source-id: e9b0ad85b921022732ea0a11db9b58115e87aaa5
2019-07-17 06:21:49 -07:00
Michał Osadnik ae840287e6 Temporarily get rid of not nullable boolean and number checks
Summary: NativeUIManager and NativeAnimatedModule are using nullable args. I believe we may teporarly don't care about that

Reviewed By: RSNara

Differential Revision: D16282683

fbshipit-source-id: 8071a9446c0e1e437391db17c16f82e131094c81
2019-07-17 06:21:48 -07:00
Michał Osadnik b4ac9ddcd5 Allow key of objects to be nullable
Summary: In this diff I handle the case where the key of an object may be nullable. To do that, I added a nullable param to the schema.

Reviewed By: rickhanlonii

Differential Revision: D16282081

fbshipit-source-id: cb7668d754e2ff30aef22df582351a512c988016
2019-07-17 06:21:48 -07:00
Michał Osadnik 6e73304401 Follow up e2e testing mechanism with real tests (#25680)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/25680

This diff's adding real e2e tests for skeleton added in previous diff.

It verifies many cases for codegen, which should generate cpp code.

Reviewed By: rickhanlonii

Differential Revision: D16279810

fbshipit-source-id: 4441dd0ed4d95476e4071fbd654ebfb8a47ecbfc
2019-07-17 06:21:48 -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
Michał Osadnik f7695e0183 Harden the Flow parser to handle more AST formats for commands and props
Summary:
This diff allows for parsing more flexible AST format.

Reusing logic used for methods, I add similar support for props and commands in components. Now it's possible to define separated type for props and commands in another part of the file.

Also, extracted this method to another file for reusing purposes.

Added tests.

Reviewed By: rickhanlonii

Differential Revision: D16221445

fbshipit-source-id: 21553bf5ade66588dd7dc0320d25333260b0ada9
2019-07-16 07:32:35 -07:00
Eli White c38d6f26e0 Remove existing Commands export
Reviewed By: rickhanlonii

Differential Revision: D16039151

fbshipit-source-id: f307697ad44f2ce1471144fc7fd0c38eb5f6c34f
2019-07-15 16:54:55 -07:00
Michał Osadnik c20eaa5ae9 Change module parser to consider extends instead of default exports
Summary:
Following out internal communication we decided to change logic of current parser to consider types which extend 'TurboModule' instead of looking at default exports.
It also cassed for minor changes in testing logic and updating snapshots.

Reviewed By: rickhanlonii

Differential Revision: D16205707

fbshipit-source-id: c75cd4febf773ba5101e6b60ed1a921773246009
2019-07-12 02:15:29 -07:00
Michał Osadnik 96318e438f Split component generator and module generator into separated dirs
Summary: Code generators for modules and components don't have a lot of in common so there's no point to keepo them in the same directory and mix their files.

Reviewed By: rickhanlonii

Differential Revision: D16183434

fbshipit-source-id: b6ee32c6b223e8d6e4bc843b2e111598bee94dc5
2019-07-11 12:58:10 -07:00
Michał Osadnik 2bc6e28d17 Add generating Cpp from schema json
Summary:
Add generating cpp files following NativeModuleSpec.

We still need to figure out how to deal with module names, so I currently made in workable by extracting `Sample` from `SampleNativeModule` and filing into proper places, but it's a temporary solution.

Reviewed By: rickhanlonii

Differential Revision: D16181292

fbshipit-source-id: 0f50352d7610f99f0228045ae78309383d3e8bfa
2019-07-11 12:58:10 -07:00
Michał Osadnik 859deb97f6 Add generating header from schem json
Summary:
Add basic Native Module header generator

We still need to figure out how to deal with module names, so I currently made in workable by extracting `Sample` from `SampleNativeModule` and filing into proper places, but it's a temporary solution.

Reviewed By: rickhanlonii

Differential Revision: D16180561

fbshipit-source-id: bb27592d565ae439707d781fb2650f2bdb140146
2019-07-11 12:58:10 -07:00
Michał Osadnik 58e61f4b6f Add skeleton for cpp module generation
Summary: I this diff I include basic codegen skeleton. It does not work yet, but I'd like to consider it as kind of playgroud for further changes. I have splited tests for component generation from test for module generation.

Reviewed By: rickhanlonii

Differential Revision: D16161909

fbshipit-source-id: a0ecb81898810fe6aa09f76238c433894c731b73
2019-07-11 12:58:09 -07:00
Ben Cheng f83f611f56 Revert D16200939: [codegen] Change module parser to consider extends instead of default exports
Differential Revision:
D16200939

Original commit changeset: a21cbfc46164

fbshipit-source-id: a551d5a9dbc7eef5c67b725e59d712fb323bd01e
2019-07-11 10:05:16 -07:00
Michał Osadnik cbd4ad43c0 Change module parser to consider extends instead of default exports
Summary:
Following out internal communication we decided to change logic of current parser to consider types which extend 'TurboModule' instead of looking at default exports.

It also cassed for minor changes i n testing logic and updating snapshots.

Reviewed By: rickhanlonii

Differential Revision: D16200939

fbshipit-source-id: a21cbfc461647df2b9210c0eca4c2c95c285dfe1
2019-07-11 09:30:52 -07:00
Michał Osadnik 4d50f5f4b8 Add support for Float and Int32 in flow parser
Summary: Int32 and Float can be represented on native site in a different after cpp code generation. Inspired by component codegen.

Reviewed By: rickhanlonii

Differential Revision: D16201358

fbshipit-source-id: a5c6c449d69f162ad9cd2a998d57e9c65bc17706
2019-07-11 08:43:19 -07:00
Michał Osadnik 0b5aa39671 Minor fixes in Flow parser
Summary:
This diff includes minor codestyle changes.
All these fixes was discussed with Rick.

Reviewed By: rickhanlonii

Differential Revision: D16169332

fbshipit-source-id: e561e2f2b116b6fdf8434c3dfc20c3e610d7ecad
2019-07-10 06:47:18 -07:00
Michał Osadnik dc52f8c2e6 Force property to be optional if value has WithDefault
Summary: It's pointless to handle non optional key if value has withDefaul so I'm adding a rule into parser preventing from such cases

Reviewed By: lunaleaps

Differential Revision: D16166709

fbshipit-source-id: 38cef522b217917a3a4886d857720932f2ebb475
2019-07-09 14:44:43 -07:00
Michał Osadnik a269c1f6c2 Add support for callback
Summary: This part of writing codegen was straightforward. I've added check for 'FunctionTypeAnnotation' and then reuse exisiting methods' parser for generating schema for callback.

Reviewed By: TheSavior

Differential Revision: D16131213

fbshipit-source-id: 2ec0e241f2174dee3a93857563db0626013d004e
2019-07-08 09:40:21 -07:00
Michał Osadnik a7664dbaf1 Add support for nullable params
Summary:
I'm not very confident with this part, but actually in existing codegen we wrap param into another object marked as `NullableTypeAnnotion`. It makes logic a little  more complicated. Also it allows for multiple `?` before type which is useless in code generation as well as nullable types inside arrays which also does not have impact on a final code generation.
I suggest adding `nullable` field into param which covers all existing cases (and probably all cases needed).

Reviewed By: TheSavior

Differential Revision: D16121609

fbshipit-source-id: 6e086d4d26bbd0aab3015ec7ecae106ebbaa5a2c
2019-07-08 09:40:21 -07:00
Michał Osadnik 233c64c675 Add support for complex objects
Summary: Add support for Object reusing mostly the code for arrays

Reviewed By: TheSavior

Differential Revision: D16122314

fbshipit-source-id: c1b201c659e6fdc98bed553fb16280ed5ce9e647
2019-07-08 09:40:20 -07:00
Michał Osadnik 702489caa8 Add support for basic objects
Summary: This implementation is a bit different than current one since previously object annotation was always wrapped into `GenericTypeAnnotation` object which is not needed in every of current use cases.

Reviewed By: TheSavior

Differential Revision: D16121727

fbshipit-source-id: e0de1852e13c66f459efd7a3bcde449e412d8b95
2019-07-08 09:40:20 -07:00
Michał Osadnik b848af3b08 Add support for optional methods
Summary:
This diff adds an optional property.

#Facebook
Following this doc: https://our.intern.facebook.com/intern/wiki/React_Native/rctexport-interface-support/?vitals_event=wiki_click_navigation_link
I suppose it's vital to support this property as well. However i don't know if it's really useful, so thus I made a separated diff for it.

Reviewed By: TheSavior

Differential Revision: D16121408

fbshipit-source-id: 15491575e999ee4fcddfd176f52d927789458061
2019-07-08 06:24:19 -07:00
Michał Osadnik 929c5d7c10 Add support for promises
Summary:
This diff add support for promises. It wraps promise's type into a special type annotation.

#Facebook
Currently the shape of promises parsing is:

```
{
  name: 'getValueWithPromise',
  optional: false,
  typeAnnotation: {
    type: 'FunctionTypeAnnotation',
    params: [
      {
        name: 'error',
        typeAnnotation: {
          type: 'BooleanTypeAnnotation',
        },
      },
    ],
    returnTypeAnnotation: {
      type: 'GenericTypeAnnotation',
      typeId: {
        hasteModuleName: 'NativeSampleTurboModule',
        name: 'Promise',
      },
      typeParameters: [
        {
          type: 'StringTypeAnnotation',
        },
      ],
    },
    returnTypeNameOverride: null,
  },
  rawTypeAnnotation: '(error: boolean) => Promise<string>',
  documentation: null,
};

```

which is a bit unclear for me. I suggest sth way more easier:

```
{
  "modules": {
    "SampleTurboModule": {
      "nativeModules": {
        "SampleTurboModule": {
          "properties": [
            {
              "name": "getValueWithPromise",
              "typeAnnotation": {
                "type": "FunctionTypeAnnotation",
                "returnTypeAnnotation": {
                  "type": "PromiseTypeAnnotation",
                  "resolvingType": {
                    "type": "StringTypeAnnotation"
                  }
                },
                "params": [
                  {
                    "name": "error",
                    "typeAnnotation": {
                      "type": "BooleanTypeAnnotation"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }
  }
}
```

However, I'd be happy to see some feedback / other solutions as well!

Reviewed By: TheSavior

Differential Revision: D16130941

fbshipit-source-id: c7dfd3f260b7c3028ce0e6208e96c62bd099ca7b
2019-07-08 06:13:05 -07:00
Michał Osadnik 690bcdf45e Add suport for array as a param and returning value
Summary: Now `Array<T>` is supported as a returning values or a param of function's definition. Also, Array of Array is allowed.

Reviewed By: TheSavior

Differential Revision: D16121246

fbshipit-source-id: 59c484120c4025a152e3ba8044eecf11dbbea1f7
2019-07-08 04:54:04 -07:00
Samuel Susla db17e969fa codegen: fix array of enums generation
Summary: While working on D16090949 I discovered that the code being generated for an array of enums was not correctly converted to mask. The type that holds the mask can't be enum class but other container type, I used `uint32_t`.

Reviewed By: shergin

Differential Revision: D16109338

fbshipit-source-id: 237077adaafe631eda973bc76cefa49035bbcd66
2019-07-08 03:56:31 -07:00
Michał Osadnik 59b8ee86c8 Prepare generic mechanism for extracting types from external type definitions
Summary: This diff a adds generic mechansm for extracting types from types' difinitions defined in other part of the file.

Reviewed By: TheSavior

Differential Revision: D16131742

fbshipit-source-id: 006b6980fa9f6a064d5bb8734ba2740b802b6989
2019-07-08 03:23:20 -07:00
Michał Osadnik e8c5495961 Add support for primitive returning type
Summary:
In this I add support for primitive types as return
- String
- Number
- Boolean
- Any
- Void

Reviewed By: TheSavior

Differential Revision: D16108273

fbshipit-source-id: 2dbd1d5a852a8cf5baf378a73d860492fe2f87cb
2019-07-05 13:15:54 -07:00
Michał Osadnik 3a5bdc17bb Add support for primitive types parsing for params
Summary:
In this diff I add handling basic primitives:
- Bool
- Number
- String

as params basing on prev schema.

Also, added flow types.

Reviewed By: TheSavior

Differential Revision: D16107737

fbshipit-source-id: 82b1534667e5cfe5b91a3306fdb6d0db44cd3a62
2019-07-05 13:15:53 -07:00
Michał Osadnik 11ff5670a9 Prepare a skeleton for native modules schema json generating
Summary: It's a skeleton for preparing schema json from native modules. Right not it does nothing, but it should considered as a kind of workplace for further work

Reviewed By: TheSavior, cpojer, RSNara

Differential Revision: D16107216

fbshipit-source-id: 12717d015e7409d980ef16cccd81330fa978b0b1
2019-07-04 05:41:16 -07:00
Michał Osadnik 61e95e5cbf Force WithDefault not to be an optional value
Summary:
`WithDefault` appears not to be required to be prefixed with `?` because it's option value per se.

Fixed tests, removed `?` where needed, updated snapshots and review them. Added mechanism fro throwing error when `?WithDefault` found. Add tests for it.

Reviewed By: rubennorte

Differential Revision: D16048463

fbshipit-source-id: f55ed7454aacf0b8c42944a9b5c1037ad1b360fe
2019-07-02 03:30:55 -07:00
Michał Osadnik 75d01075d4 Allow primitivies without default values
Summary:
It's not needed to keep required providing default values even if they are not actually relevant.

Here I add a support for `null`, `0` of `false` instead by default and remove throwing errors if no other default value provided.

Reviewed By: rubennorte

Differential Revision: D16049047

fbshipit-source-id: bc4961af3873190568f2753fc4ec975354896df5
2019-07-01 07:51:25 -07:00
Michał Osadnik 0f83dfab8e Transform BubbleEvent and DirectEvent into DirectEventHandler and BubblingEventHandler
Summary:
It appears that `(e: BubblingEvent<T>) = mixed` exists only in given context and it's pointless to keep in this way. It could be simplified to `BubblingEventHandler<T>` without any negative consequences and that's the motivation of this diff.

The only tradeoff of this decision is leaving an opportunity to declare Bubbling/Direct event in the top of the file bc then analysing the code becomes much more difficult. However, it's not used anywhere so it's not a problem now and probably any time.

Also, changes the names to `DirectEventHandler` and `BubblingEventHandler` which are more related to current state. The names were updated in many places in code.

Reviewed By: rubennorte

Differential Revision: D16054571

fbshipit-source-id: 741d075eb46b80bac8eb73a6b30fc0b448cb3902
2019-07-01 05:13:53 -07:00
Rick Hanlon 9a84970c35 Add paperTopLevelNameDeprecated
Summary:
This diff adds a way for the codegen to handle view configs with non-standard top event names by adding a `paperTopLevelNameDeprecated` field to events in the schema.

## The problem
The problem this is solving is that Android host components build their own options for event settings in the view config. So instead of enforcing `onChange` to use the top level event name `topChange` like iOS does, Android can use `change` or `forbarChange` or anything the person adding the component wanted at the time:

```
// Expected
topChange: {
  registrationName: 'onChange',
},

// Android
bringBackStargateYouCowards: {
  registrationName: 'onChange',
},
```

This is possible because of the way Android builds these settings
```
// On iOS, notice that there's no option to change the top level name:
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTDirectEventBlock);

// On Android, you provide the top level event name
Override
public Map getExportedCustomDirectEventTypeConstants() {
  return MapBuilder.of(
      "bringBackStargateYouCowards",
      MapBuilder.of("registrationName", "onChange"));
}
```

Since the codegen does not allow us to specify the top level event name (similar to iOS), we don't have a way to customize the names to support android

## The solution
To fix this, we're adding an extra option the event flow types:

```
onBubblingChange: (event: BubblingEvent<Event, 'customBubblingName'>) => void,
onDirectChange: (event: DirectEvent<Event, 'customDirectName'>) => void,
```

These will register **both** top level names in the view config:

```
{
  directEventTypes: {
     // Notice the same registration name is configured for different top level events
    topChange: {
      registrationName: 'onChange',
    },
    bringBackStargateYouCowards: {
      registrationName: 'onChange',
    },
  }
}
```
This means when either `topChange` or `bringBackStargateYouCowards` fires it will call the onChange listener. **This gives us the flexibility to rename the native event name without breaking backwards compatibility.** Old apps will work when `bringBackStargateYouCowards` is fired, and new apps with an update will work when `topChange` fires.

Note: only the correct name will be generated for Fabric so technically we don't even really need to migrate the paper names and this prop can be deleted when paper is gone.

Reviewed By: cpojer

Differential Revision: D16042065

fbshipit-source-id: 40d076b43ffbbfc6c65c3c19de481d922a2add62
2019-06-28 06:50:36 -07:00
Eli White 365cf96fcb Remove commented out code
Summary: This shouldn't have gotten committed

Reviewed By: rickhanlonii

Differential Revision: D16033668

fbshipit-source-id: b34f9be3525af7b4a81fa7d445769dec20f280d1
2019-06-27 12:18:46 -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
Kevin Gozali b25d22aae6 Use YOGA_CXX_TARGET alias for Buck deps
Summary: Proper abstraction to make BUCK files more OSS friendly.

Reviewed By: shergin

Differential Revision: D15998817

fbshipit-source-id: cad2498f62a8774037e754e8b52200f0dcc5af59
2019-06-26 11:19:34 -07:00
Eli White 2bd503285e Update View Config generator to create command methods
Summary:
Flow types like this:
```
interface NativeCommands {
  +hotspotUpdate: (viewRef: React.Ref<'RCTView'>, x: Int32, y: Int32) => void;
}

export const Commands = codegenNativeCommands<NativeCommands>();
```

get turned into this:

```
export const Commands = {
  hotspotUpdate(viewRef: React.Ref<'RCTView'>, x: number, y: number) {
    UIManager.dispatchViewCommand(
      findNodeHandle(viewRef),
      UIManager.getViewManagerConfig('RCTView').Commands.hotspotUpdate,
      [x, y]
    );
  }
}
```

Reviewed By: rickhanlonii

Differential Revision: D15953126

fbshipit-source-id: edbb91056347d021dd0683391c903b76f3d1c33f
2019-06-24 18:54:41 -07:00
Eli White 9ad60131ba Support parsing View Commands into the schema
Summary: The schema for these view commands is lifted wholesale from the schema for TurboModules: P67239314

Reviewed By: rickhanlonii

Differential Revision: D15943109

fbshipit-source-id: a0ccd4e47067b62970218df6a32527c15868c4a5
2019-06-24 18:54:41 -07:00
Rick Hanlon 468c9f581f Fix native output without props
Summary: Fixes an issue with the native output of components without props and events (a trailing comma)

Reviewed By: cpojer

Differential Revision: D15960962

fbshipit-source-id: 315276ef01484546da43954e6fd879350e214006
2019-06-24 04:59:12 -07:00
Rick Hanlon 8253f90967 Bump babel plugin version to break metro cache
Reviewed By: ejanzer

Differential Revision: D15904504

fbshipit-source-id: 8ea7437156d1bfebaeec3a5dcfccadaad728400b
2019-06-20 02:43:15 -07:00
Rick Hanlon ff5592cff4 Add paperComponentName and paperComponentNameDeprecated
Summary:
This diff removes an option from the codegen and replaces it with two new options

Removes:
- `isDeprecatedPaperComponentNameRCT`

Adds:
- `paperComponentName`: a better version of the removed option that allows more than just adding RCT
- `paperComponentNameDeprecated`: a new option that allows migrating native code to a new name

```
  // Use for components with no current paper rename in progress
  // Does not check for new name
  paperComponentName?: string,

  // Use for components currently being renamed in paper
  // Will use new name if it is available and fallback to this name
  paperComponentNameDeprecated?: string,
```

For example, Slider uses `paperComponentName: 'RCTSlider'` because it has a different name in fabric but is not currently being migrated to a new name. Because of other work in progress, we don't want to use UIManager check if we don't need to

Reviewed By: shergin

Differential Revision: D15857629

fbshipit-source-id: ca0d3b7dc4a75e00d136ae1f5c84f7423960399d
2019-06-19 09:56:04 -07:00
Rick Hanlon 2deb39b8f6 Add support for enum event arguments
Summary:
This diff adds codegen support for event arguments such as:

```
type Event = $ReadOnly<{|
    orientation: ('portrait' | 'landscape'),
|}>;
```

Facebook
 #noautofix

Reviewed By: shergin

Differential Revision: D15769046

fbshipit-source-id: b2ad8d044b06c2394a9aa75a198ea504672cde68
2019-06-18 06:32:31 -07:00
Cameron Bourke be07435e6a Allow type exports from the typed native component
Summary:
## Context
At the moment, the codegen process does not expect any types defined in a native component (*NativeComponent.js) to be exported. For example, the `NativeProps` type may be defined as:

```
// RCTSegmentedControlNativeComponent.js

type NativeProps = $ReadOnly<{|
   ...
   onChange?: ?(event: BubblingEvent<Event>) => mixed,
|}>;
```

However, it would be helpful to be able to reuse `NativeProps` in the user facing component:

```
// SegmentedControlIOS.js

type Props = $ReadOnly<{|
   ...NativeProps
  onValueChange?: ?(value: number) => mixed,
|}>;
```

## Changes
- updates the `getTypes` function to unwrap the type declaration inside exported declarations
- add test to verify that exported types are parsed as expected

Reviewed By: rickhanlonii

Differential Revision: D15851693

fbshipit-source-id: a9cd375c69cbb8fe9a38be3d2a681227444fb33d
2019-06-17 09:05:09 -07:00
Rubén Norte e371978539 Add support for the Stringish type
Summary: `Stringish` is commonly used in components to accept either strings or values coming from Fbt tags. The codegen should support them as they can be used transparently as strings.

Reviewed By: rickhanlonii

Differential Revision: D15821882

fbshipit-source-id: fb94f702d82820677c5a737325b7b46ff4c88151
2019-06-14 06:30:11 -07:00
Eli White 5b4a488617 Remove error for components not defining props
Reviewed By: rickhanlonii

Differential Revision: D15758337

fbshipit-source-id: 91dc52b7cc1a9c9ef978d054fc78f9555d850cf3
2019-06-14 03:54:35 -07:00
Valentin Shergin 874f656435 Fabric: Rethinking of prop parsing infra
Summary:
This diff reimplements the prop parsing infrastructure in a part where it interacts with RawProps value.

Local synthetic tests show that the new way is 3x faster but the actual production result is quite unpredictable. MobileLab tests show some improvements about 10-20 ms on iPhone 6.

In short, the new way is faster because it inverts the lookup order and heavily relies on actual data types (and their properties) that we use. The old approach required about 130 hash-map lookups (where the key is `std::string`) to parse a single *Props object.
The new approach prepares concrete-props-specific tables with indexes of coming values ahead of time,  iterates over raw data and puts it into those tables, and then performs a lookup in a very efficient manner.

Reviewed By: JoshuaGross

Differential Revision: D15752968

fbshipit-source-id: 847106e652eb7fc7ef7b99884a6f819ea3b9fd06
2019-06-12 21:35:21 -07:00
Rick Hanlon c2824dd426 Add schema support for prop array enums
Summary:
This diff adds codegen support for flow types such as:

```
type ModuleProps = $ReadOnly<{|
  size: $ReadOnlyArray<('small', 'large')>
|}>
```

These array enums are codegen'd as bitmaps in c++

Reviewed By: sammy-SC

Differential Revision: D15766763

fbshipit-source-id: 8c55303fb3a0ab151eae2b441119ab078e2c5d3d
2019-06-12 08:10:35 -07:00
Rick Hanlon 0f7bf518ce Add support for WithDefault<string, null>
Summary:
This diff adds support for:

```
propName: WithDefault<string, null>,
```

It will throw if null is used for any other type like boolean

Reviewed By: TheSavior, cpojer

Differential Revision: D15748556

fbshipit-source-id: 925457ca1739bfad08e4776ecb47c0beb3acacf5
2019-06-11 06:33:47 -07:00
Rick Hanlon d8bacc28f6 Add test screen for generating view configs
Summary:
This diff adds a testing screen dev route to the facebook app for testing generated view configs

It's not pretty (i have 0 tetra experiance) but it gets the job done

There are three cases handled:
- No generated config �
- Invalid generated config (useful for dev) �
- Valid generated config �

On the description page we:
- Redbox it it's invalid (this could be used to redbox test all host components)
- Show diffs of the view config properties
- List all of the generated config properties
- List all of the native config properties

Using this tool, it's easy to see what the current config on native is, add correct flow types for the generated config, and validate the generated config

Coming later: adding all of the native configs to the list (will probably need filtering)

Reviewed By: cpojer

Differential Revision: D15683033

fbshipit-source-id: 5a566a56bef4f3f0bac3ea581c2e6acb2b9984e3
2019-06-11 05:06:42 -07:00
Rick Hanlon 97d439e0ba Remove checked-in view configs and js1 build viewconfigs
Summary:
Now that we have the babel plugin, we can remove the checked in view configs

Note that this requires switching the old NativeComponent.js files back to `requireNativeComponent` for open source support (until the babel plugin and codegen are published to a package)

The babel plugin replaces this export with the inline view config

Reviewed By: cpojer

Differential Revision: D15524779

fbshipit-source-id: ab819ce6f24cb2f15a1897ed6d510a0db6aff3a1
2019-06-07 12:31:36 -07:00
Rick Hanlon 504fc0c7d0 Update flow parser to use codegenNativeComponent
Summary:
This diff updated the codegen flow types syntax replacing:

```
type Options = {
  isDeprecatedPaperComponentNameRCT: true,
};

type ActivityIndicatorNativeType = CodegenNativeComponent<
  'ActivityIndicatorView',
  NativeProps,
  Options,
>;

module.exports = ((requireNativeComponent(
  'RCTActivityIndicatorView',
): any): ActivityIndicatorNativeType);
```
with:

```
export default codegenNativeComponent<NativeProps>('ActivityIndicatorView', {
  isDeprecatedPaperComponentNameRCT: true,
});
```

This is from Tim's comment in the [View Config Codegen Quip](https://fb.quip.com/jR2aASHad4Se):

> What it CodegenNativeComponent were instead `NativeComponent.fromFlow<T>('…')` that returned `'...'`?
>And the Babel plugin swapped it for NativeComponent.fromSchema('...', {…}) which would both register and return '...'?

I went with `codegenNativeComponent` because it has nice parity with `requireNativeComponent`

I also didn't update the babel output here (we can update that whenever) because I think `registerGeneratedViewConfig` is more clear for what it's doing

Reviewed By: cpojer

Differential Revision: D15602077

fbshipit-source-id: 2d24dc32136ba6d31724f8c929b51417ba625a58
2019-06-07 12:31:36 -07:00
Rick Hanlon efec97f2be Add view config babel plugin
Summary:
This diff adds a babel plugin for the generated view configs which will inline them in the file instead of needing to check the view configs in (fb only)

The way it works is:
- babel reads the code
- looks for type alias `CodegenNativeComponent` in `*NativeComponet.js` files
- run the flow parser on the file source to create a schema
- run the schema into codegen to get the view config source code
- inject the generated source code back into the NativeComponent.js file
- remove the original export
- profit

After this diff we will remove the `js1 build viewconfigs` command and the checked-in NativeViewConfig.js files

Note: since this plugin is not published to open source, for now OSS will continue using the `requireNativeComponent` function

Reviewed By: cpojer

Differential Revision: D15516062

fbshipit-source-id: a8efb077773e04fd9753a7036682eeaae9175e09
2019-06-07 12:31:36 -07:00
Rick Hanlon 886fb501bd RN Codegen] Add registerGeneratedViewConfig
Summary:
This diff updated the format of generated view configs so that they don't need to spread View props into every config, by adding a new registerGeneratedConfig function which will spread them instead

This is a bit of a cleanup of the generated output but is primarily so that the view config babel plugin will not need to rely on object spreading or object.assigns

Reviewed By: TheSavior, cpojer

Differential Revision: D15517199

fbshipit-source-id: 08e575578177bad12d40ee3dcad9381974b6466d
2019-06-07 12:31:35 -07:00
Valentin Shergin 15302284cc Fabric: Enable CXX (aka Default) platfrom fravour for all C++ Fabric targets
Summary:
First of all, seems it's the right thing to do. Fabric C++ code is cross-platfrom and should run on *all* platforms including Windows, Linux, and Mac.
While we don't have a real *production* use cases where we need compilation for desktops, having CXX target is really handy for two reasons:
* It simplifies local test running process. Instead of going to `/fbandroid/` and executing something like `buck test fbsource//xplat/js/react-native-github/ReactCommon/fabric/core:coreAndroid` (note the suffix). We can just do `buck test fbsource//xplat/js/react-native-github/ReactCommon/fabric/core:core` everywhere and it works now out of the box. Running tests with "Apple" flavor never worked for me.
* It allows creating synthetic benchmark tests (using Google Benchmark) that can be used as a rough approximation of code micro-optimizations.

Reviewed By: JoshuaGross

Differential Revision: D15608678

fbshipit-source-id: d2449035685dbca6ab983480f5334ec4ac11cd35
2019-06-04 15:34:34 -07:00
Sam Goldman b3a50ec0de Deploy Flow v0.100 to xplat/js
Reviewed By: dsainati1

Differential Revision: D15617077

fbshipit-source-id: b88325dd80d167473d3c4cc7bb93c27ea71e654b
2019-06-03 23:03:41 -07:00
Rick Hanlon ebb8caa4df Add handling for ColorArray
Summary: This diff adds support for ColorArrayValue in the flow parser

Reviewed By: cpojer

Differential Revision: D15502923

fbshipit-source-id: 6a906b6d609168378fabeb49d0080de011a34d78
2019-06-03 07:21:20 -07:00
James Ide 33ee6f8b99 Add a lint rule to disallow Haste imports (#25058)
Summary:
This is an ESLint plugin that infers whether an import looks like a Haste module name. To keep the linter fast and simple, it does not look in the Haste map. Instead, it looks for uppercase characters in single-name import paths, since npm has disallowed uppercase letters in package names for a long time. There are some false negatives (e.g. "merge" is a Haste module and this linter rule would not pick it up) but those are about 1.1% of the module names in the RN repo, and unit tests and integration tests will fail anyway once Haste is turned off.

You can disable the lint rule on varying granular levels with ESLint's normal disabling/enabling mechanisms.

Also rewrote more Haste imports so that the linter passes (i.e. fixed lint errors as part of this PR).

## Changelog

[General] [Changed] - Add a lint rule to disallow Haste imports
Pull Request resolved: https://github.com/facebook/react-native/pull/25058

Differential Revision: D15515826

Pulled By: cpojer

fbshipit-source-id: d58a3c30dfe0887f8a530e3393af4af5a1ec1cac
2019-05-30 07:45:16 -07:00
Sam Goldman 87b31bccdf @allow-large-files Deploy Flow v0.99.0 to xplat/js
Reviewed By: dsainati1

Differential Revision: D15541620

fbshipit-source-id: e19795e13d47dca58c5603b308b7cd60ba67ef86
2019-05-29 18:11:43 -07:00
Rick Hanlon 40625ceabf Revert Slider and Activity indicator view configs
Summary: Reverting the generated view configs due to a potential issue

Reviewed By: mdvacca

Differential Revision: D15539319

fbshipit-source-id: bddf923dcfda18bd074196f06610fea8bb4561b4
2019-05-29 13:31:12 -07:00
Rick Hanlon 9f8305a837 Add view config for PullToRefresh
Summary:
Adds the generated view config for PullToRefresh

Note: we're not using this view config yet, the component is in the process of being renamed (see TODO)

Reviewed By: rubennorte

Differential Revision: D15485870

fbshipit-source-id: a163ac371181dcc990093e3cd995d7dd9058b26a
2019-05-24 09:21:28 -07:00
Rick Hanlon ac62274e56 Use generated view config for ActivityIndicatorView
Summary: This diff moves ActivityIndicatorView to the generated view config

Reviewed By: shergin

Differential Revision: D15392561

fbshipit-source-id: 67a2fa0dbbb884af9e9c02b9062d3a610a023240
2019-05-24 09:21:27 -07:00
Rick Hanlon e52bc2aa73 Use generated view config for Slider
Summary: This diff uses the generated view config for the slider component �

Reviewed By: JoshuaGross, TheSavior, mdvacca

Differential Revision: D15336089

fbshipit-source-id: 46c458805fd947e202e2084df65c8c83560cf106
2019-05-24 09:21:27 -07:00
Rick Hanlon ca783414d6 Integrate flow parser into view config generation
Summary:
This diff integrates the new flow parser into `js1 build viewconfig` so that we're generating the view config from actual source

Note: see next diff for usage

Reviewed By: mdvacca

Differential Revision: D15452255

fbshipit-source-id: db04cb1c7adffaf3167a49c2260cae8fd365f50b
2019-05-24 09:21:27 -07:00
Rick Hanlon 057ea6a5c7 Add flow parser
Summary:
This diff initializes the codegen flow parser using a proposal for some new syntaxes in flow file to handle missing  information like:

- Float vs Int32
- Bubbling Events vs Direct Events
- Default props
- Codegen options
- Specifying the component name

For a deep dive on the proposal see:  https://fb.quip.com/kPYJAjCHxlgO

Note: there are still some todos to follow up with:
  - Array props
  - Enum props
  - Object event arguments

Note also: the parser code is a little rough, I didn't want spend too much time cleaning it up before we agreed on the format

[General][Added] Add codegen flow parser

Reviewed By: cpojer

Differential Revision: D15417733

fbshipit-source-id: dd80887c0b2ac46fdc3da203214775facd204e28
2019-05-24 09:21:26 -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 de33b8a237 Generate events with no arguments
Summary:
This diff allows generating native events without any arguments with an event like:

```
{
  name: 'onEnd',
  optional: true,
  bubblingType: 'bubble',
  typeAnnotation: {
    type: 'EventTypeAnnotation',
    // note: no argument key
  },
},
```

See the snapshot updates in the diff for the native code that will be generated �

Reviewed By: shergin

Differential Revision: D15403791

fbshipit-source-id: 925a49bb477eebb234e181df681f0d6b1d4e8cf1
2019-05-22 05:36:20 -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 531f11f084 Fix flow and formatting
Summary: Fixes a flow failure in the generated output and adds trailing commas to pass linting

Reviewed By: yungsters

Differential Revision: D15354725

fbshipit-source-id: 1eac27fa753af595a9a2787426b147e5f49a4e1d
2019-05-20 02:52:37 -07:00
Rick Hanlon a5105d5c54 Normalize directEventType names
Summary: After reading the native code, all bubbling and direct events need to start with "top", but we were only doing this for bubbling in the view config. Updated and added comments pointing to native behaviors

Reviewed By: TheSavior

Differential Revision: D15336080

fbshipit-source-id: d8f883f5fd41bb7856a334849dc7fce0c8922872
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 ed61a3b5f9 Handle component name
Summary:
In order to generate the view configs, we need to know the name of the component used in:

```
ReactNativeViewConfigRegistry.register(
  'RCTNativeComponent',  // <------- this name
  () => BooleanPropNativeComponentViewConfig,
);
```

For this, we'll use `component.name` in the schema (see fixture updates). Doing this would break the native code we generate though, since that code has the RCT stripped.

So this diff adds support to mirror the native stripping of 'RCT' for generated native code

Reviewed By: TheSavior

Differential Revision: D15320422

fbshipit-source-id: be1ab9964078df2c7bc6e41462776f00b94b104f
2019-05-16 10:51:06 -07:00
Rick Hanlon 382846aefd Add viewconfig verification
Summary: This diff adds a line to the codegen'd view configs which will check that all of the properties in the native view config are also in the JS view config we generate (note that the JS view config may have more properties than one native platform because it includes a union of both platforms)

Reviewed By: TheSavior

Differential Revision: D15278478

fbshipit-source-id: 0fef20c12265b952c69aca4e4c070a7d036db05a
2019-05-16 10:51:06 -07:00
Rick Hanlon 1aca74586f Update view configs handle view props/events
Summary:
This diff adds support for spreading view props into the generated viewconfig (currently hardcoded the view viewconfig but soon that will also be generated)

Results in a generated view config such as:

```
const ReactNativeViewConfig = require('ReactNativeViewConfig');
const ReactNativeViewConfigRegistry = require('ReactNativeViewConfigRegistry');

const BooleanPropNativeComponentViewConfig = {
  uiViewClassName: 'BooleanPropNativeComponent',
  Commands: {},

  bubblingEventTypes: {
    ...ReactNativeViewConfig.bubblingEventTypes
  },

  directEventTypes: {
    ...ReactNativeViewConfig.directEventTypes
  },

  validAttributes: {
    ...ReactNativeViewConfig.validAttributes,
    disabled: true
  }
};

ReactNativeViewConfigRegistry.register(
  'BooleanPropNativeComponent',
  () => BooleanPropNativeComponentViewConfig,
);

module.exports = 'BooleanPropNativeComponent';
```

Reviewed By: TheSavior

Differential Revision: D15258778

fbshipit-source-id: 2c70d20dc366f32a8114d42e0e15b5f1e359d11f
2019-05-16 10:51:06 -07:00
Rick Hanlon 3e1e661d2a Update generated differs
Summary: This diff inserts the differs for color/image/point inline into the generated viewconfigs

Reviewed By: TheSavior

Differential Revision: D15258752

fbshipit-source-id: 0e93dc6abc186851b411dfd6864d5b4ca005885b
2019-05-16 10:51:06 -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
Adrian Zgorzalek ff9f8f347d Upgrade prettier to 1.17.0
Summary:
Run `js1 upgrade prettier 1.17.0` and `xplat/js/scripts/update-oss-yarn-lockfile.sh` and `hg revert -r .^ xplat/js/rome`

allow-large-files

Reviewed By: zackargyle, pvdz

Differential Revision: D15164375

fbshipit-source-id: 2fe68733dfa93ea64a67d170ba2f80c5af086917
2019-05-07 10:35:14 -07:00
Rick Hanlon 43357df5cd Support hyphen symbols in enums
Summary: This diff adds support for kebab-case enum properties by transforming them to KebabCase in cpp

Reviewed By: mdvacca

Differential Revision: D15218781

fbshipit-source-id: 0ec6d28f3ca0e5b8187fc7026e12a8d76be73a7c
2019-05-07 06:29:18 -07:00
Florian 2becfabb7d Update eslint-plugin-react-native dependency in eslint-config-react-native-community package (#24686)
Summary:
I need this in my life because version 3.7.0 fixes [this](https://github.com/Intellicode/eslint-plugin-react-native/pull/220) issue.

[General][fixed] - Fix an issue with `no-raw-text` rule for TypeScript by updating the eslint-plugin-react-native dependency to 3.7.0
Pull Request resolved: https://github.com/facebook/react-native/pull/24686

Differential Revision: D15237597

Pulled By: cpojer

fbshipit-source-id: 42ee13997d238025d0c50d154951549392d3abc7
2019-05-07 03:12:44 -07:00
Rick Hanlon 38483d4ab1 Generate cpp tests for props
Summary:
This diff adds generated c++ tests for all generated components

There is a test for every prop based on type, and in the case of enums every allowed value

Reviewed By: shergin

Differential Revision: D15147126

fbshipit-source-id: b4f88d2dab825e41754a880081d86b3cd12274ee
2019-05-04 12:00:38 -07:00
Matt Oakes 2ef56c025d Bump @react-native-community/eslint-config version (#24650)
Summary:
Bump the `react-native-community/eslint-config` version so we can release it.

[General] [Changed] - Bumped react-native-community/eslint-config version
Pull Request resolved: https://github.com/facebook/react-native/pull/24650

Differential Revision: D15146456

Pulled By: cpojer

fbshipit-source-id: 9a6767f502f1b5dcd49cf55b4e35c0d851f33222
2019-04-30 02:31:06 -07:00
Matt Oakes 65eea9d1f8 Set the Prettier config so it is not forced on users of @react-native-community/eslint-config (#24635)
Summary:
This fixes an issue where the Prettier config was set to the `fb` (Facebook) values for all users of the `react-native-community/eslint-config` package. This was due to [this line](8f186b84ae/packages/eslint-config-react-native-community/index.js (L219)) in the config file.

It was causing issues like these:

* Errors when using newer versions of `eslint-plugin-prettier` (you had to use a version that was >1 year old): https://github.com/facebook/react-native/issues/24564
* Errors due to the Prettier parser being forced to be `flow` when using Typescript: https://github.com/typescript-eslint/typescript-eslint/issues/481

This PR:

* Changes that line to remove the explicit `fb` config so users can set their own.
* Moves the React Native Prettier config to `.prettierrc` so ESLint, Prettier, and code editors can all read from the same place.
* Upgrades both `prettier` and the `eslint-plugin-prettier` to the latest versions.

[General] [Fixed] - Stopped the Prettier config being set for all users of react-native-community/eslint-config
Pull Request resolved: https://github.com/facebook/react-native/pull/24635

Differential Revision: D15122200

Pulled By: cpojer

fbshipit-source-id: 56bae8a7f2d8e133b1d808091a6b73302b94d2ed
2019-04-29 09:44:51 -07:00
Rick Hanlon bddd9c7d59 Generate Tests
Summary:
To ensure greater type safety, we want to generate some cpp tests for the fromRawValue conversions

This diff adds support to generate Tests.cpp along with the `buck test` targets itegrated into the rn_codegen rule automatically. The tests just `assert(true, true)` as a starting point

Reviewed By: fkgozali

Differential Revision: D14739493

fbshipit-source-id: fc9dea64ea31e6af7d997aebc54cfd459d48bf4f
2019-04-17 07:32:18 -07:00
zhongwuzw b60651dd09 Add indent for event emitter header generation of codegen (#24445)
Summary:
Part of #24438, add indent foe event emitter header codegen.
cc. cpojer rickhanlonii.

[General] [Fixed] - Add indent for event emitter header generation of codegen
Pull Request resolved: https://github.com/facebook/react-native/pull/24445

Differential Revision: D14930352

Pulled By: cpojer

fbshipit-source-id: 8bd03b8e12ccf9bd06546acdb744541fcb92eea1
2019-04-14 06:07:04 -07:00
zhongwuzw 2a4a9f86d4 Add indent for props generation of codegen (#24438)
Summary:
Add correct indent when run codegen.
Before:
<img width="686" alt="image" src="https://user-images.githubusercontent.com/5061845/56078952-41f43a80-5e20-11e9-998e-e386f54b0b95.png">
<img width="655" alt="image" src="https://user-images.githubusercontent.com/5061845/56078955-491b4880-5e20-11e9-9935-561039806e48.png">

After:
<img width="692" alt="image" src="https://user-images.githubusercontent.com/5061845/56078931-18d3aa00-5e20-11e9-9865-126b18fbeb58.png">
<img width="658" alt="image" src="https://user-images.githubusercontent.com/5061845/56078940-225d1200-5e20-11e9-9ec7-374cf5c83768.png">

cc. cpojer rickhanlonii

[General] [Fixed] - Add indent for props generation of codegen
Pull Request resolved: https://github.com/facebook/react-native/pull/24438

Differential Revision: D14930351

Pulled By: cpojer

fbshipit-source-id: ec144119f78dd9e6e6d49321184d7d996aae90aa
2019-04-14 05:43:48 -07:00
michalchudziak 037d16ba72 Bump @react-native-community/eslint-config version (#24389)
Summary:
[General] [Changed] - Bumped react-native-community/eslint-config version
Pull Request resolved: https://github.com/facebook/react-native/pull/24389

Differential Revision: D14870055

Pulled By: cpojer

fbshipit-source-id: 1a8d208757cf433146e71383e59044740321760a
2019-04-10 04:04:51 -07:00
Eli White ec3adae99a Turn on react-hooks/exhaustive-deps in FBSource
Summary: Looks like there are already a bunch of issues in the codebase because this wasn't on.

Reviewed By: cpojer

Differential Revision: D14701084

fbshipit-source-id: 09ff8e0d905b81fbe08c41d4f58758479b38187b
2019-04-01 08:20:18 -07:00
satyajit.happy b49fdd19e4 Add typescript support to the ESLint config (#24100)
Summary:
This adds TypeScript support to the community ESLint config. Our babel preset supports TypeScript by default, so it's nice to have TypeScript support pre-configured in the ESLint config too.

Note: Users need to install `typescript` in their project for linting to work for TypeScript files.

[General] [Added] - Add TypeScript support to the ESLint config
Pull Request resolved: https://github.com/facebook/react-native/pull/24100

Differential Revision: D14597127

Pulled By: cpojer

fbshipit-source-id: dfbf1b97061ed6e8c46aa49adb21630f5acdb5d1
2019-03-25 21:28:26 -07:00
michalchudziak c8e26e6ac4 Fix eslint glob for `.test.js` and `.spec.js` files. (#24088)
Summary:
Existing glob might not work very well with `spec.js` and `test.js` files unless they're placed in `__tests__` directory. This PR aims to bring back the support of `jest` globals in these files, even if they're outside of `__tests__` directory.

[General] [Fixed] - Fixed globs for `spec.js` and `test.js` files.
Pull Request resolved: https://github.com/facebook/react-native/pull/24088

Differential Revision: D14562085

Pulled By: cpojer

fbshipit-source-id: 543d67e3f8a154256f454b34ccc68bb070197a75
2019-03-21 08:39:39 -07:00
michalchudziak 395197dafe Add .eslintrc to RN project template (#23901)
Summary:
The goal of this PR is to enable eslint checks in the projects generated by `react-native init` command. I added `template/_eslintrc` file, that would be replaced in an initialized project with `.eslintrc` file. This PR comes in parallel with https://github.com/react-native-community/react-native-cli/pull/229

[General] [Added] - Added `.eslintrc` file to generated template.
Pull Request resolved: https://github.com/facebook/react-native/pull/23901

Differential Revision: D14561084

Pulled By: cpojer

fbshipit-source-id: 6eb717bf03c45d83ae8a393e6a0abb79e1e2f915
2019-03-21 07:14:23 -07:00
Matt Hargett e67aa427a8 Eliminate eslint npm version mismatch warnings and bump some to latest (#23969)
Summary:
I was annoyed by warnings from yarn/npm about eslint peer dependencies not being met, so I dived in to try and get rid of some of them. Sometimes it meant bumping a plugin, but then that plugin needed a newer babel-eslint, so it was a dance.

Some we can't easily update to latest (eslint-plugin-prettier) because the rule format has changed a bit. Happy to do that in this PR if folks think its a good idea. eslint-config-fbjs itself needs to be updated and republished to eliminate the last few warnings.

There are a few new warnings (the repo wasn't linting cleanly for me from the start). I can fix those in this PR, or a separate one, based on people's preferences.

[internal] [chore] - Eliminate some peer dependency warnings and bump some eslint packages to latest.
Pull Request resolved: https://github.com/facebook/react-native/pull/23969

Differential Revision: D14519076

Pulled By: cpojer

fbshipit-source-id: aa44cfd05814d7b79069414aa78d089e448c2235
2019-03-19 11:14:30 -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
Mike Grabowski 5558333c60 Update React Native to use latest CLI (#23940)
Summary:
Landing D14472633 again which failed because of a metro-buck issue.

Latest CLI requires `reactNativePath` to be explicitly set when `react-native` is not present under `node_modules` (which is the case when running from source).

Fixes #23936

This PR also updates CLI to latest version and removes private calls to `findPlugins` (it's now exposed under public interface).

We also remove custom `rn-cli.config.js` options that are no longer needed that we have `--reactNativePath`. I added them a month ago as a temporary workaround.

[GENERAL] [FIXED] - Internal - Update to the latest CLI
Pull Request resolved: https://github.com/facebook/react-native/pull/23940

Reviewed By: rickhanlonii

Differential Revision: D14501686

Pulled By: cpojer

fbshipit-source-id: c8dac71b3806d81c9d18b6d4a7e92d82962791f9
2019-03-18 06:22:53 -07:00
Adam Ernst 0ceaaf0cf6 Revert D14472633: [react-native][PR] Update React Native to use latest CLI
Differential Revision:
D14472633

Original commit changeset: b7ea92ee130d

fbshipit-source-id: ed5bce3ba4a39c8b60e787cb678747231583f6f5
2019-03-15 14:07:54 -07:00
Mike Grabowski 1fe4799a88 Update React Native to use latest CLI (#23940)
Summary:
Latest CLI requires `reactNativePath` to be explicitly set when `react-native` is not present under `node_modules` (which is the case when running from source).

Fixes #23936

This PR also updates CLI to latest version and removes private calls to `findPlugins` (it's now exposed under public interface).

We also remove custom `rn-cli.config.js` options that are no longer needed that we have `--reactNativePath`. I added them a month ago as a temporary workaround.

[GENERAL] [FIXED] - Internal - Update to the latest CLI
Pull Request resolved: https://github.com/facebook/react-native/pull/23940

Differential Revision: D14472633

Pulled By: cpojer

fbshipit-source-id: b7ea92ee130da6730aa0093265958aa1b8c2ab97
2019-03-15 11:07:48 -07:00
Peter van der Zee dcd4e90d9a Bump Prettier to 1.16.4
Summary:
@public
This bumps Prettier to v1.16.4
Only format source files were updated.

Reviewed By: mjesun

Differential Revision: D14454893

fbshipit-source-id: 72f9872fe764a79dbf0d9fab9bebb1456b039f2f
2019-03-14 07:00:27 -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
michalchudziak 3898ee3a01 Move `@react-native-community/eslint-config` devDependencies to dependencies (#23766)
Summary:
I moved `devDependencies` to `dependencies` section of `packages/eslint-config-react-native-community`, to avoid the need for installation of them in the main projects. Now the installation should match the guide, from https://github.com/facebook/react-native/tree/master/packages/eslint-config-react-native-community

[General] [Changed] - Moved `devDependencies` of eslint config to `dependencies` section.
Pull Request resolved: https://github.com/facebook/react-native/pull/23766

Differential Revision: D14436081

Pulled By: cpojer

fbshipit-source-id: 770110eb4b2b6dfbbb7456fd1b69e20a8473a4e2
2019-03-12 23:37:18 -07:00
Eli White e3b2818581 Add test for -0.0 float
Summary:
This was an idea to check by Joshua Gross

Changelog:
[General][Internal] Codegen: Adding test for negative zero floats

Reviewed By: JoshuaGross

Differential Revision: D14378418

fbshipit-source-id: 4d18eea18143c501d3f2e7ba334f35ec1dd140e6
2019-03-07 18:21:27 -08:00
Rick Hanlon f43703bdb5 Add #pragma once to Props.h generator
Summary: We need this in the Props.h files

Reviewed By: TheSavior

Differential Revision: D14307476

fbshipit-source-id: 34a86ced30e04bfb6d7f85dc292e43d2a1a0ac3e
2019-03-05 11:53:56 -08: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
michalchudziak 1ed2b82693 Rename eslint config to 'eslint-config-react-native-community' (#23718)
Summary:
Renamed `eslint-config-react-native` to `eslint-config-react-native-community`, due to the fact, that initial name is already taken on `npm`. Additionally, I added very simple `README.md` file, to prepare the package to be published.

[General] [Changed] - Changed `eslint-config-react-native` name to `eslint-config-react-native-community`
Pull Request resolved: https://github.com/facebook/react-native/pull/23718

Differential Revision: D14298553

Pulled By: cpojer

fbshipit-source-id: bad5a42502ccdebf5f95d8217187be23bbf8f26c
2019-03-03 20:39:43 -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 85d343d056 Capitalize enum default values
Summary: It was weird that the default values for enums did not match the casing for the enum options

Reviewed By: TheSavior

Differential Revision: D14258101

fbshipit-source-id: f601e50390a6c67f20e7a18aa94b377597a831cc
2019-03-02 12:56:01 -08:00
Dratwas e903d8059a Move eslint/prettier config to packages/eslint-config-react-native (#23688)
Summary:
Basing on discussion from this issue - https://github.com/react-native-community/discussions-and-proposals/issues/65 we moved ESLint/Prettier config to its own package inside packages directory.
At this moment we had to left all `eslint` dependencies in root `package.json` since `eslint-config-react-native` is not published yet.

[General] [Changed] - Move eslint/prettier config to packages/eslint-config-react-native
Pull Request resolved: https://github.com/facebook/react-native/pull/23688

Differential Revision: D14277068

Pulled By: cpojer

fbshipit-source-id: ef2d0b33210418318cc8324f15fedd84df0ef64d
2019-02-28 23:49:55 -08:00
Moti Zilberman 0ae48f5c38 Move react-native-symbolicate to metro repo
Summary:
@public

Previously open-sourced as `react-native-symbolicate`, this package is more closely coupled with Metro and should therefore be part of the latter.

Reviewed By: cpojer

Differential Revision: D14208031

fbshipit-source-id: 8bae2100149142394e12d499dc4b8a256f07647e
2019-02-28 10:19:02 -08:00
Martynas Bardauskas 9cb93abc47 enable symbolicate for sectioned sourcemaps (#23572)
Summary:
`react-native-symbolicate` usage output claim to work with 4 arguments, though the code supports 3. Furthermore, `Symbolication.parseFileName` is getting a lineNumber argument instead of fileName. Described issues disable usage of sectioned source map symbolication, which was discussed in https://github.com/getsentry/sentry-cli/issues/408.
Duplicate of https://github.com/facebook/react-native/pull/23514 without modified commit history

[General] [Fixed] - enable symbolicate for sectioned/indexed/segmented source maps
Pull Request resolved: https://github.com/facebook/react-native/pull/23572

Differential Revision: D14179787

Pulled By: cpojer

fbshipit-source-id: 15f983c285fc6ac5570d01550fc939b975375bfa
2019-02-21 19:42:09 -08:00
Christoph Nakazawa 59377830b4 JavaScript tests for symbolication
Summary:
People in open source are now contributing to our symbolication code. They cannot figure out how to run buck for their tests so I instead converted them to Jest tests. See https://github.com/facebook/react-native/pull/23514 for an example contribution where people are struggling.

This PR:
* Changes the stdin reading mechanism to also work inside of a forked child process
* I manually verified that the previous BUCK tests were all passing after my modifications to the main script
* I rewrote each test using Jest
* I then switched the passing tests over to use snapshots

As a result, there are now a few fewer files and they all run inside of Jest. The code being tested is identical and keeps working.

Reviewed By: davidaurelio

Differential Revision: D14147615

fbshipit-source-id: 699044a579278f6451bb9d26a05712f00e4b7c04
2019-02-20 05:08:53 -08:00
Héctor Ramos 2c25e34060 Use new yearless copyright header format
Summary: Use the new copyright header format used elsewhere in the React Native repository.

Reviewed By: shergin

Differential Revision: D14091706

fbshipit-source-id: b27b8e6bcdf2f3d9402886dbc6b68c305150b7d5
2019-02-19 10:35:12 -08:00
Christoph Nakazawa d27a4f9166 Add metadata to symbolicate package.
Summary: This will allow publishing the package to npm.

Reviewed By: davidaurelio

Differential Revision: D14083973

fbshipit-source-id: b5f68b87b82a3b6bc644727de403bd449ec17239
2019-02-15 07:28:15 -08:00
Christoph Nakazawa 3d83540973 Open Source symbolication code
Summary: This moves the internal symbolication code out to open source so that people can look up source locations for stack traces in RAM bundles. Wix needs this, and there is no reason to keep this code internal.

Reviewed By: bthood

Differential Revision: D14083307

fbshipit-source-id: afd2435c1b549b04ae7a04340ceeac1c5e4c99f0
2019-02-15 07:28:15 -08:00
Jonathan Kim c02f278d8f xplat// -> fbsource//xplat/ for xplat/js
Reviewed By: scottrice

Differential Revision: D14076351

fbshipit-source-id: f803d2af438a5eb3f18c981793e17b6293d8ef1c
2019-02-14 23:53:32 -08:00
Jonathan Kim 79d9595b97 Turn off translation for fbandroid
Summary:
Turn off translations in fbandroid to mitigate the parse time regression. Translate the remaining `xplat//` to `fbsource//xplat/` to do so

run_all_tests

Reviewed By: scottrice

Differential Revision: D14041085

fbshipit-source-id: 9d3bc493c6662c03c4028aaebfbec58d145e8c6b
2019-02-13 04:36:00 -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