Skip to content

Commit e2c54ed

Browse files
committed
Cleanup of react-nodegui and remove non-working methods from view
1 parent 377dbe8 commit e2c54ed

File tree

5 files changed

+37
-136
lines changed

5 files changed

+37
-136
lines changed

package-lock.json

Lines changed: 10 additions & 16 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
@@ -22,11 +22,11 @@
2222
"react": "16.9.0"
2323
},
2424
"devDependencies": {
25-
"@nodegui/nodegui": "^0.1.5",
25+
"@nodegui/nodegui": "^0.1.7",
2626
"@types/node": "^12.0.10",
2727
"@types/react-reconciler": "^0.18.0",
2828
"prettier": "^1.18.2",
2929
"react": "^16.9.0",
3030
"typescript": "^3.5.2"
3131
}
32-
}
32+
}

src/components/View/index.ts

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
QWidget,
3-
NodeWidget,
4-
WidgetAttribute,
5-
WindowType
6-
} from "@nodegui/nodegui";
1+
import { QWidget, NodeWidget } from "@nodegui/nodegui";
72
import { registerComponent } from "../config";
83

94
type Geometry = {
@@ -16,18 +11,16 @@ export interface ListenerMap {
1611
[key: string]: (payload?: any) => void;
1712
}
1813
export interface ViewProps {
14+
visible?: boolean;
15+
styleSheet?: string;
16+
style?: string; // Inline style from NodeGui
1917
geometry?: Geometry;
2018
id?: string;
21-
style?: string; // Inline style from NodeGui
22-
styleSheet?: string;
23-
visible?: boolean;
24-
ref?: any;
25-
on?: ListenerMap;
2619
mouseTracking?: boolean;
2720
enabled?: boolean;
28-
attributes?: WidgetAttribute[];
29-
windowFlags?: WindowType[];
3021
windowOpacity?: Number;
22+
on?: ListenerMap;
23+
ref?: any;
3124
}
3225

3326
export const setProps = (
@@ -36,35 +29,38 @@ export const setProps = (
3629
oldProps: ViewProps
3730
) => {
3831
const setter: ViewProps = {
39-
set geometry(geometry: Geometry) {
40-
widget.setGeometry(
41-
geometry.x,
42-
geometry.y,
43-
geometry.width,
44-
geometry.height
45-
);
46-
},
4732
set visible(shouldShow: boolean) {
4833
shouldShow ? widget.show() : widget.hide();
4934
},
35+
set styleSheet(styleSheet: string) {
36+
widget.setStyleSheet(styleSheet);
37+
},
5038
set style(inlineStyle: string) {
5139
if (newProps.styleSheet) {
5240
console.warn("Both styleSheet and inlineStyle can't be used together");
5341
}
5442
widget.setInlineStyle(inlineStyle);
5543
},
56-
set styleSheet(styleSheet: string) {
57-
widget.setStyleSheet(styleSheet);
44+
set geometry(geometry: Geometry) {
45+
widget.setGeometry(
46+
geometry.x,
47+
geometry.y,
48+
geometry.width,
49+
geometry.height
50+
);
5851
},
5952
set id(id: string) {
6053
widget.setObjectName(id);
6154
},
6255
set mouseTracking(isMouseTracked: boolean) {
63-
widget.setMouseTracking(isMouseTracked); //TODO: add a getter for this in nodegui
56+
widget.setMouseTracking(isMouseTracked);
6457
},
6558
set enabled(enable: boolean) {
6659
widget.setEnabled(enable);
6760
},
61+
set windowOpacity(opacity: Number) {
62+
widget.setWindowOpacity(opacity);
63+
},
6864
set on(listenerMap: ListenerMap) {
6965
const listenerMapLatest = Object.assign({}, listenerMap);
7066
const oldListenerMap = Object.assign({}, oldProps.on);
@@ -83,29 +79,6 @@ export const setProps = (
8379
widget.addEventListener(eventType, newEvtListener);
8480
}
8581
);
86-
},
87-
set attributes(attributes: WidgetAttribute[]) {
88-
const oldAttributes = oldProps.attributes || [];
89-
const newAttributes = attributes || [];
90-
oldAttributes.forEach(eachOldAttribute => {
91-
widget.setAttribute(eachOldAttribute, false);
92-
});
93-
newAttributes.forEach(eachNewAttribute => {
94-
widget.setAttribute(eachNewAttribute, true);
95-
});
96-
},
97-
set windowFlags(windowTypes: WindowType[]) {
98-
const oldFlags = oldProps.windowFlags || [];
99-
const newFlags = windowTypes || [];
100-
oldFlags.forEach(eachOldFlag => {
101-
widget.setWindowFlag(eachOldFlag, false);
102-
});
103-
newFlags.forEach(eachNewWindowFlag => {
104-
widget.setWindowFlag(eachNewWindowFlag, true);
105-
});
106-
},
107-
set windowOpacity(opacity: Number) {
108-
widget.setWindowOpacity(opacity);
10982
}
11083
};
11184
Object.assign(setter, newProps);

src/demo.tsx

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,18 @@
1-
import { Renderer, View, Button, Window, Image, LineEdit } from "./index";
2-
import React, { useEffect, useRef, useMemo, useState } from "react";
3-
import {
4-
AspectRatioMode,
5-
QMainWindow,
6-
QLineEditEvents,
7-
QPushButtonEvents
8-
} from "@nodegui/nodegui";
1+
import { Renderer, Window } from "./index";
2+
import React, { useEffect, useRef } from "react";
3+
import { QMainWindow } from "@nodegui/nodegui";
94

105
const App = () => {
116
const winRef = useRef<QMainWindow>(null);
12-
const [fileUrl, setFileUrl] = useState();
13-
const [imageSrc, setImageSrc] = useState();
147
useEffect(() => {
158
if (winRef.current) {
169
winRef.current.resize(800, 450);
1710
}
1811
}, []);
19-
const lineEditHandler = useMemo(
20-
() => ({
21-
[QLineEditEvents.textChanged]: (text: string) => {
22-
setFileUrl(text);
23-
}
24-
}),
25-
[]
26-
);
27-
28-
const loadButtonHandler = useMemo(
29-
() => ({
30-
[QPushButtonEvents.clicked]: () => {
31-
setImageSrc(fileUrl);
32-
}
33-
}),
34-
[fileUrl]
35-
);
3612

3713
return (
3814
<>
39-
<Window ref={winRef} styleSheet={styleSheet}>
40-
<View id="container">
41-
<View id="controls">
42-
<LineEdit
43-
on={lineEditHandler}
44-
id="textField"
45-
text={fileUrl}
46-
placeholderText="Absolute path to an image"
47-
/>
48-
<Button
49-
style={`
50-
background-color: green;
51-
`}
52-
text="Load Image"
53-
on={loadButtonHandler}
54-
/>
55-
</View>
56-
<Image
57-
id="img"
58-
aspectRatioMode={AspectRatioMode.KeepAspectRatio}
59-
src={imageSrc}
60-
></Image>
61-
</View>
62-
</Window>
15+
<Window ref={winRef} styleSheet={styleSheet}></Window>
6316
</>
6417
);
6518
};
@@ -69,24 +22,6 @@ const styleSheet = `
6922
flex: 1;
7023
min-height: '100%';
7124
}
72-
#controls {
73-
flex-direction: 'row';
74-
justify-content: 'space-around';
75-
align-items: 'center';
76-
padding-horizontal: 20;
77-
padding-vertical: 10;
78-
}
79-
#img {
80-
flex: 1;
81-
qproperty-alignment: 'AlignCenter';
82-
}
83-
#textField {
84-
flex: 1;
85-
}
8625
`;
8726

88-
Renderer.render(<App />, {
89-
onRender: () => {
90-
console.log("Yo");
91-
}
92-
});
27+
Renderer.render(<App />);

src/reconciler/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Reconciler from "react-reconciler";
22
import { NodeWidget, FlexLayout } from "@nodegui/nodegui";
33
import { getComponent } from "../components/config";
4-
import * as scheduler from "scheduler";
54

65
export type AppContainer = Set<NodeWidget>;
76
export const appContainer: AppContainer = new Set<NodeWidget>();

0 commit comments

Comments
 (0)