Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 84 additions & 79 deletions packages/react-native-codegen/src/generators/ReservedPrimitiveTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,99 +28,104 @@ export type ReservedPrimitiveName =
| 'DimensionPrimitive';

type CppTypeInfo = {
+typeName: string,
+localIncludes: ReadonlyArray<string>,
+conversionIncludes: ReadonlyArray<string>,
readonly typeName: string,
readonly localIncludes: ReadonlyArray<string>,
readonly conversionIncludes: ReadonlyArray<string>,
};

type JavaImportInfo = {
+interfaceImports: ReadonlyArray<string>,
+delegateImports: ReadonlyArray<string>,
readonly interfaceImports: ReadonlyArray<string>,
readonly delegateImports: ReadonlyArray<string>,
};

type ReservedTypeMapping = {
+cpp: CppTypeInfo,
+java: JavaImportInfo,
readonly cpp: CppTypeInfo,
readonly java: JavaImportInfo,
};

const RESERVED_TYPES: {+[ReservedPrimitiveName]: ReservedTypeMapping} = {
ColorPrimitive: {
cpp: {
typeName: 'SharedColor',
localIncludes: ['#include <react/renderer/graphics/Color.h>'],
conversionIncludes: [],
const RESERVED_TYPES: {readonly [ReservedPrimitiveName]: ReservedTypeMapping} =
{
ColorPrimitive: {
cpp: {
typeName: 'SharedColor',
localIncludes: ['#include <react/renderer/graphics/Color.h>'],
conversionIncludes: [],
},
java: {
interfaceImports: [],
delegateImports: [
'import com.facebook.react.bridge.ColorPropConverter;',
],
},
},
java: {
interfaceImports: [],
delegateImports: ['import com.facebook.react.bridge.ColorPropConverter;'],
ImageSourcePrimitive: {
cpp: {
typeName: 'ImageSource',
localIncludes: ['#include <react/renderer/imagemanager/primitives.h>'],
conversionIncludes: [
'#include <react/renderer/components/image/conversions.h>',
],
},
java: {
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
},
},
},
ImageSourcePrimitive: {
cpp: {
typeName: 'ImageSource',
localIncludes: ['#include <react/renderer/imagemanager/primitives.h>'],
conversionIncludes: [
'#include <react/renderer/components/image/conversions.h>',
],
ImageRequestPrimitive: {
cpp: {
typeName: 'ImageRequest',
localIncludes: [
'#include <react/renderer/imagemanager/ImageRequest.h>',
],
conversionIncludes: [],
},
java: {
// ImageRequestPrimitive is not used in Java component props
interfaceImports: [],
delegateImports: [],
},
},
java: {
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
PointPrimitive: {
cpp: {
typeName: 'Point',
localIncludes: ['#include <react/renderer/graphics/Point.h>'],
conversionIncludes: [],
},
java: {
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
},
},
},
ImageRequestPrimitive: {
cpp: {
typeName: 'ImageRequest',
localIncludes: ['#include <react/renderer/imagemanager/ImageRequest.h>'],
conversionIncludes: [],
EdgeInsetsPrimitive: {
cpp: {
typeName: 'EdgeInsets',
localIncludes: ['#include <react/renderer/graphics/RectangleEdges.h>'],
conversionIncludes: [],
},
java: {
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
},
},
java: {
// ImageRequestPrimitive is not used in Java component props
interfaceImports: [],
delegateImports: [],
DimensionPrimitive: {
cpp: {
typeName: 'YGValue',
localIncludes: [
'#include <yoga/Yoga.h>',
'#include <react/renderer/core/graphicsConversions.h>',
],
conversionIncludes: [
'#include <react/renderer/components/view/conversions.h>',
],
},
java: {
interfaceImports: ['import com.facebook.yoga.YogaValue;'],
delegateImports: [
'import com.facebook.react.bridge.DimensionPropConverter;',
],
},
},
},
PointPrimitive: {
cpp: {
typeName: 'Point',
localIncludes: ['#include <react/renderer/graphics/Point.h>'],
conversionIncludes: [],
},
java: {
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
},
},
EdgeInsetsPrimitive: {
cpp: {
typeName: 'EdgeInsets',
localIncludes: ['#include <react/renderer/graphics/RectangleEdges.h>'],
conversionIncludes: [],
},
java: {
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
},
},
DimensionPrimitive: {
cpp: {
typeName: 'YGValue',
localIncludes: [
'#include <yoga/Yoga.h>',
'#include <react/renderer/core/graphicsConversions.h>',
],
conversionIncludes: [
'#include <react/renderer/components/view/conversions.h>',
],
},
java: {
interfaceImports: ['import com.facebook.yoga.YogaValue;'],
delegateImports: [
'import com.facebook.react.bridge.DimensionPropConverter;',
],
},
},
};
};

function getCppTypeForReservedPrimitive(name: ReservedPrimitiveName): string {
return RESERVED_TYPES[name].cpp.typeName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ function getNativeTypeFromAnnotation(
| ObjectTypeAnnotation<PropTypeAnnotation>
| ReservedPropTypeAnnotation
| {
+default: string,
+options: ReadonlyArray<string>,
+type: 'StringEnumTypeAnnotation',
readonly default: string,
readonly options: ReadonlyArray<string>,
readonly type: 'StringEnumTypeAnnotation',
}
| {
+elementType: ObjectTypeAnnotation<PropTypeAnnotation>,
+type: 'ArrayTypeAnnotation',
readonly elementType: ObjectTypeAnnotation<PropTypeAnnotation>,
readonly type: 'ArrayTypeAnnotation',
},
},
nameParts: ReadonlyArray<string>,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-codegen/src/parsers/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class UnsupportedModulePropertyParserError extends ParserError {
}

class UnsupportedTypeAnnotationParserError extends ParserError {
+typeAnnotationType: string;
readonly typeAnnotationType: string;
constructor(
nativeModuleName: string,
typeAnnotation: $FlowFixMe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,53 +91,83 @@ type CustomObj = {foo: string, bar: number};
type CustomObj2 = {a: Int32, b: string};

interface NativeCommands {
+methodInt: (viewRef: React.ElementRef<NativeType>, a: Int32) => void;
+methodIntString: (
readonly methodInt: (viewRef: React.ElementRef<NativeType>, a: Int32) => void;
readonly methodIntString: (
viewRef: React.ElementRef<NativeType>,
a: Int32,
b: string,
) => void;
+methodString: (viewRef: React.ElementRef<NativeType>, a: string) => void;
+methodBool: (viewRef: React.ElementRef<NativeType>, a: boolean) => void;
+methodFloat: (viewRef: React.ElementRef<NativeType>, a: Float) => void;
+methodDouble: (viewRef: React.ElementRef<NativeType>, a: Double) => void;
readonly methodString: (
viewRef: React.ElementRef<NativeType>,
a: string,
) => void;
readonly methodBool: (
viewRef: React.ElementRef<NativeType>,
a: boolean,
) => void;
readonly methodFloat: (
viewRef: React.ElementRef<NativeType>,
a: Float,
) => void;
readonly methodDouble: (
viewRef: React.ElementRef<NativeType>,
a: Double,
) => void;

+methodIntAlias: (viewRef: React.ElementRef<NativeType>, a: Int) => void;
+methodStringAlias: (viewRef: React.ElementRef<NativeType>, a: Str) => void;
+methodBoolAlias: (viewRef: React.ElementRef<NativeType>, a: Bool) => void;
+methodFloatAlias: (viewRef: React.ElementRef<NativeType>, a: Fl) => void;
+methodDoubleAlias: (viewRef: React.ElementRef<NativeType>, a: Dbl) => void;
readonly methodIntAlias: (
viewRef: React.ElementRef<NativeType>,
a: Int,
) => void;
readonly methodStringAlias: (
viewRef: React.ElementRef<NativeType>,
a: Str,
) => void;
readonly methodBoolAlias: (
viewRef: React.ElementRef<NativeType>,
a: Bool,
) => void;
readonly methodFloatAlias: (
viewRef: React.ElementRef<NativeType>,
a: Fl,
) => void;
readonly methodDoubleAlias: (
viewRef: React.ElementRef<NativeType>,
a: Dbl,
) => void;

+methodIntArray: (
readonly methodIntArray: (
viewRef: React.ElementRef<NativeType>,
a: Array<Int32>,
) => void;
+methodStringArray: (
readonly methodStringArray: (
viewRef: React.ElementRef<NativeType>,
a: Array<string>,
) => void;
+methodBoolArray: (
readonly methodBoolArray: (
viewRef: React.ElementRef<NativeType>,
a: Array<boolean>,
) => void;
+methodFloatArray: (
readonly methodFloatArray: (
viewRef: React.ElementRef<NativeType>,
a: Array<Float>,
) => void;
+methodDoubleArray: (
readonly methodDoubleArray: (
viewRef: React.ElementRef<NativeType>,
a: Array<Double>,
) => void;
+methodCustomObjArray: (
readonly methodCustomObjArray: (
viewRef: React.ElementRef<NativeType>,
a: Array<CustomObj>,
) => void;
+methodCustomObj2Array: (
readonly methodCustomObj2Array: (
viewRef: React.ElementRef<NativeType>,
a: Array<CustomObj2>,
) => void;

+methodRootTag: (viewRef: React.ElementRef<NativeType>, a: RootTag) => void;
readonly methodRootTag: (
viewRef: React.ElementRef<NativeType>,
a: RootTag,
) => void;
}

export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@ type NativeProps = Readonly<{
type NativeType = HostComponent<NativeProps>;

interface NativeCommands {
+methodInt: (viewRef: React.ElementRef<NativeType>, a: Array<Int32>) => void;
+methodString: (
readonly methodInt: (
viewRef: React.ElementRef<NativeType>,
a: Array<Int32>,
) => void;
readonly methodString: (
viewRef: React.ElementRef<NativeType>,
a: Array<string>,
) => void;
+methodBool: (
readonly methodBool: (
viewRef: React.ElementRef<NativeType>,
a: Array<boolean>,
) => void;
+methodFloat: (
readonly methodFloat: (
viewRef: React.ElementRef<NativeType>,
a: Array<Float>,
) => void;
+methodDouble: (
readonly methodDouble: (
viewRef: React.ElementRef<NativeType>,
a: Array<Double>,
) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,23 @@ type NativeProps = Readonly<{
type NativeType = HostComponent<NativeProps>;

interface NativeCommands {
+methodInt: (viewRef: React.ElementRef<NativeType>, a: Int32) => void;
+methodString: (viewRef: React.ElementRef<NativeType>, a: string) => void;
+methodBool: (viewRef: React.ElementRef<NativeType>, a: boolean) => void;
+methodFloat: (viewRef: React.ElementRef<NativeType>, a: Float) => void;
+methodDouble: (viewRef: React.ElementRef<NativeType>, a: Double) => void;
readonly methodInt: (viewRef: React.ElementRef<NativeType>, a: Int32) => void;
readonly methodString: (
viewRef: React.ElementRef<NativeType>,
a: string,
) => void;
readonly methodBool: (
viewRef: React.ElementRef<NativeType>,
a: boolean,
) => void;
readonly methodFloat: (
viewRef: React.ElementRef<NativeType>,
a: Float,
) => void;
readonly methodDouble: (
viewRef: React.ElementRef<NativeType>,
a: Double,
) => void;
}

export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ type NativeProps = Readonly<{
type NativeType = HostComponent<NativeProps>;

interface NativeCommands {
+methodInt: (viewRef: React.ElementRef<NativeType>, a: string) => void;
readonly methodInt: (
viewRef: React.ElementRef<NativeType>,
a: string,
) => void;
}

export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type NativeProps = Readonly<{
type NativeType = HostComponent<NativeProps>;

interface NativeCommands {
+methodInt: (
readonly methodInt: (
viewRef: React.ElementRef<NativeType>,
a: Int32,
b: string,
Expand Down
Loading
Loading