-
-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathindex.ts
222 lines (218 loc) · 5.51 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import Reconciler from "react-reconciler";
import { QWidget, QSystemTrayIcon, QObject } from "@nodegui/nodegui";
import {
getComponentByTagName,
RNWidget,
RNProps,
RNComponent
} from "../components/config";
export type AppContainer = Set<QWidget<any>>;
export const appContainer: AppContainer = new Set<QWidget<any>>();
const shouldIgnoreChild = (child: QObject<any>) =>
child instanceof QSystemTrayIcon;
const HostConfig: Reconciler.HostConfig<
string,
RNProps,
AppContainer,
RNComponent,
any,
any,
any,
any,
any,
any,
any,
any
> = {
now: Date.now,
getRootHostContext: function(nextRootInstance) {
let context = {
name: "rootnode"
};
return context;
},
getChildHostContext: function(parentContext, fiberType, rootInstance) {
const { getContext } = getComponentByTagName(fiberType);
return getContext(parentContext, rootInstance);
},
shouldSetTextContent: function(type, nextProps) {
const { shouldSetTextContent } = getComponentByTagName(type);
return shouldSetTextContent(nextProps);
},
createTextInstance: function(
newText,
rootContainerInstance,
context,
workInProgress
) {
// throw new Error(`Can't create text without <Text> for text: ${newText}`);
console.warn(
"createTextInstance called in reconciler when platform doesnt have host level text. "
);
console.warn(`Use <Text /> component to add the text: ${newText}`);
},
createInstance: function(
type,
newProps,
rootContainerInstance,
context,
workInProgress
) {
const { createInstance } = getComponentByTagName(type);
return createInstance(
newProps,
rootContainerInstance,
context,
workInProgress
);
},
appendInitialChild: function (parent: RNWidget, child: QWidget<any>) {
if (shouldIgnoreChild(child)) {
return;
}
parent.appendInitialChild(child);
},
finalizeInitialChildren: function(
instance,
type,
newProps,
rootContainerInstance,
context
) {
const { finalizeInitialChildren } = getComponentByTagName(type);
return finalizeInitialChildren(
instance,
newProps,
rootContainerInstance,
context
);
},
prepareForCommit: function(rootNode) {
// noop
},
resetAfterCommit: function(rootNode) {
// noop
},
commitMount: function(instance, type, newProps, internalInstanceHandle) {
const { commitMount } = getComponentByTagName(type);
return commitMount(instance, newProps, internalInstanceHandle);
},
appendChildToContainer: function(container, child: QWidget<any>) {
container.add(child);
},
insertInContainerBefore: (container, child, beforeChild) => {
container.add(child);
},
removeChildFromContainer: (container, child) => {
container.delete(child);
if (child.close) {
child.close();
}
},
prepareUpdate: function(
instance,
type,
oldProps,
newProps,
rootContainerInstance,
hostContext
) {
const { prepareUpdate } = getComponentByTagName(type);
return prepareUpdate(
instance,
oldProps,
newProps,
rootContainerInstance,
hostContext
);
},
commitUpdate: function(
instance,
updatePayload,
type,
oldProps,
newProps,
finishedWork
) {
const { commitUpdate } = getComponentByTagName(type);
return commitUpdate(
instance,
updatePayload,
oldProps,
newProps,
finishedWork
);
},
appendChild: (parent: RNWidget, child: QWidget<any>) => {
if (shouldIgnoreChild(child)) {
return;
}
parent.appendChild(child);
},
insertBefore: (
parent: RNWidget,
child: QWidget<any>,
beforeChild: QWidget<any>
) => {
if (shouldIgnoreChild(child)) {
return;
}
parent.insertBefore(child, beforeChild);
},
removeChild: (parent: RNWidget, child: QWidget<any>) => {
if (!shouldIgnoreChild(child)) {
parent.removeChild(child);
}
if (child.close) {
child.close();
}
},
commitTextUpdate: (textInstance, oldText, newText) => {
//noop since we manage all text using Text component
console.warn(
"commitTextUpdate called when platform doesnt have host level text"
);
},
resetTextContent: instance => {
console.warn("resetTextContent in reconciler triggered!");
// noop for now till we find when this method is triggered
},
supportsMutation: true,
supportsPersistence: false,
supportsHydration: false,
getPublicInstance: instance => {
//for supporting refs
return instance;
},
shouldDeprioritizeSubtree: (type, props) => {
// Use to deprioritize entire subtree based on props and types. For example if you dont need reconciler to calculate for hidden elements
if ((props as any).visible === false) {
return true;
}
return false;
},
//@ts-ignore
hideInstance: (instance: QWidget<any>) => {
instance.hide();
},
unhideInstance: (instance: QWidget<any>, Props: RNProps) => {
instance.show();
},
hideTextInstance: (instance: any) => {
// noop since we dont have any host text
console.warn(
"hideTextInstance called when platform doesnt have host level text"
);
},
unhideTextInstance: (instance: QWidget<any>, Props: RNProps) => {
// noop since we dont have any host text
console.warn(
"unhideTextInstance called when platform doesnt have host level text"
);
},
scheduleTimeout: setTimeout,
cancelTimeout: clearTimeout,
noTimeout: -1,
isPrimaryRenderer: true
};
export default Reconciler(HostConfig);