|
| 1 | +import { FlexLayout, QListWidget, QListWidgetSignals } from "@nodegui/nodegui"; |
| 2 | +import { ViewProps, setViewProps } from "../View/RNView"; |
| 3 | +import { RNComponent } from "../config"; |
| 4 | +import { RNListItem } from "../ListItem/RNListItem"; |
| 5 | + |
| 6 | + |
| 7 | +export interface ListProps extends ViewProps<QListWidgetSignals> { |
| 8 | +} |
| 9 | + |
| 10 | +type CustomListProps = ListProps; |
| 11 | + |
| 12 | + |
| 13 | +/** |
| 14 | + * @ignore |
| 15 | + */ |
| 16 | +export const setListProps = (widget: RNList, newProps: CustomListProps, oldProps: CustomListProps) => { |
| 17 | + |
| 18 | + const setter: CustomListProps = { |
| 19 | + }; |
| 20 | + Object.assign(setter, newProps); |
| 21 | + setViewProps(widget, newProps, oldProps); |
| 22 | +}; |
| 23 | + |
| 24 | +/** |
| 25 | + * @ignore |
| 26 | + */ |
| 27 | +export class RNList extends QListWidget implements RNComponent { |
| 28 | + setProps(newProps: CustomListProps, oldProps: CustomListProps): void { |
| 29 | + setListProps(this, newProps, oldProps); |
| 30 | + } |
| 31 | + removeChild(child: RNListItem): void { |
| 32 | + const row = this.row(child); |
| 33 | + this.takeItem(row); |
| 34 | + } |
| 35 | + appendInitialChild(child: RNListItem): void { |
| 36 | + this.appendChild(child); |
| 37 | + } |
| 38 | + appendChild(child: RNListItem): void { |
| 39 | + if (!this.layout) { |
| 40 | + this.setLayout(new FlexLayout()); |
| 41 | + } |
| 42 | + |
| 43 | + if (!(child instanceof RNListItem)) { |
| 44 | + throw new Error("Children of list should be of type ListItem"); |
| 45 | + } |
| 46 | + |
| 47 | + this.addItem(child); |
| 48 | + if (child.actualListItemWidget) { |
| 49 | + child.setSizeHint(child.actualListItemWidget.size()); |
| 50 | + this.setItemWidget(child, child.actualListItemWidget); |
| 51 | + } |
| 52 | + } |
| 53 | + insertBefore(child: RNListItem, beforeChild: RNListItem): void { |
| 54 | + const row = this.row(beforeChild); |
| 55 | + this.insertItem(row, child); |
| 56 | + } |
| 57 | + static tagName = "list"; |
| 58 | +} |
0 commit comments