Commit Graph

103 Commits

Author SHA1 Message Date
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 https://github.com/facebook/react-native/commit/c7ee38149d02b64bae6aadcc72c4f664900ff0cb

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 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 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
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