Skip to content

Commit

Permalink
Parse custom NativeState in Flow (#34753)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #34753

This Diff introduce a the capability to parse custom NativeStates in Flow. To achieve this I also had to define the CodegenSchema.

The parsing follows the exact same rules as props, as initial heuristic. This should allow enough customization for the developers who needs a custom state.

There is only a case I was not able to make it work that is STATE_ALIASED_LOCALLY, from the fixtures. I don't know how diffuse it is and I think we can live with some workarounds for the time being.

This diff also adds tests for the custom Native State Flow Parser.

## Changelog
[General][Added] - Implement custom Native State parsing in Flow

Reviewed By: cortinico

Differential Revision: D39686251

fbshipit-source-id: 446997a39b33b7e9351d5ba12cecaeff33df4d16
  • Loading branch information
Riccardo Cipolleschi authored and facebook-github-bot committed Sep 26, 2022
1 parent 5e79fa8 commit 925b153
Show file tree
Hide file tree
Showing 10 changed files with 4,228 additions and 1,274 deletions.
3 changes: 3 additions & 0 deletions packages/react-native-codegen/src/CodegenSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type ComponentShape = $ReadOnly<{
events: $ReadOnlyArray<EventTypeShape>,
props: $ReadOnlyArray<NamedShape<PropTypeAnnotation>>,
commands: $ReadOnlyArray<NamedShape<CommandTypeAnnotation>>,
state?: $ReadOnlyArray<NamedShape<StateTypeAnnotation>>,
}>;

export type OptionsShape = $ReadOnly<{
Expand Down Expand Up @@ -185,6 +186,8 @@ export type ReservedPropTypeAnnotation = $ReadOnly<{
| 'EdgeInsetsPrimitive',
}>;

export type StateTypeAnnotation = PropTypeAnnotation;

export type CommandTypeAnnotation = FunctionTypeAnnotation<
CommandParamTypeAnnotation,
VoidTypeAnnotation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ const {compareSnaps, compareTsArraySnaps} = require('../compareSnaps.js');

const flowFixtures = require('../../flow/components/__test_fixtures__/fixtures.js');
const flowSnaps = require('../../../../src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap');
const flowExtraCases = [];
const flowExtraCases = [
//TODO: remove these once we implement TypeScript parser for Custom State
'ALL_STATE_TYPES',
'ARRAY_STATE_TYPES',
'COMMANDS_EVENTS_STATE_TYPES_EXPORTED',
'OBJECT_STATE_TYPES',
];
const tsFixtures = require('../../typescript/components/__test_fixtures__/fixtures.js');
const tsSnaps = require('../../../../src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap');
const tsExtraCases = ['ARRAY2_PROP_TYPES_NO_EVENTS'];
const tsExtraCases = ['ARRAY2_PROP_TYPES_NO_EVENTS'].concat([
//TODO: remove these once we implement TypeScript parser for Custom State
'COMMANDS_AND_EVENTS_TYPES_EXPORTED',
]);
const ignoredCases = ['ARRAY_PROP_TYPES_NO_EVENTS'];

compareSnaps(
Expand Down

0 comments on commit 925b153

Please sign in to comment.