-
-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathRNMenu.ts
49 lines (45 loc) · 1.29 KB
/
RNMenu.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { QMenu, QMenuSignals, Component, QWidget } from "@nodegui/nodegui";
import { RNWidget } from "../config";
import { throwUnsupported } from "../../utils/helpers";
import { RNAction } from "../Action/RNAction";
import { setViewProps, ViewProps } from "../View/RNView";
export interface MenuProps extends ViewProps<QMenuSignals> {
title?: string;
}
const setMenuProps = (
widget: RNMenu,
newProps: MenuProps,
oldProps: MenuProps
) => {
const setter: MenuProps = {
set title(title: string) {
widget.setTitle(title);
},
};
Object.assign(setter, newProps);
setViewProps(widget, newProps, oldProps);
};
export class RNMenu extends QMenu implements RNWidget {
setProps(newProps: MenuProps, oldProps: MenuProps): void {
setMenuProps(this, newProps, oldProps);
}
appendInitialChild(child: Component): void {
this.appendChild(child);
}
appendChild(child: Component): void {
if (!(child instanceof RNAction)) {
console.warn("Menu only supports Action as its children");
return;
}
this.addAction(child);
}
insertBefore(child: Component, beforeChild: Component): void {
throwUnsupported(this);
}
removeChild(child: Component): void {
if (child instanceof RNAction) {
this.removeAction(child);
}
}
static tagName = "menu";
}