Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
{
"name": "@nodegui/react-nodegui",
"version": "0.3.2",
"version": "0.4.0",
"description": "React Native for building cross platform desktop applications",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand All@@ -27,17 +27,17 @@
"react-reconciler": "^0.24.0"
},
"peerDependencies":{
"@nodegui/nodegui": ">=0.9.0",
"@nodegui/nodegui": ">=0.12.0",
"@nodegui/qode": "*",
"react": "^16.9.0"
},
"devDependencies":{
"@nodegui/nodegui": "^0.11.0",
"@types/node": "^12.0.10",
"@nodegui/nodegui": "^0.12.0",
"@types/node": "^12.12.22",
"prettier": "^1.18.2",
"react": "^16.9.0",
"typedoc": "^0.15.4",
"typedoc-plugin-markdown": "^2.2.14",
"typescript": "^3.7.3"
"typescript": "^3.7.4"
}
}
7 changes: 4 additions & 3 deletions src/components/AbstractComponents/RNAbstractButton.ts
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import{QIcon, QSize } from "@nodegui/nodegui"
import{QIcon, QSize, QAbstractButtonSignals } from "@nodegui/nodegui"
import{ViewProps, setViewProps } from "../View/RNView"
import{QAbstractButton } from "@nodegui/nodegui"

Expand All@@ -23,7 +23,8 @@ import{QAbstractButton } from "@nodegui/nodegui"
*
* ```
*/
export interface AbstractButtonProps<Signals> extends ViewProps<Signals>{
export interface AbstractButtonProps<Signals extends QAbstractButtonSignals>
extends ViewProps<Signals>{
/**
* Sets the given text to the button. [QPushButton: setText](https://docs.nodegui.org/docs/api/QPushButton#buttonsettexttext)
*/
Expand All@@ -38,7 +39,7 @@ export interface AbstractButtonProps<Signals> extends ViewProps<Signals>{
iconSize?: QSize;
}

export function setAbstractButtonProps<Signals>(
export function setAbstractButtonProps<Signals extends QAbstractButtonSignals>(
widget: QAbstractButton<Signals>,
newProps: AbstractButtonProps<Signals>,
oldProps: AbstractButtonProps<Signals>
Expand Down
16 changes: 8 additions & 8 deletions src/components/View/RNView.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -105,20 +105,20 @@ export interface ViewProps<Signals extends{}> extends RNProps{
/**
* Prop to set the event listener map. See [Handlong Events](/docs/guides/handle-events)
*/
on?: Partial<EventListeners | Signals>
on?: Partial<WidgetEventListeners | Signals>
/**
* Prop to set the ref. The ref will return the underlying nodegui widget.
*/
ref?: any;
/**
* Prop to set the Widget Attributes. example:
* <View attributes={{Qt::WA_Disabled: true}} />
* `<View attributes={{[WidgetAttributes.WA_Disabled]: true}} />`
*/
attributes?: WidgetAttributesMap;

/**
* Prop to set the Widget flags. example:
* <View windowFlags={{Qt::SplashScreen: true}} />
* `<View windowFlags={{[WindowType.SplashScreen]: true}} />`
*/
windowFlags?: WindowFlagsMap;
}
Expand DownExpand Up@@ -199,7 +199,7 @@ export function setViewProps<Signals extends{}>(
set pos(position: Position){
widget.move(position.x, position.y);
},
set on(listenerMap: Partial<EventListeners | Signals>){
set on(listenerMap: Partial<WidgetEventListeners | Signals>){
const listenerMapLatest: any = Object.assign({}, listenerMap);
const oldListenerMap = Object.assign({}, oldProps.on);
Object.entries(oldListenerMap).forEach(([eventType, oldEvtListener]) =>{
Expand DownExpand Up@@ -293,14 +293,14 @@ type Position ={
y: number;
};

type EventListeners ={
[key in WidgetEventTypes]: (native?: NativeElement) => void;
};

type WidgetAttributesMap ={
[key: number]: boolean;
};

type WindowFlagsMap ={
[key: number]: boolean;
};

export type WidgetEventListeners ={
[key in WidgetEventTypes]: (native?: NativeElement) => void;
};
11 changes: 9 additions & 2 deletions src/demo.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,8 @@ import{
AnimatedImage,
ComboBox
} from "./index"
import{QIcon, QVariant } from "@nodegui/nodegui"
import{QIcon, QVariant, QPushButtonSignals } from "@nodegui/nodegui"
import{useEventHandler } from "./hooks"

const items = [
{
Expand All@@ -20,12 +21,18 @@ const items = [
{text: "world"}
];

const handler = useEventHandler<QPushButtonSignals>(
{
clicked: clicked =>{}
},
[]
);
const App = () =>{
return (
<Window>
<View style={containerStyle}>
<View on={{}}>
<Button on={{}} style={buttonStyle} text={"Hello"} />
<Button on={handler} style={buttonStyle} text={"Hello"} />
<Button style={buttonStyle} text={"World"} />
</View>
<ComboBox items={items} />
Expand Down
13 changes: 5 additions & 8 deletions src/hooks/index.ts
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
import{useMemo, DependencyList } from "react"
import{WidgetEventListeners } from "../components/View/RNView"

type EventHandlerMap ={
[key: string]: (...args: any[]) => void;
};

export const useEventHandler = (
eventHandlerMap: EventHandlerMap,
export function useEventHandler<Signals>(
eventHandlerMap: Partial<WidgetEventListeners | Signals>,
deps: DependencyList
) => {
){
const handler = useMemo(() =>{
return eventHandlerMap;
}, deps);
return handler;
};
}