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

265 Коммитов

Автор SHA1 Сообщение Дата
Kevin Gozali fb627dac6a TM JS: Revert to import from TurboModuleRegistry.js
Summary:
Changelog: [Internal]

Reverting the import to the previous local module style since importing from react-native seems to introduce some perf regression. We'll revisit this later in the future.

Reviewed By: yungsters

Differential Revision: D18383893

fbshipit-source-id: f11d46a4545768f39199fd6fd22fcf14905d0a74
2019-11-08 11:44:16 -08:00
Jordan Brown 93e58b2c96 Suppressions for 0.111
Summary:
still some generated files in www that need to land before we can release 0.111 here.

drop-conflicts

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: dsainati1

Differential Revision: D18278838

fbshipit-source-id: b20c3fefb3aab7c5fb614b33d846c7548184f49a
2019-11-05 17:36:23 -08:00
Kevin Gozali dd06f85bd0 TM JS: cleaned up TurboModuleRegistry types [2]
Summary:
Changelog: [Internal]

Moved the imports for `TurboModuleRegistry` and `TurboModule` from `react-native`. This was a jscodeshift with the script: P120688078

Reviewed By: yungsters

Differential Revision: D18262538

fbshipit-source-id: 48fac15229c897408928511c5ecbb42f17ec7b42
2019-11-04 18:51:05 -08:00
Samuel Susla 7ef252bcb3 Export native commands codegen classes and fix build issue
Summary:
1. Generated `RCTComponentViewHelpers.h` file was not being exported.
2. argument declaration was within `if RCT_DEBUG` directive which meant in production it was stripped.

changelog: [internal]

Reviewed By: TheSavior

Differential Revision: D18266846

