-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
RNTabItem.ts
72 lines (67 loc) · 1.72 KB
/
RNTabItem.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { QWidget, QIcon, Component } from "@nodegui/nodegui";
import { RNComponent, RNProps } from "../config";
import { RNTab } from "../Tab/RNTab";
export interface TabItemProps {
title?: string;
icon?: QIcon;
}
/**
* @ignore
*/
export const setTabItemProps = (
tabItem: RNTabItem,
parentTab: RNTab,
newProps: TabItemProps,
oldProps: TabItemProps
) => {
if (!tabItem.actualTabWidget) {
return;
}
const tabIndex = parentTab.indexOf(tabItem.actualTabWidget);
if (tabIndex < 0) {
console.error("TabItem is not part of the parent tab it references to");
return;
}
const setter: TabItemProps = {
set title(text: string) {
parentTab.setTabText(tabIndex, text);
},
set icon(qicon: QIcon) {
parentTab.setTabIcon(tabIndex, qicon);
}
};
Object.assign(setter, newProps);
};
/**
* @ignore
*/
export class RNTabItem extends Component implements RNComponent {
native: any;
actualTabWidget?: QWidget<any>;
initialProps: TabItemProps = {};
parentTab?: RNTab;
setProps(newProps: TabItemProps, oldProps: TabItemProps): void {
if (this.parentTab) {
setTabItemProps(this, this.parentTab, newProps, oldProps);
} else {
this.initialProps = newProps;
}
}
appendInitialChild(child: QWidget<any>): void {
if (this.actualTabWidget) {
throw new Error("Tab Item can have only one child");
}
this.actualTabWidget = child;
}
appendChild(child: QWidget<any>): void {
this.appendInitialChild(child);
}
insertBefore(child: QWidget<any>, beforeChild: QWidget<any>): void {
this.appendInitialChild(child);
}
removeChild(child: QWidget<any>): void {
child.close();
delete this.actualTabWidget;
}
static tagName: string = "tabitem";
}