Skip to content

Commit 4f834c5

Browse files
authored
simplify central widget window (#73)
* cleans up custom central widget logic * bumps version to 0.2.6
1 parent 64d0980 commit 4f834c5

File tree

4 files changed

+19
-46
lines changed

4 files changed

+19
-46
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nodegui/react-nodegui",
3-
"version": "0.2.5",
3+
"version": "0.2.6",
44
"description": "React Native for building cross platform desktop applications",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -31,7 +31,7 @@
3131
"react": "^16.9.0"
3232
},
3333
"devDependencies": {
34-
"@nodegui/nodegui": "^0.6.5",
34+
"@nodegui/nodegui": "^0.6.7",
3535
"@types/node": "^12.0.10",
3636
"prettier": "^1.18.2",
3737
"react": "^16.9.0",

src/components/Window/RNWindow.ts

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,7 @@ const setWindowProps = (
1212
oldProps: WindowProps
1313
) => {
1414
const setter: WindowProps = {
15-
set centralWidgetProps(centralWidgetProps: ViewProps) {
16-
if (window.centralWidget) {
17-
const oldcentralWidgetProps = oldProps.centralWidgetProps || {};
18-
setViewProps(
19-
window.centralWidget as RNView,
20-
centralWidgetProps,
21-
oldcentralWidgetProps
22-
);
23-
} else {
24-
console.warn(
25-
"Trying to set viewProps for main window but no central widget set."
26-
);
27-
}
28-
}
15+
// TODO add more props
2916
};
3017
Object.assign(setter, newProps);
3118
setViewProps(window, newProps, oldProps);
@@ -38,29 +25,21 @@ export class RNWindow extends QMainWindow implements RNWidget {
3825
setProps(newProps: WindowProps, oldProps: WindowProps): void {
3926
setWindowProps(this, newProps, oldProps);
4027
}
41-
static tagName = "mainwindow";
28+
removeChild(child: NodeWidget) {
29+
const removedChild = this.takeCentralWidget();
30+
if (removedChild) {
31+
removedChild.close();
32+
}
33+
child.close();
34+
}
4235
appendInitialChild(child: NodeWidget): void {
43-
this.appendChild(child);
36+
this.setCentralWidget(child);
4437
}
4538
appendChild(child: NodeWidget): void {
46-
if (!child) {
47-
return;
48-
}
49-
(this.layout as FlexLayout).addWidget(child);
39+
this.appendInitialChild(child);
5040
}
5141
insertBefore(child: NodeWidget, beforeChild: NodeWidget): void {
52-
if (!this.layout) {
53-
console.warn("window has no layout to insert child before another child");
54-
return;
55-
}
56-
(this.layout as FlexLayout).insertChildBefore(child, beforeChild);
57-
}
58-
removeChild(child: NodeWidget) {
59-
if (!this.layout) {
60-
console.warn("parent has no layout to remove child from");
61-
return;
62-
}
63-
(this.layout as FlexLayout).removeWidget(child);
64-
child.close();
42+
this.appendInitialChild(child);
6543
}
44+
static tagName = "mainwindow";
6645
}

src/components/Window/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { registerComponent, ComponentConfig } from "../config";
2-
import { QWidget, FlexLayout } from "@nodegui/nodegui";
32
import { Fiber } from "react-reconciler";
43
import { WindowProps, RNWindow } from "./RNWindow";
54
import { AppContainer } from "../../reconciler";
@@ -16,11 +15,6 @@ class WindowConfig extends ComponentConfig {
1615
workInProgress: Fiber
1716
): RNWindow {
1817
const window = new RNWindow();
19-
const rootView = new QWidget();
20-
const rootViewLayout = new FlexLayout();
21-
rootViewLayout.setFlexNode(rootView.getFlexNode());
22-
rootView.setLayout(rootViewLayout);
23-
window.setCentralWidget(rootView);
2418
window.setProps(newProps, {});
2519
return window;
2620
}

0 commit comments

Comments
 (0)