Skip to content

Commit

Permalink
simplify central widget window (#73)
Browse files Browse the repository at this point in the history
* cleans up custom central widget logic

* bumps version to 0.2.6
  • Loading branch information
a7ul authored Nov 26, 2019
1 parent 64d0980 commit 4f834c5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 46 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nodegui/react-nodegui",
"version": "0.2.5",
"version": "0.2.6",
"description": "React Native for building cross platform desktop applications",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -31,7 +31,7 @@
"react": "^16.9.0"
},
"devDependencies": {
"@nodegui/nodegui": "^0.6.5",
"@nodegui/nodegui": "^0.6.7",
"@types/node": "^12.0.10",
"prettier": "^1.18.2",
"react": "^16.9.0",
Expand Down
45 changes: 12 additions & 33 deletions src/components/Window/RNWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@ const setWindowProps = (
oldProps: WindowProps
) => {
const setter: WindowProps = {
set centralWidgetProps(centralWidgetProps: ViewProps) {
if (window.centralWidget) {
const oldcentralWidgetProps = oldProps.centralWidgetProps || {};
setViewProps(
window.centralWidget as RNView,
centralWidgetProps,
oldcentralWidgetProps
);
} else {
console.warn(
"Trying to set viewProps for main window but no central widget set."
);
}
}
// TODO add more props
};
Object.assign(setter, newProps);
setViewProps(window, newProps, oldProps);
Expand All @@ -38,29 +25,21 @@ export class RNWindow extends QMainWindow implements RNWidget {
setProps(newProps: WindowProps, oldProps: WindowProps): void {
setWindowProps(this, newProps, oldProps);
}
static tagName = "mainwindow";
removeChild(child: NodeWidget) {
const removedChild = this.takeCentralWidget();
if (removedChild) {
removedChild.close();
}
child.close();
}
appendInitialChild(child: NodeWidget): void {
this.appendChild(child);
this.setCentralWidget(child);
}
appendChild(child: NodeWidget): void {
if (!child) {
return;
}
(this.layout as FlexLayout).addWidget(child);
this.appendInitialChild(child);
}
insertBefore(child: NodeWidget, beforeChild: NodeWidget): void {
if (!this.layout) {
console.warn("window has no layout to insert child before another child");
return;
}
(this.layout as FlexLayout).insertChildBefore(child, beforeChild);
}
removeChild(child: NodeWidget) {
if (!this.layout) {
console.warn("parent has no layout to remove child from");
return;
}
(this.layout as FlexLayout).removeWidget(child);
child.close();
this.appendInitialChild(child);
}
static tagName = "mainwindow";
}
6 changes: 0 additions & 6 deletions src/components/Window/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { registerComponent, ComponentConfig } from "../config";
import { QWidget, FlexLayout } from "@nodegui/nodegui";
import { Fiber } from "react-reconciler";
import { WindowProps, RNWindow } from "./RNWindow";
import { AppContainer } from "../../reconciler";
Expand All @@ -16,11 +15,6 @@ class WindowConfig extends ComponentConfig {
workInProgress: Fiber
): RNWindow {
const window = new RNWindow();
const rootView = new QWidget();
const rootViewLayout = new FlexLayout();
rootViewLayout.setFlexNode(rootView.getFlexNode());
rootView.setLayout(rootViewLayout);
window.setCentralWidget(rootView);
window.setProps(newProps, {});
return window;
}
Expand Down

0 comments on commit 4f834c5

Please sign in to comment.