Skip to content

Commit 925b153

Browse files
Riccardo Cipolleschifacebook-github-bot
Riccardo Cipolleschi
authored andcommitted
Parse custom NativeState in Flow (#34753)
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
1 parent 5e79fa8 commit 925b153

File tree

10 files changed

+4228
-1274
lines changed

10 files changed

+4228
-1274
lines changed

packages/react-native-codegen/src/CodegenSchema.js

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export type ComponentShape = $ReadOnly<{
8080
events: $ReadOnlyArray<EventTypeShape>,
8181
props: $ReadOnlyArray<NamedShape<PropTypeAnnotation>>,
8282
commands: $ReadOnlyArray<NamedShape<CommandTypeAnnotation>>,
83+
state?: $ReadOnlyArray<NamedShape<StateTypeAnnotation>>,
8384
}>;
8485

8586
export type OptionsShape = $ReadOnly<{
@@ -185,6 +186,8 @@ export type ReservedPropTypeAnnotation = $ReadOnly<{
185186
| 'EdgeInsetsPrimitive',
186187
}>;
187188

189+
export type StateTypeAnnotation = PropTypeAnnotation;
190+
188191
export type CommandTypeAnnotation = FunctionTypeAnnotation<
189192
CommandParamTypeAnnotation,
190193
VoidTypeAnnotation,

packages/react-native-codegen/src/parsers/consistency/__tests__/checkComponentSnaps-test.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@ const {compareSnaps, compareTsArraySnaps} = require('../compareSnaps.js');
1414

1515
const flowFixtures = require('../../flow/components/__test_fixtures__/fixtures.js');
1616
const flowSnaps = require('../../../../src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap');
17-
const flowExtraCases = [];
17+
const flowExtraCases = [
18+
//TODO: remove these once we implement TypeScript parser for Custom State
19+
'ALL_STATE_TYPES',
20+
'ARRAY_STATE_TYPES',
21+
'COMMANDS_EVENTS_STATE_TYPES_EXPORTED',
22+
'OBJECT_STATE_TYPES',
23+
];
1824
const tsFixtures = require('../../typescript/components/__test_fixtures__/fixtures.js');
1925
const tsSnaps = require('../../../../src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap');
20-
const tsExtraCases = ['ARRAY2_PROP_TYPES_NO_EVENTS'];
26+
const tsExtraCases = ['ARRAY2_PROP_TYPES_NO_EVENTS'].concat([
27+
//TODO: remove these once we implement TypeScript parser for Custom State
28+
'COMMANDS_AND_EVENTS_TYPES_EXPORTED',
29+
]);
2130
const ignoredCases = ['ARRAY_PROP_TYPES_NO_EVENTS'];
2231

2332
compareSnaps(

0 commit comments

Comments
 (0)