Skip to content

Commit 85ff56c

Browse files
authored
Typed event listeners for autocomplete support (#99)
1 parent 24e126d commit 85ff56c

File tree

23 files changed

+186
-147
lines changed

23 files changed

+186
-147
lines changed

src/components/AbstractComponents/RNAbstractButton.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { QAbstractButton } from "@nodegui/nodegui";
2323
*
2424
* ```
2525
*/
26-
export interface AbstractButtonProps extends ViewProps {
26+
export interface AbstractButtonProps<Signals> extends ViewProps<Signals> {
2727
/**
2828
* Sets the given text to the button. [QPushButton: setText](https://docs.nodegui.org/docs/api/QPushButton#buttonsettexttext)
2929
*/
@@ -38,12 +38,12 @@ export interface AbstractButtonProps extends ViewProps {
3838
iconSize?: QSize;
3939
}
4040

41-
export const setAbstractButtonProps = (
42-
widget: QAbstractButton,
43-
newProps: AbstractButtonProps,
44-
oldProps: AbstractButtonProps
45-
) => {
46-
const setter: AbstractButtonProps = {
41+
export function setAbstractButtonProps<Signals>(
42+
widget: QAbstractButton<Signals>,
43+
newProps: AbstractButtonProps<Signals>,
44+
oldProps: AbstractButtonProps<Signals>
45+
) {
46+
const setter: AbstractButtonProps<Signals> = {
4747
set text(buttonText: string) {
4848
widget.setText(buttonText);
4949
},
@@ -56,4 +56,4 @@ export const setAbstractButtonProps = (
5656
};
5757
Object.assign(setter, newProps);
5858
setViewProps(widget, newProps, oldProps);
59-
};
59+
}

src/components/AnimatedImage/RNAnimatedImage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ export class RNAnimatedImage extends QLabel implements RNWidget {
4444
setProps(newProps: AnimatedImageProps, oldProps: AnimatedImageProps): void {
4545
setAnimatedImageProps(this, newProps, oldProps);
4646
}
47-
appendInitialChild(child: NodeWidget): void {
47+
appendInitialChild(child: NodeWidget<any>): void {
4848
throwUnsupported(this);
4949
}
50-
appendChild(child: NodeWidget): void {
50+
appendChild(child: NodeWidget<any>): void {
5151
throwUnsupported(this);
5252
}
53-
insertBefore(child: NodeWidget, beforeChild: NodeWidget): void {
53+
insertBefore(child: NodeWidget<any>, beforeChild: NodeWidget<any>): void {
5454
throwUnsupported(this);
5555
}
56-
removeChild(child: NodeWidget): void {
56+
removeChild(child: NodeWidget<any>): void {
5757
throwUnsupported(this);
5858
}
5959
static tagName = "animatedimage";

src/components/AnimatedImage/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Fiber } from "react-reconciler";
22
import { registerComponent, ComponentConfig } from "../config";
33
import { RNAnimatedImage, AnimatedImageProps } from "./RNAnimatedImage";
44
import { AppContainer } from "../../reconciler";
5-
import { QLabelEvents } from "@nodegui/nodegui";
65

76
class AnimatedImageConfig extends ComponentConfig {
87
tagName = RNAnimatedImage.tagName;

src/components/Button/RNButton.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QPushButton, NodeWidget } from "@nodegui/nodegui";
1+
import { QPushButton, NodeWidget, QPushButtonSignals } from "@nodegui/nodegui";
22
import {
33
AbstractButtonProps,
44
setAbstractButtonProps
@@ -27,7 +27,7 @@ import { throwUnsupported } from "../../utils/helpers";
2727
*
2828
* ```
2929
*/
30-
export interface ButtonProps extends AbstractButtonProps {
30+
export interface ButtonProps extends AbstractButtonProps<QPushButtonSignals> {
3131
/**
3232
* Sets whether the button border is raised. [QPushButton: setFlat](https://docs.nodegui.org/docs/api/QPushButton#buttonsetflatisflat)
3333
*/
@@ -52,16 +52,16 @@ const setButtonProps = (
5252
* @ignore
5353
*/
5454
export class RNButton extends QPushButton implements RNWidget {
55-
appendInitialChild(child: NodeWidget): void {
55+
appendInitialChild(child: NodeWidget<any>): void {
5656
throwUnsupported(this);
5757
}
58-
appendChild(child: NodeWidget): void {
58+
appendChild(child: NodeWidget<any>): void {
5959
throwUnsupported(this);
6060
}
61-
insertBefore(child: NodeWidget, beforeChild: NodeWidget): void {
61+
insertBefore(child: NodeWidget<any>, beforeChild: NodeWidget<any>): void {
6262
throwUnsupported(this);
6363
}
64-
removeChild(child: NodeWidget): void {
64+
removeChild(child: NodeWidget<any>): void {
6565
throwUnsupported(this);
6666
}
6767
setProps(newProps: ButtonProps, oldProps: ButtonProps) {

src/components/CheckBox/RNCheckBox.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QCheckBox, NodeWidget } from "@nodegui/nodegui";
1+
import { QCheckBox, NodeWidget, QCheckBoxSignals } from "@nodegui/nodegui";
22
import { RNWidget } from "../config";
33
import { throwUnsupported } from "../../utils/helpers";
44
import {
@@ -27,7 +27,7 @@ import {
2727
*
2828
* ```
2929
*/
30-
export interface CheckBoxProps extends AbstractButtonProps {
30+
export interface CheckBoxProps extends AbstractButtonProps<QCheckBoxSignals> {
3131
/**
3232
* This property holds whether the button is checked. [QCheckBox: setChecked](https://docs.nodegui.org/docs/api/QCheckBox/#checkboxsetcheckedcheck)
3333
*/
@@ -55,16 +55,16 @@ export class RNCheckBox extends QCheckBox implements RNWidget {
5555
setProps(newProps: CheckBoxProps, oldProps: CheckBoxProps): void {
5656
setCheckBoxProps(this, newProps, oldProps);
5757
}
58-
appendInitialChild(child: NodeWidget): void {
58+
appendInitialChild(child: NodeWidget<any>): void {
5959
throwUnsupported(this);
6060
}
61-
appendChild(child: NodeWidget): void {
61+
appendChild(child: NodeWidget<any>): void {
6262
throwUnsupported(this);
6363
}
64-
insertBefore(child: NodeWidget, beforeChild: NodeWidget): void {
64+
insertBefore(child: NodeWidget<any>, beforeChild: NodeWidget<any>): void {
6565
throwUnsupported(this);
6666
}
67-
removeChild(child: NodeWidget): void {
67+
removeChild(child: NodeWidget<any>): void {
6868
throwUnsupported(this);
6969
}
7070
static tagName = "checkbox";

src/components/ComboBox/RNComboBox.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
QVariant,
66
SizeAdjustPolicy,
77
InsertPolicy,
8-
QIcon
8+
QIcon,
9+
QComboBoxSignals
910
} from "@nodegui/nodegui";
1011
import { ViewProps, setViewProps } from "../View/RNView";
1112
import { RNWidget } from "../config";
1213
import { throwUnsupported } from "../../utils/helpers";
1314

14-
export interface ComboBoxProps extends ViewProps {
15+
export interface ComboBoxProps extends ViewProps<QComboBoxSignals> {
1516
items?: ComboBoxItem[];
1617
count?: number;
1718
iconSize?: QSize;
@@ -51,7 +52,7 @@ const setComboBoxProps = (
5152
widget.setProperty("count", count);
5253
},
5354
set iconSize(iconSize: QSize) {
54-
widget.setProperty("iconSize", iconSize);
55+
widget.setProperty("iconSize", iconSize.native);
5556
},
5657
set frame(frame: boolean) {
5758
widget.setProperty("frame", frame);
@@ -60,7 +61,7 @@ const setComboBoxProps = (
6061
widget.setProperty("currentIndex", currentIndex);
6162
},
6263
set currentData(value: QVariant) {
63-
widget.setProperty("currentData", value);
64+
widget.setProperty("currentData", value.native);
6465
},
6566
set currentText(text: string) {
6667
widget.setProperty("currentText", text);
@@ -101,16 +102,16 @@ export class RNComboBox extends QComboBox implements RNWidget {
101102
setProps(newProps: ComboBoxProps, oldProps: ComboBoxProps): void {
102103
setComboBoxProps(this, newProps, oldProps);
103104
}
104-
appendInitialChild(child: NodeWidget): void {
105+
appendInitialChild(child: NodeWidget<any>): void {
105106
throwUnsupported(this);
106107
}
107-
appendChild(child: NodeWidget): void {
108+
appendChild(child: NodeWidget<any>): void {
108109
throwUnsupported(this);
109110
}
110-
insertBefore(child: NodeWidget, beforeChild: NodeWidget): void {
111+
insertBefore(child: NodeWidget<any>, beforeChild: NodeWidget<any>): void {
111112
throwUnsupported(this);
112113
}
113-
removeChild(child: NodeWidget): void {
114+
removeChild(child: NodeWidget<any>): void {
114115
throwUnsupported(this);
115116
}
116117
static tagName = "combobox";

src/components/Dial/RNDial.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { QDial, NodeWidget } from "@nodegui/nodegui";
1+
import { QDial, NodeWidget, QDialSignals } from "@nodegui/nodegui";
22
import { ViewProps, setViewProps } from "../View/RNView";
33
import { RNWidget } from "../config";
44
import { throwUnsupported } from "../../utils/helpers";
55

6-
export interface DialProps extends ViewProps {
6+
export interface DialProps extends ViewProps<QDialSignals> {
77
notchesVisible?: boolean;
88
wrapping?: boolean;
99
notchTarget?: number;
@@ -36,16 +36,16 @@ export class RNDial extends QDial implements RNWidget {
3636
setProps(newProps: DialProps, oldProps: DialProps): void {
3737
setDialProps(this, newProps, oldProps);
3838
}
39-
appendInitialChild(child: NodeWidget): void {
39+
appendInitialChild(child: NodeWidget<any>): void {
4040
throwUnsupported(this);
4141
}
42-
appendChild(child: NodeWidget): void {
42+
appendChild(child: NodeWidget<any>): void {
4343
throwUnsupported(this);
4444
}
45-
insertBefore(child: NodeWidget, beforeChild: NodeWidget): void {
45+
insertBefore(child: NodeWidget<any>, beforeChild: NodeWidget<any>): void {
4646
throwUnsupported(this);
4747
}
48-
removeChild(child: NodeWidget): void {
48+
removeChild(child: NodeWidget<any>): void {
4949
throwUnsupported(this);
5050
}
5151
static tagName = "dial";

src/components/Image/RNImage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ export class RNImage extends QLabel implements RNWidget {
5555
setProps(newProps: ImageProps, oldProps: ImageProps): void {
5656
setImageProps(this, newProps, oldProps);
5757
}
58-
appendInitialChild(child: NodeWidget): void {
58+
appendInitialChild(child: NodeWidget<any>): void {
5959
throwUnsupported(this);
6060
}
61-
appendChild(child: NodeWidget): void {
61+
appendChild(child: NodeWidget<any>): void {
6262
throwUnsupported(this);
6363
}
64-
insertBefore(child: NodeWidget, beforeChild: NodeWidget): void {
64+
insertBefore(child: NodeWidget<any>, beforeChild: NodeWidget<any>): void {
6565
throwUnsupported(this);
6666
}
67-
removeChild(child: NodeWidget): void {
67+
removeChild(child: NodeWidget<any>): void {
6868
throwUnsupported(this);
6969
}
7070
static tagName = "image";

src/components/Image/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { QLabelEvents } from "@nodegui/nodegui";
21
import { Fiber } from "react-reconciler";
32
import { registerComponent, ComponentConfig } from "../config";
43
import { RNImage, ImageProps } from "./RNImage";
54
import { AppContainer } from "../../reconciler";
5+
import { WidgetEventTypes } from "@nodegui/nodegui";
66
class ImageConfig extends ComponentConfig {
77
tagName = RNImage.tagName;
88
shouldSetTextContent(nextProps: ImageProps): boolean {
@@ -17,7 +17,7 @@ class ImageConfig extends ComponentConfig {
1717
const widget = new RNImage();
1818
widget.setProperty("scaledContents", true);
1919
widget.setProps(newProps, {});
20-
widget.addEventListener(QLabelEvents.Resize, () => {
20+
widget.addEventListener(WidgetEventTypes.Resize, () => {
2121
widget.scalePixmap(widget.size());
2222
});
2323
return widget;

src/components/LineEdit/RNLineEdit.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import { QLineEdit, EchoMode, NodeWidget } from "@nodegui/nodegui";
1+
import {
2+
QLineEdit,
3+
EchoMode,
4+
NodeWidget,
5+
QLineEditSignals
6+
} from "@nodegui/nodegui";
27
import { ViewProps, setViewProps } from "../View/RNView";
38
import { RNWidget } from "../config";
49
import { throwUnsupported } from "../../utils/helpers";
510

6-
export interface LineEditProps extends ViewProps {
11+
export interface LineEditProps extends ViewProps<QLineEditSignals> {
712
text?: string;
813
placeholderText?: string;
914
readOnly?: boolean;
@@ -40,16 +45,16 @@ export class RNLineEdit extends QLineEdit implements RNWidget {
4045
setProps(newProps: LineEditProps, oldProps: LineEditProps): void {
4146
setLineEditProps(this, newProps, oldProps);
4247
}
43-
appendInitialChild(child: NodeWidget): void {
48+
appendInitialChild(child: NodeWidget<any>): void {
4449
throwUnsupported(this);
4550
}
46-
appendChild(child: NodeWidget): void {
51+
appendChild(child: NodeWidget<any>): void {
4752
throwUnsupported(this);
4853
}
49-
insertBefore(child: NodeWidget, beforeChild: NodeWidget): void {
54+
insertBefore(child: NodeWidget<any>, beforeChild: NodeWidget<any>): void {
5055
throwUnsupported(this);
5156
}
52-
removeChild(child: NodeWidget): void {
57+
removeChild(child: NodeWidget<any>): void {
5358
throwUnsupported(this);
5459
}
5560
static tagName = "linedit";

0 commit comments

Comments
 (0)