fbshipit-source-id: 4c13b8ee9cf4cb3b7486ba7cfef0c64bc46b2360
2019-11-04 11:17:42 -08:00
Frieder Bluemle 1353da5a53 Update eslint-config dependencies (#27085)
Summary:
A couple of minor and patch updates to the `eslint-config` package, to avoid warnings and errors with the generated code of the latest RN version templates, such as:

```
warning "react-native-community/eslint-config > eslint-plugin-react@7.12.4" has incorrect peer dependency "eslint@^3.0.0 || ^4.0.0 || ^5.0.0".
warning "react-native-community/eslint-config > eslint-plugin-react-native@3.6.0" has incorrect peer dependency "eslint@^3.17.0 || ^4 || ^5".
```

`yarn check` outputs the following errors:

```
error "react-native-community/eslint-config#eslint-plugin-react-native#eslint@^3.17.0 || ^4 || ^5" doesn't satisfy found match of "eslint@6.6.0"
error "react-native-community/eslint-config#eslint-plugin-react#eslint@^3.0.0 || ^4.0.0 || ^5.0.0" doesn't satisfy found match of "eslint@6.6.0"
```

By adding the missing `"license"` field, from now on this also avoids the following warnings:

```
warning package.json: No license field
warning react-native-community/eslint-config@0.0.6: No license field
```

## Changelog

[General] [Fixed] - Fix eslint-config peer dependency warnings
Pull Request resolved: https://github.com/facebook/react-native/pull/27085

Test Plan:
- Publish current `master` package locally (`0.0.6` is [not published](https://www.npmjs.com/package/react-native-community/eslint-config) yet!)
- Create new RN 0.61.3 project, set `eslint-config` to local package, observe errors/warnings running `yarn`/`yarn check`
- `yarn lint` passes cleanly
- Update dependencies (as in this PR), republish locally
- Update RN test project to new `eslint-config` package, **observe no more errors**
- `yarn lint` still passes cleanly

Differential Revision: D18298733

Pulled By: cpojer

fbshipit-source-id: 9a550365521fbaa4b940bc8c02cbeb345d8900b6
2019-11-04 08:17:07 -08:00
Stanislav f6a62f9ae2 Add Intl to eslint globals. (#27082)
Summary:
Fix `'Intl' is not defined. eslint(no-undef)` warning by eslint: see https://github.com/facebook/react-native/issues/27076
Pull Request resolved: https://github.com/facebook/react-native/pull/27082

Differential Revision: D18298548

Pulled By: cpojer

fbshipit-source-id: c07af711086d79d214bfbbe2bba6f396628c96c1
2019-11-04 08:14:29 -08:00
Samuel Susla b6a23d8793 Add excludedPlatform option to CodeSchema
Summary:
Currently we generate Java ViewManager interfaces and C++ classes for iOS regardless whether the component is supported on platform or it isn't. This adds an option to exclude either iOS to Android in order to avoid this.

Changelog: In codegen it is now possible to exclude one or the other platform

Reviewed By: rickhanlonii

Differential Revision: D18217185

fbshipit-source-id: 1c569b92c92a5b991c96b0abdff6b8ed395e449f
2019-11-04 04:36:55 -08:00
Tim Yung 03f5951b45 RN: Permit Inline Styles in Tests
Summary:
Configures ESLint in React Native to permit inline styles in tests. Because, why not.

Changelog:
[Internal]

Reviewed By: TheSavior

Differential Revision: D18290625

fbshipit-source-id: 111c7fd2972179536487b94bd7b14f34167ea8c7
2019-11-03 18:02:00 -08:00
dr2009 af8ea06bb4 Add WebSocket to eslint globals (#27044)
Summary:
WebSocket is giving an error by eslint. ('WebSocket is not defined').

[websocket-support](https://facebook.github.io/react-native/docs/network#websocket-support)

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

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

Differential Revision: D18223891

Pulled By: cpojer

fbshipit-source-id: c4adfde07078133930aa0ed80be5615d128f4148
2019-10-30 08:32:52 -07:00
Christoph Nakazawa 55e974d9fa Revert D18173919: fix(eslint-config): Clashes with prettier
Differential Revision:
D18173919

Original commit changeset: b333469652b4

fbshipit-source-id: 819d484101be132ae3f2d3bf8e3ba008a9d91d83
2019-10-29 13:18:49 -07:00
Kyle Roach e4b62bb139 fix(eslint-config): Clashes with prettier (#26847)
Summary:
Currently, react-native-community config package extends from prettier/recommended which comes with default settings from prettier. However there are still some eslint rules in the config that either clash or duplicate the settings from prettier.

This results in eslint fixing the formatting and then prettier undoing it. This PR removes the style specific rules from eslint and place them in the prettier section.
## Changelog

[General] [Fixed] - Remove style rules from eslint config for prettier options
Pull Request resolved: https://github.com/facebook/react-native/pull/26847

Test Plan:
I created a repo for you to test with https://github.com/iRoachie/eslint-bug-replicate. You can see that running `yarn lint --fix` will never fix the issue. Eslint will complain about double quotes and subsequently after fixing it will complain about single quotes.

Here's a gif of the behaviour (vscode eslint plugin `"eslint.autoFixOnSave": true`):

![Kapture 2019-10-13 at 23 34 15](https://user-images.githubusercontent.com/5962998/66728290-ff80da00-ee11-11e9-8993-4d1b679c270b.gif)

Differential Revision: D18173919

Pulled By: cpojer

fbshipit-source-id: b333469652b4c8e72287718af94378505e9b7d59
2019-10-28 13:17:09 -07:00
Andres Suarez aee88b6843 Tidy up license headers [3/n]
Summary: Changelog: [General] [Fixed] - License header cleanup

Reviewed By: yungsters

Differential Revision: D17952693

fbshipit-source-id: 8fcb8e58a2e04e7a3169f4d525bffc00835768e6
2019-10-16 10:06:34 -07:00
Andres Suarez 3b31e69e28 Tidy up license headers [2/n]
Summary: Changelog: [General] [Fixed] - License header cleanup

Reviewed By: yungsters

Differential Revision: D17952694

fbshipit-source-id: 17c87de7ebb271fa2ac8d00af72a4d1addef8bd0
2019-10-16 10:06:34 -07:00
Janette Cheng 10cc834567 Use fbandroid_labels and fbobjc_labels in xplat targets
Summary:
`xplat` targets add different deps based on what platform the target is being built for.

for anything using `fb_xplat`, we can put all ios supermodules in `fbobjc_labels` and all android sms in `fbandroid_labels`

There's some weirdness with python targets like `thrift_gen` in  `/xplat/mobileconfig/tools/generator/gen-py/BUCK` that don't have platform-specific labels because the except_for list for `fbandroid` doesn't need the `fbsource//` prefix (see changes in `/ios/isolation/infra.mobileconfig.sm`)

Changelog: [Internal]

Reviewed By: shergin, joshleibsly

Differential Revision: D17884952

fbshipit-source-id: e245364cf515b75682990094d24f789d53b1f3f5
2019-10-15 19:32:27 -07:00
Moti Zilberman 90977b0e00 Enable no-useless-escape lint rule
Summary: See https://eslint.org/docs/rules/no-useless-escape. Useless escapes can reflect a mismatch between the intended and actual effect of a backslash in a literal.

Reviewed By: rubennorte

Differential Revision: D17876784

fbshipit-source-id: 7641b1f2227b92e1e91469adc0d0d990a64109cf
2019-10-11 05:56:06 -07:00
Moti Zilberman 6611c4b8f4 Move error-subclass-name lint rule to GitHub
Summary: Ports an internal ESLint rule used at Facebook, `error-subclass-name`, to cover the React Native codebase. This rule enforces that error classes ( = those with PascalCase names ending with `Error`) only extend other error classes, and that regular functions don't have names that could be mistaken for those of error classes.

Reviewed By: rubennorte

Differential Revision: D17829298

fbshipit-source-id: 834e457343034a0897ab394b6a2d941789953d2e
2019-10-09 11:48:07 -07:00
Brian Solon 375ef14c04 Fix minor typos in react-native-codegen errors (#26714)
Summary:
Fixing typos

## Changelog

[Internal] [Fixed] - Fixed minor typos in react-native-codegen errors
Pull Request resolved: https://github.com/facebook/react-native/pull/26714

Test Plan: N/A

Differential Revision: D17758833

Pulled By: cpojer

fbshipit-source-id: cf3adea2b5f89426c8b98fd49f47c1b043d9a72a
2019-10-04 23:26:18 -07:00
Adam Ernst a45e6a8b5f React Native supermodule
Summary: #nocancel

Reviewed By: fkgozali

Differential Revision: D17747685

fbshipit-source-id: 9bad072d3549959528612c2f0329799853d4b675
2019-10-03 15:43:38 -07:00
Eli White 21f1cce148 Remove unused code
Summary:
There are some unused imports and variables. This was flagged by running
```
$ js1 lint --only "no-unused-vars: [1, {vars: 'all', args: 'none', ignoreRestSiblings: true}]" ~/fbsource/xplat/js/react-native-github --only "react/jsx-uses-vars" --only "react/jsx-uses-react" --fast
```

Changelog:
Internal

Reviewed By: zackargyle, JoshuaGross

Differential Revision: D17724836

fbshipit-source-id: 2b6a44f55c878d659c9c23f5878ba34f21f8bb69
2019-10-03 14:33:59 -07:00
Marek Cirkos de17cdecd8 Migrate platform imports to platform_defs.bzl
Summary:
This is easiest migration of imports that ONLY import platform symbols, so can be simply renamed
Generated by running in xplat:
```
$ REGEX="(load\(\"fbsource\/\/tools\/build_defs\:default_platform_defs\.bzl\")((, \"ANDROID\")*(, \"APPLE\")*(, \"CXX\")*(, \"IOS\")*(, \"MACOSX\")*(, \"WINDOWS\")*)\)"
$ REPLACEMENT="load(\"fbsource//tools/build_defs:platform_defs.bzl\"\2)"

$ cd xplat
$ ../fbcode/experimental/codemod2/codemod.py --filename "BUCK" "${REGEX}" "${REPLACEMENT}"
$ ../fbcode/experimental/codemod2/codemod.py --extension "bzl" "${REGEX}" "${REPLACEMENT}"
$ arc lint -a
```

Reviewed By: mzlee

Differential Revision: D17602152

fbshipit-source-id: 905f7c3c5ef27596e4c0f85dd2a0ad6b57753182
2019-09-27 09:54:58 -07:00
Eli White 62acf6e26a Update codegen test fixtures to use HostComponent
Summary:
Changelog:
[Internal] Update codegen test fixtures to use HostComponent

Reviewed By: JoshuaGross

Differential Revision: D17573955

fbshipit-source-id: bae3ab44c5d300d4b9297fcb243e49667776f9bc
2019-09-25 13:16:04 -07:00
Eli White 0676ebf79a Migrate NativeComponentType from codegenNativeComponent to HostComponent #2
Summary:
We need to migrate to HostComponent instead of the exported type from codegenNativeComponent which is the same type

Changelog:
[Internal] Migrate NativeComponentType from codegenNativeComponent to HostComponent

Reviewed By: rickhanlonii

Differential Revision: D17563307

fbshipit-source-id: 01c8fea8c67b33bed42ae28ffb8c132be87b9a7a
2019-09-25 11:44:38 -07:00
Logan Daniels 89e3f70eab Upgrade nullthrows to ^1.1.1
Reviewed By: TheSavior

Differential Revision: D17552725

fbshipit-source-id: 535faeb8d9ca2b901c5342a48ccba7fc26aebd4f
2019-09-25 10:16:00 -07:00
Samuel Susla 845cbec5cf Add codegen support for EdgeInsets
Summary: Add codegen support for `EdgeInsets`.

Reviewed By: rickhanlonii

Differential Revision: D17500509

fbshipit-source-id: b2909fe296c51d3a47cc961c45294eead7707853
2019-09-23 09:12:51 -07:00
Oleksandr Melnykov 92f3b4a27f Allow null as default value for float props
Summary:
Some props must have their default values set by native. To be able to support this, we have to introduce a null as a supported default value for some types. In this diff I'm adding support for null default values for float props. An example of this to be useful is `ReactDrawerLayoutManager`:

```
  Override
  public void setDrawerWidth(ReactDrawerLayout view, Nullable Float width) {
    int widthInPx =
        width == null
            ? LayoutParams.MATCH_PARENT
            : Math.round(PixelUtil.toPixelFromDIP(width));
    view.setDrawerWidth(widthInPx);
  }
```

We need to be able to generate an interface method, that accepts a boxed `Float` value instead of the primitive `float` so that the native code can decide what value to use by default (`LayoutParams.MATCH_PARENT` in this case).

Reviewed By: rickhanlonii

Differential Revision: D17343172

fbshipit-source-id: 7662a4e0e495f58d05a92892f063535a359d09ae
2019-09-23 07:18:09 -07:00
Oleksandr Melnykov bf89d1d536 Allow null as default value for boolean props
Summary: Some props must have their default values set by native. To be able to support this, we have to introduce a `null` as a supported default value for some types. In this diff I'm adding support for `null` default values for boolean props. Check D17260168 for the example of the usage of the nullable boolean values.

Reviewed By: rickhanlonii, TheSavior

Differential Revision: D17258234

fbshipit-source-id: 63b7864be97856704d5964230526f23c0e395a67
2019-09-23 07:18:08 -07:00
Ramanpreet Nara 4c998fd05d Rename JSCallInvoker{,Holder} to CallInvoker{,Holder}
Summary:
## Motivation
The concept behind JSCallInvoker doesn't necessarily have to apply only to the JS thread. On Android, we need to re-use this abstraction to allow execution of async method calls on the NativeModules thread.

Reviewed By: PeteTheHeat

Differential Revision: D17377313

fbshipit-source-id: 3d9075cbfce0b908d800a366947cfd16a3013d1c
2019-09-20 10:52:56 -07:00
Samuel Susla c2d28074b3 Fix syntax errors in commands codegen
Summary:
I noticed two syntax errors in code gen while using it. This fixes them.
One of them is missing semicolon, the other one is name mismatch.

Reviewed By: TheSavior

Differential Revision: D17226188

fbshipit-source-id: 880dbf4c9b22efa7754de6413d01c04e7abbe411
2019-09-10 03:40:03 -07:00
Rick Hanlon 5048f02518 Add flow parser for array<array<object>>
Summary:
Adds support for parsing array of array of object flowtypes as:

```
type Props = $ReadOnly<{|
  someProp: $ReadOnlyArray<$ReadOnlyArray<$ReadOnly<{|foo: string|}>>
|}>;
```

Reviewed By: JoshuaGross

Differential Revision: D16936281

fbshipit-source-id: 5a8a4be0e4983554ddb6ddc27c49fa375c5f8a24
2019-09-06 06:04:17 -07:00
Rick Hanlon a7a1c8c5d3 Add generator for array<array<object>>
Summary: This diff adds support for generating native code for arrays of arrays of objects

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D16936272

fbshipit-source-id: 1543f8c1d5d9d4db28e4c7841ff7184ca0e417b3
2019-09-06 06:04:17 -07:00
Rick Hanlon 588ece23a0 Add fixture for array<array<object>>
Summary:
This diff adds a fixture for supporting arrays of arrays of objects, eventually parsable as:

`$ReadOnlyArray<$ReadOnlyArray<$ReadOnly<{|foo: string|}>>`

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D16936233

fbshipit-source-id: 14143522d82ad7d42e81605bb701890ca2731bed
2019-09-06 06:04:17 -07:00
Rick Hanlon c232b5ae3b Add e2e tests for int enums
Summary: This diff adds e2e tests for int enums

Reviewed By: JoshuaGross

Differential Revision: D17161728

fbshipit-source-id: 25003d9472d1df53931e9df8d42d5a68e9d11632
2019-09-06 05:33:08 -07:00
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