Commit Graph

117 Commits

Author SHA1 Message Date
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
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
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