diff --git a/src/components/BoxView/RNBoxView.ts b/src/components/BoxView/RNBoxView.ts index d748fae..9cc7e45 100644 --- a/src/components/BoxView/RNBoxView.ts +++ b/src/components/BoxView/RNBoxView.ts @@ -7,6 +7,7 @@ import { } from "@nodegui/nodegui"; import { ViewProps, setViewProps } from "../View/RNView"; import { RNComponent } from "../config"; +import { NodeDialog } from "@nodegui/nodegui/dist/lib/QtWidgets/QDialog"; export interface BoxViewProps extends ViewProps { direction?: Direction; @@ -50,6 +51,9 @@ export class RNBoxView extends QWidget implements RNComponent { this.appendChild(child); } appendChild(child: NodeWidget): void { + if (child instanceof NodeDialog) { + return; + } const updateChild = () => { this.layout?.addWidget(child); this.children.push(child); @@ -73,6 +77,9 @@ export class RNBoxView extends QWidget implements RNComponent { updateChild(); } insertBefore(child: NodeWidget, beforeChild: NodeWidget): void { + if (child instanceof NodeDialog) { + return; + } const prevIndex = this.children.indexOf(beforeChild); if (prevIndex === -1) { diff --git a/src/components/ColorDialog/RNColorDialog.ts b/src/components/ColorDialog/RNColorDialog.ts new file mode 100644 index 0000000..b6b2fa5 --- /dev/null +++ b/src/components/ColorDialog/RNColorDialog.ts @@ -0,0 +1,47 @@ +import { NodeWidget, QColor, QColorDialog, QColorDialogSignals } from "@nodegui/nodegui"; +import { ColorDialogOption } from "@nodegui/nodegui/dist/lib/QtWidgets/QColorDialog"; +import { throwUnsupported } from "../../utils/helpers"; +import { RNWidget } from "../config"; +import { DialogProps, setDialogProps } from "../Dialog/RNDialog"; +import { DialogOption } from "../FileDialog/RNFileDialog"; + +export interface ColorDialogProps extends DialogProps { + currentColor?: QColor; + option?: DialogOption; + options?: ColorDialogOption; +} + +function setColorDialogProps(widget: RNColorDialog, newProps: ColorDialogProps, oldProps: ColorDialogProps) { + const setter: ColorDialogProps = { + set currentColor(currentColor: QColor) { + widget.setCurrentColor(currentColor); + }, + set option({ option, on }: DialogOption) { + widget.setOption(option, on); + }, + set options(options: ColorDialogOption) { + widget.setOptions(options); + }, + }; + Object.assign(setter, newProps); + setDialogProps(widget, newProps, oldProps); +} + +export class RNColorDialog extends QColorDialog implements RNWidget { + setProps(newProps: ColorDialogProps, oldProps: ColorDialogProps): void { + setColorDialogProps(this, newProps, oldProps); + } + appendInitialChild(child: NodeWidget): void { + throwUnsupported(this); + } + appendChild(child: NodeWidget): void { + throwUnsupported(this); + } + insertBefore(child: NodeWidget, beforeChild: NodeWidget): void { + throwUnsupported(this); + } + removeChild(child: NodeWidget): void { + throwUnsupported(this); + } + static tagName = "color-dialog"; +} diff --git a/src/components/ColorDialog/index.ts b/src/components/ColorDialog/index.ts new file mode 100644 index 0000000..d009a25 --- /dev/null +++ b/src/components/ColorDialog/index.ts @@ -0,0 +1,47 @@ +import { Fiber } from "react-reconciler"; +import { AppContainer } from "../../reconciler"; +import { ComponentConfig, registerComponent } from "../config"; +import { RNColorDialog, ColorDialogProps } from "./RNColorDialog"; + +class ColorDialogConfig extends ComponentConfig { + tagName: string = RNColorDialog.tagName; + shouldSetTextContent(nextProps: ColorDialogProps): boolean { + return false; + } + createInstance(newProps: ColorDialogProps, rootInstance: AppContainer, context: any, workInProgress: Fiber): RNColorDialog { + const widget = new RNColorDialog(); + widget.setProps(newProps, {}); + return widget; + } + commitMount(instance: RNColorDialog, newProps: ColorDialogProps, internalInstanceHandle: any): void { + if (newProps.visible !== false && newProps.open !== false) { + instance.show(); + } + return; + } + commitUpdate(instance: RNColorDialog, updatePayload: any, oldProps: ColorDialogProps, newProps: ColorDialogProps, finishedWork: Fiber): void { + instance.setProps(newProps, oldProps); + } +} +/** + * Pop up ColorDialog inheriting the functionality of nodegui's `QColorDialog` + * @example + * ```javascript + * function ColorDialogExample(props){ + * const [open, setOpen] = useState(false); + * const events = useEventHandler({ + * colorSelected(color){ + * //....do whatever + * } + * }, [....deps]) + * return ( + * + * + *