Skip to content

Commit

Permalink
Add more test coverage for $ReadOnlyArray<UnsafeMixed> in component c…
Browse files Browse the repository at this point in the history
…odegen (#49349)

Summary:
Pull Request resolved: #49349

Follow-up on D69454101 to add more test coverage for `$ReadOnlyArray<UnsafeMixed>` as a component prop. The new type was missing from the CodegenSchema, which revealed some gaps in tests.

Changelog: [Internal]

Reviewed By: fabriziocucci

Differential Revision: D69488035

fbshipit-source-id: 19895e55e5ec4d89a790f1c388de9eea025a316c
  • Loading branch information
javache authored and facebook-github-bot committed Feb 12, 2025
1 parent 96a8a3d commit 9073817
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/react-native-codegen/src/CodegenSchema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export type ComponentArrayTypeAnnotation = ArrayTypeAnnotation<
| DoubleTypeAnnotation
| FloatTypeAnnotation
| Int32TypeAnnotation
| MixedTypeAnnotation
| {
readonly type: 'StringEnumTypeAnnotation';
readonly default: string;
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-codegen/src/CodegenSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export type ComponentArrayTypeAnnotation = ArrayTypeAnnotation<
| DoubleTypeAnnotation
| FloatTypeAnnotation
| Int32TypeAnnotation
| MixedTypeAnnotation
| $ReadOnly<{
type: 'StringEnumTypeAnnotation',
default: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type PojoTypeAnnotation =
| DoubleTypeAnnotation
| FloatTypeAnnotation
| Int32TypeAnnotation
| MixedTypeAnnotation
| $ReadOnly<{
type: 'StringEnumTypeAnnotation',
default: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ function toJavaType(
case 'Int32TypeAnnotation': {
return 'Integer';
}
case 'MixedTypeAnnotation': {
importDynamic();
return 'Dynamic';
}

/**
* Enums
Expand Down Expand Up @@ -214,7 +218,7 @@ function toJavaType(
default: {
(elementType.type: empty);
throw new Error(
`Unrecognized PojoTypeAnnotation Array element type annotation '${typeAnnotation.type}'`,
`Unrecognized PojoTypeAnnotation Array element type annotation '${elementType.type}'`,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,16 @@ const ARRAY_PROPS: SchemaType = {
},
},
},
{
name: 'arrayOfMixed',
optional: true,
typeAnnotation: {
type: 'ArrayTypeAnnotation',
elementType: {
type: 'MixedTypeAnnotation',
},
},
},
],
commands: [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ ArrayPropsNativeComponentProps::ArrayPropsNativeComponentProps(
sizes(convertRawProp(context, rawProps, \\"sizes\\", ArrayPropsNativeComponentSizesMaskWrapped{ .value = sourceProps.sizes }, {static_cast<ArrayPropsNativeComponentSizesMask>(ArrayPropsNativeComponentSizes::Small)}).value),
object(convertRawProp(context, rawProps, \\"object\\", sourceProps.object, {})),
array(convertRawProp(context, rawProps, \\"array\\", sourceProps.array, {})),
arrayOfArrayOfObject(convertRawProp(context, rawProps, \\"arrayOfArrayOfObject\\", sourceProps.arrayOfArrayOfObject, {}))
arrayOfArrayOfObject(convertRawProp(context, rawProps, \\"arrayOfArrayOfObject\\", sourceProps.arrayOfArrayOfObject, {})),
arrayOfMixed(convertRawProp(context, rawProps, \\"arrayOfMixed\\", sourceProps.arrayOfMixed, {}))
{}
} // namespace facebook::react
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class ArrayPropsNativeComponentProps final : public ViewProps {
std::vector<ArrayPropsNativeComponentObjectStruct> object{};
std::vector<ArrayPropsNativeComponentArrayStruct> array{};
std::vector<std::vector<ArrayPropsNativeComponentArrayOfArrayOfObjectStruct>> arrayOfArrayOfObject{};
std::vector<folly::dynamic> arrayOfMixed{};
};
} // namespace facebook::react
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class ArrayPropsNativeComponentManagerDelegate<T extends View, U extends
case \\"arrayOfArrayOfObject\\":
mViewManager.setArrayOfArrayOfObject(view, (ReadableArray) value);
break;
case \\"arrayOfMixed\\":
mViewManager.setArrayOfMixed(view, (ReadableArray) value);
break;
default:
super.setProperty(view, propName, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public interface ArrayPropsNativeComponentManagerInterface<T extends View> exten
void setObject(T view, @Nullable ReadableArray value);
void setArray(T view, @Nullable ReadableArray value);
void setArrayOfArrayOfObject(T view, @Nullable ReadableArray value);
void setArrayOfMixed(T view, @Nullable ReadableArray value);
}
",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class ArrayPropsNativeComponentPropsArrayOfArrayOfObjectElementElement {
package com.facebook.react.viewmanagers.Slider;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.yoga.YogaValue;
import java.util.ArrayList;
Expand All @@ -124,6 +125,7 @@ public class ArrayPropsNativeComponentProps {
private ArrayList<ArrayPropsNativeComponentPropsObjectElement> mObject;
private ArrayList<ArrayPropsNativeComponentPropsArrayElement> mArray;
private ArrayList<ArrayList<ArrayPropsNativeComponentPropsArrayOfArrayOfObjectElementElement>> mArrayOfArrayOfObject;
private ArrayList<Dynamic> mArrayOfMixed;
@DoNotStrip
public ArrayList<String> getNames() {
return mNames;
Expand Down Expand Up @@ -172,6 +174,10 @@ public class ArrayPropsNativeComponentProps {
public ArrayList<ArrayList<ArrayPropsNativeComponentPropsArrayOfArrayOfObjectElementElement>> getArrayOfArrayOfObject() {
return mArrayOfArrayOfObject;
}
@DoNotStrip
public ArrayList<Dynamic> getArrayOfMixed() {
return mArrayOfMixed;
}
}
",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const __INTERNAL_VIEW_CONFIG = {
object: true,
array: true,
arrayOfArrayOfObject: true,
arrayOfMixed: true,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@ type ModuleProps = $ReadOnly<{|
array_object_optional_value: ?ArrayObjectType,
array_object_optional_both?: ?$ReadOnlyArray<ObjectType>,
// UnsafeMixed props
array_mixed_required: $ReadOnlyArray<UnsafeMixed>,
array_mixed_optional_key?: $ReadOnlyArray<UnsafeMixed>,
array_mixed_optional_value: ?$ReadOnlyArray<UnsafeMixed>,
array_mixed_optional_both?: ?$ReadOnlyArray<UnsafeMixed>,
// Nested array object types
array_of_array_object_required: $ReadOnlyArray<
$ReadOnly<{|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,46 @@ exports[`RN Codegen Flow Parser can generate fixture ARRAY_PROP_TYPES_NO_EVENTS
}
}
},
{
'name': 'array_mixed_required',
'optional': false,
'typeAnnotation': {
'type': 'ArrayTypeAnnotation',
'elementType': {
'type': 'MixedTypeAnnotation'
}
}
},
{
'name': 'array_mixed_optional_key',
'optional': true,
'typeAnnotation': {
'type': 'ArrayTypeAnnotation',
'elementType': {
'type': 'MixedTypeAnnotation'
}
}
},
{
'name': 'array_mixed_optional_value',
'optional': true,
'typeAnnotation': {
'type': 'ArrayTypeAnnotation',
'elementType': {
'type': 'MixedTypeAnnotation'
}
}
},
{
'name': 'array_mixed_optional_both',
'optional': true,
'typeAnnotation': {
'type': 'ArrayTypeAnnotation',
'elementType': {
'type': 'MixedTypeAnnotation'
}
}
},
{
'name': 'array_of_array_object_required',
'optional': false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ const ARRAY_PROP_TYPES_NO_EVENTS = `
const codegenNativeComponent = require('codegenNativeComponent');
import type {Int32, Double, Float, WithDefault} from 'CodegenTypes';
import type {Int32, Double, Float, UnsafeMixed, WithDefault} from 'CodegenTypes';
import type {ImageSource} from 'ImageSource';
import type {
ColorValue,
Expand Down Expand Up @@ -479,6 +479,12 @@ export interface ModuleProps extends ViewProps {
array_object_optional_value: ArrayObjectType | null | undefined;
array_object_optional_both?: ReadonlyArray<ObjectType> | null | undefined;
// UnsafeMixed props
array_mixed_required: ReadonlyArray<UnsafeMixed>;
array_mixed_optional_key?: ReadonlyArray<UnsafeMixed>;
array_mixed_optional_value: ReadonlyArray<UnsafeMixed> | null | undefined;
array_mixed_optional_both?: ReadonlyArray<UnsafeMixed> | null | undefined;
// Nested array object types
array_of_array_object_required: ReadonlyArray<
Readonly<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,46 @@ exports[`RN Codegen TypeScript Parser can generate fixture ARRAY_PROP_TYPES_NO_E
}
}
},
{
'name': 'array_mixed_required',
'optional': false,
'typeAnnotation': {
'type': 'ArrayTypeAnnotation',
'elementType': {
'type': 'MixedTypeAnnotation'
}
}
},
{
'name': 'array_mixed_optional_key',
'optional': true,
'typeAnnotation': {
'type': 'ArrayTypeAnnotation',
'elementType': {
'type': 'MixedTypeAnnotation'
}
}
},
{
'name': 'array_mixed_optional_value',
'optional': true,
'typeAnnotation': {
'type': 'ArrayTypeAnnotation',
'elementType': {
'type': 'MixedTypeAnnotation'
}
}
},
{
'name': 'array_mixed_optional_both',
'optional': true,
'typeAnnotation': {
'type': 'ArrayTypeAnnotation',
'elementType': {
'type': 'MixedTypeAnnotation'
}
}
},
{
'name': 'array_of_array_object_required',
'optional': false,
Expand Down

0 comments on commit 9073817

Please sign in to comment.