From fbd6a537934f22968fc6e9e6c2bfb279fdca1101 Mon Sep 17 00:00:00 2001 From: KR Tirtho Date: Fri, 26 Mar 2021 04:38:38 -0700 Subject: [PATCH 01/18] Dialog & all its inherited widget added (#344) * Dialog component created & RNView, RNBoxView was tweaked for Dialog * Added Components: - FileDialog - InputDialog - ProgressDialog Edited: - demo file for testing the dialogs * Added Compoents: - ColorDialog - FontDialog Edited: - Dialog (for adding some props) * updated ProgressBar Example * newly created components were exported --- src/components/BoxView/RNBoxView.ts | 7 ++ src/components/ColorDialog/RNColorDialog.ts | 47 ++++++++ src/components/ColorDialog/index.ts | 47 ++++++++ src/components/Dialog/RNDialog.ts | 77 +++++++++++++ src/components/Dialog/index.ts | 53 +++++++++ src/components/FileDialog/RNFileDialog.ts | 63 +++++++++++ src/components/FileDialog/index.ts | 47 ++++++++ src/components/FontDialog/RNFontDialog.ts | 46 ++++++++ src/components/FontDialog/index.ts | 47 ++++++++ src/components/InputDialog/RNInputDialog.ts | 101 ++++++++++++++++++ src/components/InputDialog/index.ts | 47 ++++++++ .../ProgressDialog/RNProgressDialog.ts | 88 +++++++++++++++ src/components/ProgressDialog/index.ts | 59 ++++++++++ src/components/View/RNView.ts | 45 ++------ src/index.ts | 6 ++ 15 files changed, 746 insertions(+), 34 deletions(-) create mode 100644 src/components/ColorDialog/RNColorDialog.ts create mode 100644 src/components/ColorDialog/index.ts create mode 100644 src/components/Dialog/RNDialog.ts create mode 100644 src/components/Dialog/index.ts create mode 100644 src/components/FileDialog/RNFileDialog.ts create mode 100644 src/components/FileDialog/index.ts create mode 100644 src/components/FontDialog/RNFontDialog.ts create mode 100644 src/components/FontDialog/index.ts create mode 100644 src/components/InputDialog/RNInputDialog.ts create mode 100644 src/components/InputDialog/index.ts create mode 100644 src/components/ProgressDialog/RNProgressDialog.ts create mode 100644 src/components/ProgressDialog/index.ts diff --git a/src/components/BoxView/RNBoxView.ts b/src/components/BoxView/RNBoxView.ts index d748faed..9cc7e455 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 00000000..b6b2fa54 --- /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 00000000..d009a257 --- /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 ( + * + * + *