mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
536edf3726
Summary: Changelog: [General][BREAKING] Don't support 'float' enums in Turbo Modules - The current implementation of 'float enums' in C++ does not work as invalid results are returned. - At potential fix could still cause rounding errors when crossing language bounaries, e.g. `4.6` can become `4.5599999942..` - C++ enum classes don't support float: https://eel.is/c++draft/dcl.enum#2.sentence-4 > The type-specifier-seq of an enum-base shall name an integral type; any cv-qualification is ignored. Hence removing the feature of `float enums` for now Reviewed By: NickGerleman Differential Revision: D52120405 fbshipit-source-id: 3685ad0629e16ff9db424ba67e07d09df6027553
116 lines
3.0 KiB
JavaScript
116 lines
3.0 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
*/
|
|
|
|
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
|
|
|
|
import {TurboModuleRegistry} from 'react-native';
|
|
|
|
export enum EnumInt {
|
|
IA = 23,
|
|
IB = 42,
|
|
}
|
|
|
|
export enum EnumNone {
|
|
NA,
|
|
NB,
|
|
}
|
|
|
|
export enum EnumStr {
|
|
SA = 's---a',
|
|
SB = 's---b',
|
|
}
|
|
|
|
export type UnionFloat = 1.44 | 2.88 | 5.76;
|
|
export type UnionString = 'One' | 'Two' | 'Three';
|
|
export type UnionObject = {value: number} | {low: string};
|
|
|
|
export type ConstantsStruct = {
|
|
const1: boolean,
|
|
const2: number,
|
|
const3: string,
|
|
};
|
|
|
|
export type ObjectStruct = {
|
|
a: number,
|
|
b: string,
|
|
c?: ?string,
|
|
};
|
|
|
|
export type ValueStruct = {
|
|
x: number,
|
|
y: string,
|
|
z: ObjectStruct,
|
|
};
|
|
|
|
export type CustomHostObject = {};
|
|
|
|
export type BinaryTreeNode = {
|
|
left?: BinaryTreeNode,
|
|
value: number,
|
|
right?: BinaryTreeNode,
|
|
};
|
|
|
|
export type GraphNode = {
|
|
label: string,
|
|
neighbors?: Array<GraphNode>,
|
|
};
|
|
|
|
export type MenuItem = {
|
|
label: string,
|
|
onPress: (value: string, flag: boolean) => void,
|
|
shortcut?: ?string,
|
|
items?: Array<MenuItem>,
|
|
};
|
|
|
|
export type CustomDeviceEvent = {
|
|
type: string,
|
|
level: number,
|
|
degree?: ?number,
|
|
};
|
|
|
|
export interface Spec extends TurboModule {
|
|
+getArray: (arg: Array<ObjectStruct | null>) => Array<ObjectStruct | null>;
|
|
+getBool: (arg: boolean) => boolean;
|
|
+getConstants: () => ConstantsStruct;
|
|
+getCustomEnum: (arg: EnumInt) => EnumInt;
|
|
+getCustomHostObject: () => CustomHostObject;
|
|
+consumeCustomHostObject: (customHostObject: CustomHostObject) => string;
|
|
+getBinaryTreeNode: (arg: BinaryTreeNode) => BinaryTreeNode;
|
|
+getGraphNode: (arg: GraphNode) => GraphNode;
|
|
+getNumEnum: (arg: EnumInt) => EnumInt;
|
|
+getStrEnum: (arg: EnumNone) => EnumStr;
|
|
+getMap: (arg: {[key: string]: ?number}) => {[key: string]: ?number};
|
|
+getNumber: (arg: number) => number;
|
|
+getObject: (arg: ObjectStruct) => ObjectStruct;
|
|
+getSet: (arg: Array<number>) => Array<number>;
|
|
+getString: (arg: string) => string;
|
|
+getUnion: (x: UnionFloat, y: UnionString, z: UnionObject) => string;
|
|
+getValue: (x: number, y: string, z: ObjectStruct) => ValueStruct;
|
|
+getValueWithCallback: (callback: (value: string) => void) => void;
|
|
+setValueCallbackWithSubscription: (
|
|
callback: (value: string) => void,
|
|
) => () => void;
|
|
+getValueWithPromise: (error: boolean) => Promise<string>;
|
|
+getWithWithOptionalArgs: (optionalArg?: boolean) => ?boolean;
|
|
+voidFunc: () => void;
|
|
+setMenu: (menuItem: MenuItem) => void;
|
|
+emitCustomDeviceEvent: (eventName: string) => void;
|
|
+voidFuncThrows: () => void;
|
|
+getObjectThrows: (arg: ObjectStruct) => ObjectStruct;
|
|
+promiseThrows: () => Promise<void>;
|
|
+voidFuncAssert: () => void;
|
|
+getObjectAssert: (arg: ObjectStruct) => ObjectStruct;
|
|
+promiseAssert: () => Promise<void>;
|
|
}
|
|
|
|
export default (TurboModuleRegistry.get<Spec>(
|
|
'NativeCxxModuleExampleCxx',
|
|
): ?Spec);
|