mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Add function properties to C++ TM complex datatyes (#41810)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41810 Changelog: [Internal] Reviewed By: zeyap Differential Revision: D51858746 fbshipit-source-id: e45ee68fc40e8b7ae3388ecdcedfec646d022e19
This commit is contained in:
1 parent
616a907798
commit
db609ff0c6
8 files changed
+280
-1
No files matched your search
@@ -169,6 +169,15 @@ void NativeCxxModuleExample::voidFunc(jsi::Runtime& rt) {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
void NativeCxxModuleExample::setMenu(jsi::Runtime& rt, MenuItem menuItem) {
|
||||
menuItem.onPress("value", true);
|
||||
if (menuItem.items) {
|
||||
for (auto subMenuItem : *menuItem.items) {
|
||||
subMenuItem.onPress("another value", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NativeCxxModuleExample::emitCustomDeviceEvent(
|
||||
jsi::Runtime& rt,
|
||||
jsi::String eventName) {
|
||||
|
||||
@@ -104,6 +104,17 @@ template <>
|
||||
struct Bridging<GraphNode>
|
||||
: NativeCxxModuleExampleCxxGraphNodeBridging<GraphNode> {};
|
||||
|
||||
#pragma mark - functional object properties
|
||||
|
||||
using MenuItem = NativeCxxModuleExampleCxxMenuItem<
|
||||
std::string,
|
||||
AsyncCallback<std::string, bool>,
|
||||
std::optional<std::string>>;
|
||||
|
||||
template <>
|
||||
struct Bridging<MenuItem>
|
||||
: NativeCxxModuleExampleCxxMenuItemBridging<MenuItem> {};
|
||||
|
||||
#pragma mark - implementation
|
||||
class NativeCxxModuleExample
|
||||
: public NativeCxxModuleExampleCxxSpec<NativeCxxModuleExample> {
|
||||
@@ -171,6 +182,8 @@ class NativeCxxModuleExample
|
||||
|
||||
void voidFunc(jsi::Runtime& rt);
|
||||
|
||||
void setMenu(jsi::Runtime& rt, MenuItem menuItem);
|
||||
|
||||
void emitCustomDeviceEvent(jsi::Runtime& rt, jsi::String eventName);
|
||||
|
||||
void voidFuncThrows(jsi::Runtime& rt);
|
||||
|
||||
@@ -67,6 +67,13 @@ export type GraphNode = {
|
||||
neighbors?: Array<GraphNode>,
|
||||
};
|
||||
|
||||
export type MenuItem = {
|
||||
label: string,
|
||||
onPress: (value: string, flag: boolean) => void,
|
||||
shortcut?: ?string,
|
||||
items?: Array<MenuItem>,
|
||||
};
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getArray: (arg: Array<ObjectStruct | null>) => Array<ObjectStruct | null>;
|
||||
+getBool: (arg: boolean) => boolean;
|
||||
@@ -92,6 +99,7 @@ export interface Spec extends TurboModule {
|
||||
+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;
|
||||
|
||||
Reference in new issue
Block a user