nodegui / react-nodegui

Build performant, native and cross-platform desktop applications with native React + powerful CSS like styling.🚀
https://react.nodegui.org
MIT License
6.18k stars 171 forks source link

Dialog & all its inherited widget added #344

Closed KRTirtho closed 3 years ago

KRTirtho commented 3 years ago

Fixes #108 Added Components:

Edited/Modified:

Disclaimer!: Dialog & its all inherited widgets can only be used inside a View or BoxView. Using it in other places will not work. It'd cause the Dialog components to not appear. This behavior was expected since adding NodeDialog inherited widgets to Layout or as a child to other widgets doesn't work. Thus filters were added to View & BoxView to not let any instance of NodeDialog to be added in the layout tree

An working example:

import React, {useState} from "react";
import { Text, Renderer, Window, View, Button, Dialog } from "@nodegui/react-nodegui";

const App = () => {
  const [open, setOpen] = useState(false);

  return (
    <Window styleSheet={styleSheet}>
      <View id="container">
        <Dialog open={open}/>
        <Button text="Click me" on={{clicked:()=>setOpen(!open)}}></Button>
      </View>
    </Window>
  );
};

const styleSheet = `
  #container {
    flex: 1;
    min-height: '100%';
    justify-content: 'center';
  }
`;

Renderer.render(<App />);

Thanks @a7ul

a7ul commented 3 years ago

Amazing work!!!

Dialog & its all inherited widgets can only be used inside a View or BoxView. Using it in other places will not work. It'd cause the Dialog components to not appear. 

Can you add a warning log here saying child wasnt rendered because it was used not inside a view or boxview when this happens ?

KRTirtho commented 3 years ago

Currently I don't know any way of accessing parent Component/Widget in react thus determining whether any component was added as a child to a certain type of Component/s isn't possible in that view. But if there's any method/property of QDialog that can get the instance of parent widget or anything about parent widget please let me know...

a7ul commented 3 years ago

You can take a look at this: https://github.com/nodegui/react-nodegui/blob/master/src/components/TabItem/RNTabItem.ts

But If its too complex for this use case we can go ahead with too.

KRTirtho commented 3 years ago

Well, I looked into that example.. But I've to extend QDialog to inherit the functionalities but looks like TabItem isn't a nodegui/qt widget. It is a vanilla widget & was fundamentally created for react-nodegui's Tabs so inheriting Component was possible. If you really want to show a warning log about adding a NodeDialog instance to the layout tree than you can do so in nodegui's widget.layout.addWidget, widget.setWidget or widget.setCentralWidget. It'd even make it better for the nodegui's part too preventing accidental addition of Dialog as child

Looks like it'd be complicated for the react-nodegui part. So I suggest about going ahead Thanks again @a7ul

a7ul commented 3 years ago

@all-contributors add @KRTirtho for code

allcontributors[bot] commented 3 years ago

@a7ul

I've put up a pull request to add @KRTirtho! :tada: