@applicaster/zapp-react-native-utils 12.0.0-rc.81 → 12.0.0-rc.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "12.0.0-rc.
|
|
3
|
+
"version": "12.0.0-rc.82",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "12.0.0-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "12.0.0-rc.82",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -1,1094 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
findFocusableNode,
|
|
3
|
-
getLastFocusedItems,
|
|
4
|
-
getPreferableItems,
|
|
5
|
-
getPriorityItems,
|
|
6
|
-
getSelectedItems,
|
|
7
|
-
hasPriorityInDirection,
|
|
8
|
-
} from "../../Utils/index.android";
|
|
9
|
-
import { FocusDirection } from "../../../../directionHelper";
|
|
10
|
-
import { Tree } from "../../Tree";
|
|
11
|
-
|
|
12
|
-
const directionMocks = {
|
|
13
|
-
right: { axis: "x", isHorizontal: true, isVertical: false, value: "right" },
|
|
14
|
-
left: { axis: "x", isHorizontal: true, isVertical: false, value: "left" },
|
|
15
|
-
up: { axis: "x", isHorizontal: false, isVertical: true, value: "up" },
|
|
16
|
-
down: { axis: "x", isHorizontal: false, isVertical: true, value: "down" },
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const screenMock1 = {
|
|
20
|
-
root: {
|
|
21
|
-
id: "root",
|
|
22
|
-
children: [
|
|
23
|
-
{
|
|
24
|
-
id: "menu",
|
|
25
|
-
parent: {
|
|
26
|
-
id: "root",
|
|
27
|
-
},
|
|
28
|
-
children: [
|
|
29
|
-
{
|
|
30
|
-
id: "1dfa32eb-c1b6-4056-b566-ae001978d9eb",
|
|
31
|
-
parent: {
|
|
32
|
-
id: "menu",
|
|
33
|
-
},
|
|
34
|
-
component: {
|
|
35
|
-
props: {
|
|
36
|
-
id: "1dfa32eb-c1b6-4056-b566-ae001978d9eb",
|
|
37
|
-
groupId: "menu",
|
|
38
|
-
preferredFocus: false,
|
|
39
|
-
},
|
|
40
|
-
selected: false,
|
|
41
|
-
getRect: jest.fn(() => ({
|
|
42
|
-
top: 60,
|
|
43
|
-
left: 678,
|
|
44
|
-
right: 931,
|
|
45
|
-
bottom: 90,
|
|
46
|
-
width: 253,
|
|
47
|
-
height: 30,
|
|
48
|
-
x: 0,
|
|
49
|
-
y: 0,
|
|
50
|
-
})),
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
id: "a892edf2-ceb6-425f-8fdb-3e58b38b233e",
|
|
55
|
-
parent: {
|
|
56
|
-
id: "menu",
|
|
57
|
-
},
|
|
58
|
-
component: {
|
|
59
|
-
props: {
|
|
60
|
-
id: "a892edf2-ceb6-425f-8fdb-3e58b38b233e",
|
|
61
|
-
groupId: "menu",
|
|
62
|
-
preferredFocus: true,
|
|
63
|
-
},
|
|
64
|
-
selected: true,
|
|
65
|
-
getRect: jest.fn(() => ({
|
|
66
|
-
top: 60,
|
|
67
|
-
left: 931,
|
|
68
|
-
right: 1130,
|
|
69
|
-
bottom: 90,
|
|
70
|
-
width: 199,
|
|
71
|
-
height: 30,
|
|
72
|
-
x: 0,
|
|
73
|
-
y: 0,
|
|
74
|
-
})),
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
component: {
|
|
79
|
-
props: {
|
|
80
|
-
id: "menu",
|
|
81
|
-
preferredFocus: true,
|
|
82
|
-
},
|
|
83
|
-
getRect: jest.fn(() => ({
|
|
84
|
-
top: 0,
|
|
85
|
-
left: 0,
|
|
86
|
-
right: 1920,
|
|
87
|
-
bottom: 100,
|
|
88
|
-
width: 1920,
|
|
89
|
-
height: 100,
|
|
90
|
-
x: 0,
|
|
91
|
-
y: 0,
|
|
92
|
-
})),
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
id: "ScreenPicker",
|
|
97
|
-
parent: {
|
|
98
|
-
id: "root",
|
|
99
|
-
},
|
|
100
|
-
children: [
|
|
101
|
-
{
|
|
102
|
-
id: "ScreenPicker.ScreenSelector",
|
|
103
|
-
parent: {
|
|
104
|
-
id: "ScreenPicker",
|
|
105
|
-
},
|
|
106
|
-
children: [
|
|
107
|
-
{
|
|
108
|
-
id: 14948,
|
|
109
|
-
parent: {
|
|
110
|
-
id: "ScreenPicker.ScreenSelector",
|
|
111
|
-
},
|
|
112
|
-
component: {
|
|
113
|
-
props: {
|
|
114
|
-
id: 14948,
|
|
115
|
-
groupId: "ScreenPicker.ScreenSelector",
|
|
116
|
-
preferredFocus: true,
|
|
117
|
-
},
|
|
118
|
-
selected: false,
|
|
119
|
-
getRect: jest.fn(() => ({
|
|
120
|
-
top: 131,
|
|
121
|
-
left: 112,
|
|
122
|
-
right: 412,
|
|
123
|
-
bottom: 188,
|
|
124
|
-
width: 300,
|
|
125
|
-
height: 57,
|
|
126
|
-
x: 0,
|
|
127
|
-
y: 0,
|
|
128
|
-
})),
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
id: 14949,
|
|
133
|
-
parent: {
|
|
134
|
-
id: "ScreenPicker.ScreenSelector",
|
|
135
|
-
},
|
|
136
|
-
component: {
|
|
137
|
-
props: {
|
|
138
|
-
id: 14949,
|
|
139
|
-
groupId: "ScreenPicker.ScreenSelector",
|
|
140
|
-
preferredFocus: false,
|
|
141
|
-
},
|
|
142
|
-
selected: false,
|
|
143
|
-
getRect: jest.fn(() => ({
|
|
144
|
-
top: 188,
|
|
145
|
-
left: 112,
|
|
146
|
-
right: 412,
|
|
147
|
-
bottom: 245,
|
|
148
|
-
width: 300,
|
|
149
|
-
height: 57,
|
|
150
|
-
x: 0,
|
|
151
|
-
y: 0,
|
|
152
|
-
})),
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
{
|
|
157
|
-
id: 14950,
|
|
158
|
-
parent: {
|
|
159
|
-
id: "ScreenPicker.ScreenSelector",
|
|
160
|
-
},
|
|
161
|
-
component: {
|
|
162
|
-
props: {
|
|
163
|
-
id: 14950,
|
|
164
|
-
groupId: "ScreenPicker.ScreenSelector",
|
|
165
|
-
preferredFocus: false,
|
|
166
|
-
},
|
|
167
|
-
selected: true,
|
|
168
|
-
getRect: jest.fn(() => ({
|
|
169
|
-
top: 245,
|
|
170
|
-
left: 112,
|
|
171
|
-
right: 412,
|
|
172
|
-
bottom: 302,
|
|
173
|
-
width: 300,
|
|
174
|
-
height: 57,
|
|
175
|
-
x: 0,
|
|
176
|
-
y: 0,
|
|
177
|
-
})),
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
{
|
|
182
|
-
id: 16270,
|
|
183
|
-
parent: {
|
|
184
|
-
id: "ScreenPicker.ScreenSelector",
|
|
185
|
-
},
|
|
186
|
-
component: {
|
|
187
|
-
props: {
|
|
188
|
-
id: 16270,
|
|
189
|
-
groupId: "ScreenPicker.ScreenSelector",
|
|
190
|
-
preferredFocus: false,
|
|
191
|
-
},
|
|
192
|
-
selected: false,
|
|
193
|
-
getRect: jest.fn(() => ({
|
|
194
|
-
top: 302,
|
|
195
|
-
left: 112,
|
|
196
|
-
right: 412,
|
|
197
|
-
bottom: 359,
|
|
198
|
-
width: 300,
|
|
199
|
-
height: 57,
|
|
200
|
-
x: 0,
|
|
201
|
-
y: 0,
|
|
202
|
-
})),
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
],
|
|
206
|
-
component: {
|
|
207
|
-
props: {
|
|
208
|
-
id: "ScreenPicker.ScreenSelector",
|
|
209
|
-
groupId: "ScreenPicker",
|
|
210
|
-
preferredFocus: true,
|
|
211
|
-
},
|
|
212
|
-
getRect: jest.fn(() => ({
|
|
213
|
-
top: 101,
|
|
214
|
-
left: 112,
|
|
215
|
-
right: 412,
|
|
216
|
-
bottom: 2186,
|
|
217
|
-
width: 300,
|
|
218
|
-
height: 2085,
|
|
219
|
-
x: 0,
|
|
220
|
-
y: 0,
|
|
221
|
-
})),
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
|
|
225
|
-
{
|
|
226
|
-
id: "ScreenPicker.ScreenContainer",
|
|
227
|
-
parent: {
|
|
228
|
-
id: "ScreenPicker",
|
|
229
|
-
},
|
|
230
|
-
children: [
|
|
231
|
-
{
|
|
232
|
-
id: "Grid",
|
|
233
|
-
parent: {
|
|
234
|
-
id: "ScreenPicker.ScreenContainer",
|
|
235
|
-
},
|
|
236
|
-
children: [
|
|
237
|
-
{
|
|
238
|
-
id: "Grid+5bc7813a8c1abc222700000e",
|
|
239
|
-
parent: {
|
|
240
|
-
id: "Grid",
|
|
241
|
-
},
|
|
242
|
-
component: {
|
|
243
|
-
props: {
|
|
244
|
-
id: "Grid+5bc7813a8c1abc222700000e",
|
|
245
|
-
groupId: "Grid",
|
|
246
|
-
preferredFocus: true,
|
|
247
|
-
},
|
|
248
|
-
getRect: jest.fn(() => ({
|
|
249
|
-
top: 758,
|
|
250
|
-
left: 526,
|
|
251
|
-
right: 955,
|
|
252
|
-
bottom: 1245,
|
|
253
|
-
width: 429,
|
|
254
|
-
height: 487,
|
|
255
|
-
x: 0,
|
|
256
|
-
y: 0,
|
|
257
|
-
})),
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
|
|
261
|
-
{
|
|
262
|
-
id: "Grid+5af0a05a841c4b344c00002a",
|
|
263
|
-
parent: {
|
|
264
|
-
id: "Grid",
|
|
265
|
-
},
|
|
266
|
-
component: {
|
|
267
|
-
props: {
|
|
268
|
-
id: "Grid+5af0a05a841c4b344c00002a",
|
|
269
|
-
groupId: "Grid",
|
|
270
|
-
preferredFocus: false,
|
|
271
|
-
},
|
|
272
|
-
getRect: jest.fn(() => ({
|
|
273
|
-
top: 758,
|
|
274
|
-
left: 955,
|
|
275
|
-
right: 1384,
|
|
276
|
-
bottom: 1245,
|
|
277
|
-
width: 429,
|
|
278
|
-
height: 487,
|
|
279
|
-
x: 0,
|
|
280
|
-
y: 0,
|
|
281
|
-
})),
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
|
|
285
|
-
{
|
|
286
|
-
id: "Grid+5ae9f107dbc8585711000011",
|
|
287
|
-
parent: {
|
|
288
|
-
id: "Grid",
|
|
289
|
-
},
|
|
290
|
-
component: {
|
|
291
|
-
props: {
|
|
292
|
-
id: "Grid+5ae9f107dbc8585711000011",
|
|
293
|
-
groupId: "Grid",
|
|
294
|
-
preferredFocus: false,
|
|
295
|
-
},
|
|
296
|
-
getRect: jest.fn(() => ({
|
|
297
|
-
top: 758,
|
|
298
|
-
left: 1384,
|
|
299
|
-
right: 1813,
|
|
300
|
-
bottom: 1245,
|
|
301
|
-
width: 429,
|
|
302
|
-
height: 487,
|
|
303
|
-
x: 0,
|
|
304
|
-
y: 0,
|
|
305
|
-
})),
|
|
306
|
-
},
|
|
307
|
-
},
|
|
308
|
-
|
|
309
|
-
{
|
|
310
|
-
id: "Grid+5ad6451a841c4b3168000017",
|
|
311
|
-
parent: {
|
|
312
|
-
id: "Grid",
|
|
313
|
-
},
|
|
314
|
-
component: {
|
|
315
|
-
props: {
|
|
316
|
-
id: "Grid+5ad6451a841c4b3168000017",
|
|
317
|
-
groupId: "Grid",
|
|
318
|
-
preferredFocus: false,
|
|
319
|
-
},
|
|
320
|
-
getRect: jest.fn(() => ({
|
|
321
|
-
top: 1245,
|
|
322
|
-
left: 526,
|
|
323
|
-
right: 955,
|
|
324
|
-
bottom: 1732,
|
|
325
|
-
width: 429,
|
|
326
|
-
height: 487,
|
|
327
|
-
x: 0,
|
|
328
|
-
y: 0,
|
|
329
|
-
})),
|
|
330
|
-
},
|
|
331
|
-
},
|
|
332
|
-
|
|
333
|
-
{
|
|
334
|
-
id: "Grid+5ad50977dbc8580f24000002",
|
|
335
|
-
parent: {
|
|
336
|
-
id: "Grid",
|
|
337
|
-
},
|
|
338
|
-
component: {
|
|
339
|
-
props: {
|
|
340
|
-
id: "Grid+5ad50977dbc8580f24000002",
|
|
341
|
-
groupId: "Grid",
|
|
342
|
-
preferredFocus: false,
|
|
343
|
-
},
|
|
344
|
-
getRect: jest.fn(() => ({
|
|
345
|
-
top: 1245,
|
|
346
|
-
left: 955,
|
|
347
|
-
right: 1384,
|
|
348
|
-
bottom: 1732,
|
|
349
|
-
width: 429,
|
|
350
|
-
height: 487,
|
|
351
|
-
x: 0,
|
|
352
|
-
y: 0,
|
|
353
|
-
})),
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
|
|
357
|
-
{
|
|
358
|
-
id: "Grid+5abbb261841c4b026d00001b",
|
|
359
|
-
parent: {
|
|
360
|
-
id: "Grid",
|
|
361
|
-
},
|
|
362
|
-
component: {
|
|
363
|
-
props: {
|
|
364
|
-
id: "Grid+5abbb261841c4b026d00001b",
|
|
365
|
-
groupId: "Grid",
|
|
366
|
-
preferredFocus: false,
|
|
367
|
-
},
|
|
368
|
-
getRect: jest.fn(() => ({
|
|
369
|
-
top: 1245,
|
|
370
|
-
left: 1384,
|
|
371
|
-
right: 1813,
|
|
372
|
-
bottom: 1732,
|
|
373
|
-
width: 429,
|
|
374
|
-
height: 487,
|
|
375
|
-
x: 0,
|
|
376
|
-
y: 0,
|
|
377
|
-
})),
|
|
378
|
-
},
|
|
379
|
-
},
|
|
380
|
-
|
|
381
|
-
{
|
|
382
|
-
id: "Grid+5a553591148bb0623f00000b",
|
|
383
|
-
parent: {
|
|
384
|
-
id: "Grid",
|
|
385
|
-
},
|
|
386
|
-
component: {
|
|
387
|
-
props: {
|
|
388
|
-
id: "Grid+5a553591148bb0623f00000b",
|
|
389
|
-
groupId: "Grid",
|
|
390
|
-
preferredFocus: false,
|
|
391
|
-
},
|
|
392
|
-
getRect: jest.fn(() => ({
|
|
393
|
-
top: 1732,
|
|
394
|
-
left: 526,
|
|
395
|
-
right: 955,
|
|
396
|
-
bottom: 2219,
|
|
397
|
-
width: 429,
|
|
398
|
-
height: 487,
|
|
399
|
-
x: 0,
|
|
400
|
-
y: 0,
|
|
401
|
-
})),
|
|
402
|
-
},
|
|
403
|
-
},
|
|
404
|
-
|
|
405
|
-
{
|
|
406
|
-
id: "Grid+5a284cb8148bb006e3000002",
|
|
407
|
-
parent: {
|
|
408
|
-
id: "Grid",
|
|
409
|
-
},
|
|
410
|
-
component: {
|
|
411
|
-
props: {
|
|
412
|
-
id: "Grid+5a284cb8148bb006e3000002",
|
|
413
|
-
groupId: "Grid",
|
|
414
|
-
preferredFocus: false,
|
|
415
|
-
},
|
|
416
|
-
getRect: jest.fn(() => ({
|
|
417
|
-
top: 1732,
|
|
418
|
-
left: 955,
|
|
419
|
-
right: 1384,
|
|
420
|
-
bottom: 2219,
|
|
421
|
-
width: 429,
|
|
422
|
-
height: 487,
|
|
423
|
-
x: 0,
|
|
424
|
-
y: 0,
|
|
425
|
-
})),
|
|
426
|
-
},
|
|
427
|
-
},
|
|
428
|
-
|
|
429
|
-
{
|
|
430
|
-
id: "Grid+59dd327b2d1ca033d3000027",
|
|
431
|
-
parent: {
|
|
432
|
-
id: "Grid",
|
|
433
|
-
},
|
|
434
|
-
component: {
|
|
435
|
-
props: {
|
|
436
|
-
id: "Grid+59dd327b2d1ca033d3000027",
|
|
437
|
-
groupId: "Grid",
|
|
438
|
-
preferredFocus: false,
|
|
439
|
-
},
|
|
440
|
-
getRect: jest.fn(() => ({
|
|
441
|
-
top: 1732,
|
|
442
|
-
left: 1384,
|
|
443
|
-
right: 1813,
|
|
444
|
-
bottom: 2219,
|
|
445
|
-
width: 429,
|
|
446
|
-
height: 487,
|
|
447
|
-
x: 0,
|
|
448
|
-
y: 0,
|
|
449
|
-
})),
|
|
450
|
-
},
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
id: "Grid+594d8085fd2e611a7600002a",
|
|
454
|
-
parent: {
|
|
455
|
-
id: "Grid",
|
|
456
|
-
},
|
|
457
|
-
component: {
|
|
458
|
-
props: {
|
|
459
|
-
id: "Grid+594d8085fd2e611a7600002a",
|
|
460
|
-
groupId: "Grid",
|
|
461
|
-
preferredFocus: false,
|
|
462
|
-
},
|
|
463
|
-
getRect: jest.fn(() => ({
|
|
464
|
-
top: 2219,
|
|
465
|
-
left: 526,
|
|
466
|
-
right: 955,
|
|
467
|
-
bottom: 2706,
|
|
468
|
-
width: 429,
|
|
469
|
-
height: 487,
|
|
470
|
-
x: 0,
|
|
471
|
-
y: 0,
|
|
472
|
-
})),
|
|
473
|
-
},
|
|
474
|
-
},
|
|
475
|
-
{
|
|
476
|
-
id: "Grid+594ad354fd2e61585c000019",
|
|
477
|
-
parent: {
|
|
478
|
-
id: "Grid",
|
|
479
|
-
},
|
|
480
|
-
component: {
|
|
481
|
-
props: {
|
|
482
|
-
id: "Grid+594ad354fd2e61585c000019",
|
|
483
|
-
groupId: "Grid",
|
|
484
|
-
preferredFocus: false,
|
|
485
|
-
},
|
|
486
|
-
getRect: jest.fn(() => ({
|
|
487
|
-
top: 2219,
|
|
488
|
-
left: 955,
|
|
489
|
-
right: 1384,
|
|
490
|
-
bottom: 2706,
|
|
491
|
-
width: 429,
|
|
492
|
-
height: 487,
|
|
493
|
-
x: 0,
|
|
494
|
-
y: 0,
|
|
495
|
-
})),
|
|
496
|
-
},
|
|
497
|
-
},
|
|
498
|
-
{
|
|
499
|
-
id: "Grid+59405d44b57ac32c80000014",
|
|
500
|
-
parent: {
|
|
501
|
-
id: "Grid",
|
|
502
|
-
},
|
|
503
|
-
component: {
|
|
504
|
-
props: {
|
|
505
|
-
id: "Grid+59405d44b57ac32c80000014",
|
|
506
|
-
groupId: "Grid",
|
|
507
|
-
preferredFocus: false,
|
|
508
|
-
},
|
|
509
|
-
getRect: jest.fn(() => ({
|
|
510
|
-
top: 2219,
|
|
511
|
-
left: 1384,
|
|
512
|
-
right: 1813,
|
|
513
|
-
bottom: 2706,
|
|
514
|
-
width: 429,
|
|
515
|
-
height: 487,
|
|
516
|
-
x: 0,
|
|
517
|
-
y: 0,
|
|
518
|
-
})),
|
|
519
|
-
},
|
|
520
|
-
},
|
|
521
|
-
],
|
|
522
|
-
component: {
|
|
523
|
-
props: {
|
|
524
|
-
id: "Grid",
|
|
525
|
-
groupId: "ScreenPicker.ScreenContainer",
|
|
526
|
-
preferredFocus: true,
|
|
527
|
-
},
|
|
528
|
-
getRect: jest.fn(() => ({
|
|
529
|
-
top: 661,
|
|
530
|
-
left: 412,
|
|
531
|
-
right: 1912,
|
|
532
|
-
bottom: 2706,
|
|
533
|
-
width: 1500,
|
|
534
|
-
height: 2045,
|
|
535
|
-
x: 0,
|
|
536
|
-
y: 0,
|
|
537
|
-
})),
|
|
538
|
-
},
|
|
539
|
-
},
|
|
540
|
-
{
|
|
541
|
-
id: "Hero",
|
|
542
|
-
parent: {
|
|
543
|
-
id: "ScreenPicker.ScreenContainer",
|
|
544
|
-
},
|
|
545
|
-
children: [
|
|
546
|
-
{
|
|
547
|
-
id: "Hero+5ad6451a841c4b3168000017",
|
|
548
|
-
parent: {
|
|
549
|
-
id: "Hero",
|
|
550
|
-
},
|
|
551
|
-
component: {
|
|
552
|
-
props: {
|
|
553
|
-
id: "Hero+5ad6451a841c4b3168000017",
|
|
554
|
-
groupId: "Hero",
|
|
555
|
-
preferredFocus: false,
|
|
556
|
-
},
|
|
557
|
-
getRect: jest.fn(() => ({
|
|
558
|
-
top: 180,
|
|
559
|
-
left: -596,
|
|
560
|
-
right: 558,
|
|
561
|
-
bottom: 661,
|
|
562
|
-
width: 1154,
|
|
563
|
-
height: 481,
|
|
564
|
-
x: 0,
|
|
565
|
-
y: 0,
|
|
566
|
-
})),
|
|
567
|
-
},
|
|
568
|
-
},
|
|
569
|
-
|
|
570
|
-
{
|
|
571
|
-
id: "Hero+5bc7813a8c1abc222700000e",
|
|
572
|
-
parent: {
|
|
573
|
-
id: "Hero",
|
|
574
|
-
},
|
|
575
|
-
component: {
|
|
576
|
-
props: {
|
|
577
|
-
id: "Hero+5bc7813a8c1abc222700000e",
|
|
578
|
-
groupId: "Hero",
|
|
579
|
-
preferredFocus: false,
|
|
580
|
-
},
|
|
581
|
-
getRect: jest.fn(() => ({
|
|
582
|
-
top: 180,
|
|
583
|
-
left: 558,
|
|
584
|
-
right: 1712,
|
|
585
|
-
bottom: 661,
|
|
586
|
-
width: 1154,
|
|
587
|
-
height: 481,
|
|
588
|
-
x: 0,
|
|
589
|
-
y: 0,
|
|
590
|
-
})),
|
|
591
|
-
},
|
|
592
|
-
},
|
|
593
|
-
{
|
|
594
|
-
id: "Hero+5af0a05a841c4b344c00002a",
|
|
595
|
-
parent: {
|
|
596
|
-
id: "Hero",
|
|
597
|
-
},
|
|
598
|
-
component: {
|
|
599
|
-
props: {
|
|
600
|
-
id: "Hero+5af0a05a841c4b344c00002a",
|
|
601
|
-
groupId: "Hero",
|
|
602
|
-
preferredFocus: true,
|
|
603
|
-
},
|
|
604
|
-
getRect: jest.fn(() => ({
|
|
605
|
-
top: 180,
|
|
606
|
-
left: 1712,
|
|
607
|
-
right: 2866,
|
|
608
|
-
bottom: 661,
|
|
609
|
-
width: 1154,
|
|
610
|
-
height: 481,
|
|
611
|
-
x: 0,
|
|
612
|
-
y: 0,
|
|
613
|
-
})),
|
|
614
|
-
},
|
|
615
|
-
},
|
|
616
|
-
|
|
617
|
-
{
|
|
618
|
-
id: "Hero+5ae9f107dbc8585711000011",
|
|
619
|
-
parent: {
|
|
620
|
-
id: "Hero",
|
|
621
|
-
},
|
|
622
|
-
component: {
|
|
623
|
-
props: {
|
|
624
|
-
id: "Hero+5ae9f107dbc8585711000011",
|
|
625
|
-
groupId: "Hero",
|
|
626
|
-
preferredFocus: false,
|
|
627
|
-
},
|
|
628
|
-
getRect: jest.fn(() => ({
|
|
629
|
-
top: 180,
|
|
630
|
-
left: 2866,
|
|
631
|
-
right: 4020,
|
|
632
|
-
bottom: 661,
|
|
633
|
-
width: 1154,
|
|
634
|
-
height: 481,
|
|
635
|
-
x: 0,
|
|
636
|
-
y: 0,
|
|
637
|
-
})),
|
|
638
|
-
},
|
|
639
|
-
},
|
|
640
|
-
],
|
|
641
|
-
component: {
|
|
642
|
-
props: {
|
|
643
|
-
id: "Hero",
|
|
644
|
-
groupId: "ScreenPicker.ScreenContainer",
|
|
645
|
-
preferredFocus: true,
|
|
646
|
-
},
|
|
647
|
-
getRect: jest.fn(() => ({
|
|
648
|
-
top: 131,
|
|
649
|
-
left: 412,
|
|
650
|
-
right: 1912,
|
|
651
|
-
bottom: 661,
|
|
652
|
-
width: 1500,
|
|
653
|
-
height: 530,
|
|
654
|
-
x: 0,
|
|
655
|
-
y: 0,
|
|
656
|
-
})),
|
|
657
|
-
},
|
|
658
|
-
},
|
|
659
|
-
],
|
|
660
|
-
component: {
|
|
661
|
-
props: {
|
|
662
|
-
id: "ScreenPicker.ScreenContainer",
|
|
663
|
-
groupId: "ScreenPicker",
|
|
664
|
-
preferredFocus: false,
|
|
665
|
-
},
|
|
666
|
-
getRect: jest.fn(() => ({
|
|
667
|
-
top: 101,
|
|
668
|
-
left: 412,
|
|
669
|
-
right: 1912,
|
|
670
|
-
bottom: 2186,
|
|
671
|
-
width: 1500,
|
|
672
|
-
height: 2085,
|
|
673
|
-
x: 0,
|
|
674
|
-
y: 0,
|
|
675
|
-
})),
|
|
676
|
-
},
|
|
677
|
-
},
|
|
678
|
-
],
|
|
679
|
-
component: {
|
|
680
|
-
props: {
|
|
681
|
-
id: "ScreenPicker",
|
|
682
|
-
preferredFocus: true,
|
|
683
|
-
},
|
|
684
|
-
getRect: jest.fn(() => ({
|
|
685
|
-
top: 100,
|
|
686
|
-
left: 0,
|
|
687
|
-
right: 1920,
|
|
688
|
-
bottom: 2186,
|
|
689
|
-
width: 1920,
|
|
690
|
-
height: 2086,
|
|
691
|
-
x: 0,
|
|
692
|
-
y: 0,
|
|
693
|
-
})),
|
|
694
|
-
},
|
|
695
|
-
},
|
|
696
|
-
],
|
|
697
|
-
},
|
|
698
|
-
};
|
|
699
|
-
|
|
700
|
-
const priorityMock = [
|
|
701
|
-
{
|
|
702
|
-
id: "child1",
|
|
703
|
-
parent: { id: "parent1", lastFocusedItem: "child5" },
|
|
704
|
-
component: {
|
|
705
|
-
props: { id: "child1", preferredFocus: false, selected: false },
|
|
706
|
-
},
|
|
707
|
-
},
|
|
708
|
-
{
|
|
709
|
-
id: "child2",
|
|
710
|
-
parent: { id: "parent1", lastFocusedItem: "child5" },
|
|
711
|
-
component: {
|
|
712
|
-
props: { id: "child2", preferredFocus: true, selected: false },
|
|
713
|
-
},
|
|
714
|
-
},
|
|
715
|
-
{
|
|
716
|
-
id: "child3",
|
|
717
|
-
parent: { id: "parent1", lastFocusedItem: "child5" },
|
|
718
|
-
component: {
|
|
719
|
-
props: { id: "child3", preferredFocus: false, selected: false },
|
|
720
|
-
},
|
|
721
|
-
},
|
|
722
|
-
{
|
|
723
|
-
id: "child4",
|
|
724
|
-
parent: { id: "parent1", lastFocusedItem: "child5" },
|
|
725
|
-
component: {
|
|
726
|
-
props: { id: "child4", preferredFocus: false, selected: true },
|
|
727
|
-
},
|
|
728
|
-
},
|
|
729
|
-
{
|
|
730
|
-
id: "child5",
|
|
731
|
-
parent: { id: "parent1", lastFocusedItem: "child5" },
|
|
732
|
-
component: {
|
|
733
|
-
props: { id: "child5", preferredFocus: false, selected: false },
|
|
734
|
-
},
|
|
735
|
-
},
|
|
736
|
-
];
|
|
737
|
-
|
|
738
|
-
const priorityMock2 = [
|
|
739
|
-
{
|
|
740
|
-
id: "child1",
|
|
741
|
-
parent: { id: "parent1", lastFocusedItem: "child5" },
|
|
742
|
-
component: {
|
|
743
|
-
props: { id: "child1", preferredFocus: false, selected: false },
|
|
744
|
-
},
|
|
745
|
-
},
|
|
746
|
-
{
|
|
747
|
-
id: "child2",
|
|
748
|
-
parent: { id: "parent1", lastFocusedItem: "child5" },
|
|
749
|
-
component: {
|
|
750
|
-
props: { id: "child2", preferredFocus: true, selected: false },
|
|
751
|
-
},
|
|
752
|
-
},
|
|
753
|
-
{
|
|
754
|
-
id: "child3",
|
|
755
|
-
parent: { id: "parent1", lastFocusedItem: "child5" },
|
|
756
|
-
component: {
|
|
757
|
-
props: { id: "child3", preferredFocus: false, selected: false },
|
|
758
|
-
},
|
|
759
|
-
},
|
|
760
|
-
{
|
|
761
|
-
id: "child4",
|
|
762
|
-
parent: { id: "parent1", lastFocusedItem: "child5" },
|
|
763
|
-
component: {
|
|
764
|
-
props: { id: "child4", preferredFocus: false, selected: false },
|
|
765
|
-
},
|
|
766
|
-
},
|
|
767
|
-
{
|
|
768
|
-
id: "child5",
|
|
769
|
-
parent: { id: "parent1", lastFocusedItem: "child5" },
|
|
770
|
-
component: {
|
|
771
|
-
props: { id: "child5", preferredFocus: false, selected: false },
|
|
772
|
-
},
|
|
773
|
-
},
|
|
774
|
-
];
|
|
775
|
-
|
|
776
|
-
const priorityMock3 = [
|
|
777
|
-
{
|
|
778
|
-
id: "child1",
|
|
779
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
780
|
-
component: {
|
|
781
|
-
props: { id: "child1", preferredFocus: false, selected: false },
|
|
782
|
-
},
|
|
783
|
-
},
|
|
784
|
-
{
|
|
785
|
-
id: "child2",
|
|
786
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
787
|
-
component: {
|
|
788
|
-
props: { id: "child2", preferredFocus: true, selected: false },
|
|
789
|
-
},
|
|
790
|
-
},
|
|
791
|
-
{
|
|
792
|
-
id: "child3",
|
|
793
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
794
|
-
component: {
|
|
795
|
-
props: { id: "child3", preferredFocus: false, selected: false },
|
|
796
|
-
},
|
|
797
|
-
},
|
|
798
|
-
{
|
|
799
|
-
id: "child4",
|
|
800
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
801
|
-
component: {
|
|
802
|
-
props: { id: "child4", preferredFocus: false, selected: false },
|
|
803
|
-
},
|
|
804
|
-
},
|
|
805
|
-
{
|
|
806
|
-
id: "child5",
|
|
807
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
808
|
-
component: {
|
|
809
|
-
props: { id: "child5", preferredFocus: false, selected: false },
|
|
810
|
-
},
|
|
811
|
-
},
|
|
812
|
-
];
|
|
813
|
-
|
|
814
|
-
const priorityMock4 = [
|
|
815
|
-
{
|
|
816
|
-
id: "child1",
|
|
817
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
818
|
-
component: {
|
|
819
|
-
props: { id: "child1", preferredFocus: false, selected: false },
|
|
820
|
-
},
|
|
821
|
-
},
|
|
822
|
-
{
|
|
823
|
-
id: "child2",
|
|
824
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
825
|
-
component: {
|
|
826
|
-
props: { id: "child2", preferredFocus: false, selected: false },
|
|
827
|
-
},
|
|
828
|
-
},
|
|
829
|
-
{
|
|
830
|
-
id: "child3",
|
|
831
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
832
|
-
component: {
|
|
833
|
-
props: { id: "child3", preferredFocus: false, selected: false },
|
|
834
|
-
},
|
|
835
|
-
},
|
|
836
|
-
{
|
|
837
|
-
id: "child4",
|
|
838
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
839
|
-
component: {
|
|
840
|
-
props: { id: "child4", preferredFocus: false, selected: false },
|
|
841
|
-
},
|
|
842
|
-
},
|
|
843
|
-
{
|
|
844
|
-
id: "child5",
|
|
845
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
846
|
-
component: {
|
|
847
|
-
props: { id: "child5", preferredFocus: false, selected: false },
|
|
848
|
-
},
|
|
849
|
-
},
|
|
850
|
-
];
|
|
851
|
-
|
|
852
|
-
function prepareMock(node) {
|
|
853
|
-
if (node.children) {
|
|
854
|
-
node.children.forEach((child) => {
|
|
855
|
-
child.parent = node;
|
|
856
|
-
prepareMock(child);
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
function treeLoaded() {}
|
|
862
|
-
|
|
863
|
-
describe("findFocusableNode", () => {
|
|
864
|
-
const mockScreen = screenMock1;
|
|
865
|
-
prepareMock(mockScreen.root);
|
|
866
|
-
const tree = new Tree(treeLoaded);
|
|
867
|
-
tree.root = mockScreen.root;
|
|
868
|
-
const selectedHero = tree.findInTree("Hero+5bc7813a8c1abc222700000e");
|
|
869
|
-
const expectedOnRight = tree.findInTree("Hero+5af0a05a841c4b344c00002a");
|
|
870
|
-
|
|
871
|
-
it("return expectedOnRight component when moving right direction", async () => {
|
|
872
|
-
const foundNode = await findFocusableNode(
|
|
873
|
-
directionMocks.right,
|
|
874
|
-
selectedHero
|
|
875
|
-
);
|
|
876
|
-
|
|
877
|
-
expect(foundNode).toEqual(expectedOnRight);
|
|
878
|
-
});
|
|
879
|
-
|
|
880
|
-
// TODO this should change with new functionality of screen picker selector on left.
|
|
881
|
-
const expectedOnLeft = tree.findInTree("Hero+5ad6451a841c4b3168000017");
|
|
882
|
-
|
|
883
|
-
it("return expectedOnLeft component when moving left direction", async () => {
|
|
884
|
-
const foundNode = await findFocusableNode(
|
|
885
|
-
directionMocks.left,
|
|
886
|
-
selectedHero
|
|
887
|
-
);
|
|
888
|
-
|
|
889
|
-
expect(foundNode).toEqual(expectedOnLeft);
|
|
890
|
-
});
|
|
891
|
-
|
|
892
|
-
it("return preferred menu id a892edf2-ceb6-425f-8fdb-3e58b38b233e component when moving up direction", async () => {
|
|
893
|
-
const foundNode = await findFocusableNode(directionMocks.up, selectedHero);
|
|
894
|
-
expect(foundNode.id).toEqual("a892edf2-ceb6-425f-8fdb-3e58b38b233e");
|
|
895
|
-
});
|
|
896
|
-
|
|
897
|
-
it("return preferred grid id Grid+5bc7813a8c1abc222700000e component when moving down direction", async () => {
|
|
898
|
-
const foundNode = await findFocusableNode(
|
|
899
|
-
directionMocks.down,
|
|
900
|
-
selectedHero
|
|
901
|
-
);
|
|
902
|
-
|
|
903
|
-
expect(foundNode.id).toEqual("Grid+5bc7813a8c1abc222700000e");
|
|
904
|
-
});
|
|
905
|
-
});
|
|
906
|
-
|
|
907
|
-
describe("getSelectedItems", () => {
|
|
908
|
-
it("return size 1 of array and child4 for first item.id if parent currently selected item is child4", () => {
|
|
909
|
-
const selectedItems = getSelectedItems(priorityMock);
|
|
910
|
-
expect(selectedItems.length).toEqual(1);
|
|
911
|
-
expect(selectedItems[0].id).toEqual("child4");
|
|
912
|
-
});
|
|
913
|
-
});
|
|
914
|
-
|
|
915
|
-
describe("getLastFocusedItems", () => {
|
|
916
|
-
it("return size 1 of array and child5 for first item.id if parent last focused item is child5", () => {
|
|
917
|
-
const lastFocusedItems = getLastFocusedItems(priorityMock);
|
|
918
|
-
expect(lastFocusedItems.length).toEqual(1);
|
|
919
|
-
expect(lastFocusedItems[0].id).toEqual("child5");
|
|
920
|
-
});
|
|
921
|
-
});
|
|
922
|
-
|
|
923
|
-
describe("getPreferableItems", () => {
|
|
924
|
-
it("return size 1 of array and child2 for first item.id for preferable item", () => {
|
|
925
|
-
const preferableItems = getPreferableItems(priorityMock);
|
|
926
|
-
expect(preferableItems.length).toEqual(1);
|
|
927
|
-
expect(preferableItems[0].id).toEqual("child2");
|
|
928
|
-
});
|
|
929
|
-
});
|
|
930
|
-
|
|
931
|
-
describe("getPriorityItems", () => {
|
|
932
|
-
it("return size 1 of array and child4 for first item.id for currently selected item.", () => {
|
|
933
|
-
const priorityItems = getPriorityItems(priorityMock);
|
|
934
|
-
expect(priorityItems.length).toEqual(1);
|
|
935
|
-
expect(priorityItems[0].id).toEqual("child4");
|
|
936
|
-
});
|
|
937
|
-
|
|
938
|
-
it(`return size 1 of array and child5 for first item.id
|
|
939
|
-
if there is no currently selected item is child4`, () => {
|
|
940
|
-
const priorityItems = getPriorityItems(priorityMock2);
|
|
941
|
-
expect(priorityItems.length).toEqual(1);
|
|
942
|
-
expect(priorityItems[0].id).toEqual("child5");
|
|
943
|
-
});
|
|
944
|
-
|
|
945
|
-
it(`return size 1 of array and child2 for first item.id
|
|
946
|
-
if there is no last focused or currently selected item.`, () => {
|
|
947
|
-
const priorityItems = getPriorityItems(priorityMock3);
|
|
948
|
-
expect(priorityItems.length).toEqual(1);
|
|
949
|
-
expect(priorityItems[0].id).toEqual("child2");
|
|
950
|
-
});
|
|
951
|
-
|
|
952
|
-
it(`return size 1 of array and child1 for first item.id
|
|
953
|
-
if there is no last focused, preferable or currently selected item.`, () => {
|
|
954
|
-
const priorityItems = getPriorityItems(priorityMock4);
|
|
955
|
-
expect(priorityItems.length).toEqual(1);
|
|
956
|
-
expect(priorityItems[0].id).toEqual("child1");
|
|
957
|
-
});
|
|
958
|
-
});
|
|
959
|
-
|
|
960
|
-
const componentMock1 = {
|
|
961
|
-
id: "componentMock",
|
|
962
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
963
|
-
component: {
|
|
964
|
-
props: {
|
|
965
|
-
id: "componentMock",
|
|
966
|
-
prioritiseFocusOn: FocusDirection.UP | FocusDirection.LEFT,
|
|
967
|
-
preferredFocus: false,
|
|
968
|
-
selected: false,
|
|
969
|
-
},
|
|
970
|
-
},
|
|
971
|
-
};
|
|
972
|
-
|
|
973
|
-
const componentMock2 = {
|
|
974
|
-
id: "componentMock",
|
|
975
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
976
|
-
component: {
|
|
977
|
-
props: {
|
|
978
|
-
id: "componentMock",
|
|
979
|
-
prioritiseFocusOn:
|
|
980
|
-
FocusDirection.UP |
|
|
981
|
-
FocusDirection.LEFT |
|
|
982
|
-
FocusDirection.DOWN |
|
|
983
|
-
FocusDirection.RIGHT,
|
|
984
|
-
preferredFocus: false,
|
|
985
|
-
selected: false,
|
|
986
|
-
},
|
|
987
|
-
},
|
|
988
|
-
};
|
|
989
|
-
|
|
990
|
-
const componentMock3 = {
|
|
991
|
-
id: "componentMock",
|
|
992
|
-
parent: { id: "parent1", lastFocusedItem: null },
|
|
993
|
-
component: {
|
|
994
|
-
props: {
|
|
995
|
-
id: "componentMock",
|
|
996
|
-
preferredFocus: false,
|
|
997
|
-
selected: false,
|
|
998
|
-
},
|
|
999
|
-
},
|
|
1000
|
-
};
|
|
1001
|
-
|
|
1002
|
-
describe("hasPriorityInDirection", () => {
|
|
1003
|
-
it(`return true for up and left directions and return false for right and bottom,
|
|
1004
|
-
when input prioritiseFocusOn is .TOP or .LEFT`, () => {
|
|
1005
|
-
const hasPriorityInUpDirection = hasPriorityInDirection(
|
|
1006
|
-
directionMocks.up,
|
|
1007
|
-
componentMock1.component
|
|
1008
|
-
);
|
|
1009
|
-
|
|
1010
|
-
expect(hasPriorityInUpDirection).toEqual(true);
|
|
1011
|
-
|
|
1012
|
-
const hasPriorityInDownDirection = hasPriorityInDirection(
|
|
1013
|
-
directionMocks.down,
|
|
1014
|
-
componentMock1.component
|
|
1015
|
-
);
|
|
1016
|
-
|
|
1017
|
-
expect(hasPriorityInDownDirection).toEqual(false);
|
|
1018
|
-
|
|
1019
|
-
const hasPriorityInLeftDirection = hasPriorityInDirection(
|
|
1020
|
-
directionMocks.left,
|
|
1021
|
-
componentMock1.component
|
|
1022
|
-
);
|
|
1023
|
-
|
|
1024
|
-
expect(hasPriorityInLeftDirection).toEqual(true);
|
|
1025
|
-
|
|
1026
|
-
const hasPriorityInRightDirection = hasPriorityInDirection(
|
|
1027
|
-
directionMocks.right,
|
|
1028
|
-
componentMock1.component
|
|
1029
|
-
);
|
|
1030
|
-
|
|
1031
|
-
expect(hasPriorityInRightDirection).toEqual(false);
|
|
1032
|
-
});
|
|
1033
|
-
|
|
1034
|
-
it(`return true for in any direction, when input
|
|
1035
|
-
prioritiseFocusOn is .TOP or .LEFT or .BOTTOM or .RIGHT`, () => {
|
|
1036
|
-
const hasPriorityInUpDirection = hasPriorityInDirection(
|
|
1037
|
-
directionMocks.up,
|
|
1038
|
-
componentMock2.component
|
|
1039
|
-
);
|
|
1040
|
-
|
|
1041
|
-
expect(hasPriorityInUpDirection).toEqual(true);
|
|
1042
|
-
|
|
1043
|
-
const hasPriorityInDownDirection = hasPriorityInDirection(
|
|
1044
|
-
directionMocks.down,
|
|
1045
|
-
componentMock2.component
|
|
1046
|
-
);
|
|
1047
|
-
|
|
1048
|
-
expect(hasPriorityInDownDirection).toEqual(true);
|
|
1049
|
-
|
|
1050
|
-
const hasPriorityInLeftDirection = hasPriorityInDirection(
|
|
1051
|
-
directionMocks.left,
|
|
1052
|
-
componentMock2.component
|
|
1053
|
-
);
|
|
1054
|
-
|
|
1055
|
-
expect(hasPriorityInLeftDirection).toEqual(true);
|
|
1056
|
-
|
|
1057
|
-
const hasPriorityInRightDirection = hasPriorityInDirection(
|
|
1058
|
-
directionMocks.right,
|
|
1059
|
-
componentMock2.component
|
|
1060
|
-
);
|
|
1061
|
-
|
|
1062
|
-
expect(hasPriorityInRightDirection).toEqual(true);
|
|
1063
|
-
});
|
|
1064
|
-
|
|
1065
|
-
it("return false for in any direction, when input prioritiseFocusOn is not defined", () => {
|
|
1066
|
-
const hasPriorityInUpDirection = hasPriorityInDirection(
|
|
1067
|
-
directionMocks.up,
|
|
1068
|
-
componentMock3.component
|
|
1069
|
-
);
|
|
1070
|
-
|
|
1071
|
-
expect(hasPriorityInUpDirection).toEqual(false);
|
|
1072
|
-
|
|
1073
|
-
const hasPriorityInDownDirection = hasPriorityInDirection(
|
|
1074
|
-
directionMocks.down,
|
|
1075
|
-
componentMock3.component
|
|
1076
|
-
);
|
|
1077
|
-
|
|
1078
|
-
expect(hasPriorityInDownDirection).toEqual(false);
|
|
1079
|
-
|
|
1080
|
-
const hasPriorityInLeftDirection = hasPriorityInDirection(
|
|
1081
|
-
directionMocks.left,
|
|
1082
|
-
componentMock3.component
|
|
1083
|
-
);
|
|
1084
|
-
|
|
1085
|
-
expect(hasPriorityInLeftDirection).toEqual(false);
|
|
1086
|
-
|
|
1087
|
-
const hasPriorityInRightDirection = hasPriorityInDirection(
|
|
1088
|
-
directionMocks.right,
|
|
1089
|
-
componentMock3.component
|
|
1090
|
-
);
|
|
1091
|
-
|
|
1092
|
-
expect(hasPriorityInRightDirection).toEqual(false);
|
|
1093
|
-
});
|
|
1094
|
-
});
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import * as R from "ramda";
|
|
2
|
-
import { rejectItemByPath } from "../../../../objectUtils";
|
|
3
|
-
import {
|
|
4
|
-
measureDistance,
|
|
5
|
-
measureEuclidianDistanceToCenter,
|
|
6
|
-
} from "@applicaster/zapp-react-native-utils/rectUtils";
|
|
7
|
-
|
|
8
|
-
import { mapAsync } from "../../../../functionUtils";
|
|
9
|
-
|
|
10
|
-
export const FocusDirection = {
|
|
11
|
-
LEFT: 1,
|
|
12
|
-
TOP: 2,
|
|
13
|
-
RIGHT: 4,
|
|
14
|
-
BOTTOM: 8,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Function search down the tree for priority item in given children array.
|
|
19
|
-
* Priorities are:
|
|
20
|
-
* Priority 1: Currently selected item - like a menu item
|
|
21
|
-
* Priority 2: Previously focused item in the parent group
|
|
22
|
-
* Priority 3: Preferrable items - items which have been marked as preferable
|
|
23
|
-
* Priority 4: First item on the list - if by any accident above priories are not satisfied
|
|
24
|
-
* @private
|
|
25
|
-
* @param {Array} children
|
|
26
|
-
* @returns focusable priority item.
|
|
27
|
-
*/
|
|
28
|
-
export function findPriorityItem(children) {
|
|
29
|
-
let preferedGroups = getPriorityItems(children);
|
|
30
|
-
|
|
31
|
-
if (preferedGroups.length > 0 && !preferedGroups[0].children) {
|
|
32
|
-
return preferedGroups;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
preferedGroups = preferedGroups.filter(
|
|
36
|
-
(it) =>
|
|
37
|
-
it.children &&
|
|
38
|
-
it.children.length > 0 &&
|
|
39
|
-
it.children.filter((obj) => obj && obj.component.props.preferredFocus)
|
|
40
|
-
.length > 0
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
while (
|
|
44
|
-
preferedGroups.length > 0 &&
|
|
45
|
-
preferedGroups[0].children &&
|
|
46
|
-
preferedGroups[0].children.length > 0
|
|
47
|
-
) {
|
|
48
|
-
preferedGroups = getPriorityItems(preferedGroups[0].children);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return preferedGroups;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Function search for currently selected item - like a menu item.
|
|
56
|
-
* @private
|
|
57
|
-
* @param {Array} children
|
|
58
|
-
* @returns array of selected items
|
|
59
|
-
*/
|
|
60
|
-
export function getSelectedItems(children) {
|
|
61
|
-
const selectedItems = children.filter(
|
|
62
|
-
(obj) => obj && obj.component.props.selected
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
return selectedItems;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Function search for previously focused item in the parent group.
|
|
70
|
-
* @private
|
|
71
|
-
* @param {Array} children
|
|
72
|
-
* @returns array of last focus items
|
|
73
|
-
*/
|
|
74
|
-
export function getLastFocusedItems(children) {
|
|
75
|
-
const lastFocusedItems = children.filter(
|
|
76
|
-
(obj) => obj && obj.id === obj.parent.lastFocusedItem
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
return lastFocusedItems;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Function search for items which have been marked as preferable.
|
|
84
|
-
* @private
|
|
85
|
-
* @param {Array} children
|
|
86
|
-
* @returns array of prefereable focus items
|
|
87
|
-
*/
|
|
88
|
-
export function getPreferableItems(children) {
|
|
89
|
-
const preferredItems = children.filter(
|
|
90
|
-
(obj) => obj && obj.component.props.preferredFocus
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
return preferredItems;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Function search for priority items in children array. Priorities are:
|
|
98
|
-
* Priority 1: Currently selected item - like a menu item
|
|
99
|
-
* Priority 2: Previously focused item in the parent group
|
|
100
|
-
* Priority 3: Preferrable items - items which have been marked as preferable
|
|
101
|
-
* Priority 4: First item on the list - if by any accident above priories are not satisfied
|
|
102
|
-
* @private
|
|
103
|
-
* @param {Array} children
|
|
104
|
-
* @returns array of pririty focus items
|
|
105
|
-
*/
|
|
106
|
-
export function getPriorityItems(children) {
|
|
107
|
-
const selectedItems = getSelectedItems(children);
|
|
108
|
-
const lastFocusedItems = getLastFocusedItems(children);
|
|
109
|
-
const preferredItems = getPreferableItems(children);
|
|
110
|
-
|
|
111
|
-
if (selectedItems.length > 0) {
|
|
112
|
-
return selectedItems;
|
|
113
|
-
} else if (lastFocusedItems.length > 0) {
|
|
114
|
-
return lastFocusedItems;
|
|
115
|
-
} else if (preferredItems.length > 0) {
|
|
116
|
-
return preferredItems;
|
|
117
|
-
} else if (children.length > 0) {
|
|
118
|
-
return [children[0]];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return [];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Get target in shortest distance in specified direction
|
|
126
|
-
* @private
|
|
127
|
-
* @param {Object} direction of the navigation, which led to this focus change
|
|
128
|
-
* @param {Object} excludedNode node which should be excluded from target group
|
|
129
|
-
* @param {Array} targetNodes array of input target nodes
|
|
130
|
-
* @param {Object} comparisonRect rectangle to compare sides in direction.
|
|
131
|
-
* @returns {Object} target in direction.
|
|
132
|
-
*/
|
|
133
|
-
export async function getTargetInDirection(
|
|
134
|
-
direction,
|
|
135
|
-
excludedNode,
|
|
136
|
-
targetNodes,
|
|
137
|
-
comparisonRect
|
|
138
|
-
) {
|
|
139
|
-
const targets = rejectItemByPath(["id"], excludedNode.id, targetNodes);
|
|
140
|
-
|
|
141
|
-
const targetsWithDistances = await mapAsync(async (target) => {
|
|
142
|
-
const targetRect = await target.component.getRect();
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
distance: measureDistance(direction, comparisonRect, targetRect),
|
|
146
|
-
euclidianDistance: measureEuclidianDistanceToCenter(
|
|
147
|
-
comparisonRect,
|
|
148
|
-
targetRect
|
|
149
|
-
),
|
|
150
|
-
target,
|
|
151
|
-
targetRect,
|
|
152
|
-
};
|
|
153
|
-
}, targets);
|
|
154
|
-
|
|
155
|
-
const distances = targetsWithDistances.filter((obj) => obj.distance >= 0);
|
|
156
|
-
|
|
157
|
-
if (!distances || distances.length === 0) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const match = R.compose(
|
|
162
|
-
R.head,
|
|
163
|
-
R.sortBy((it) => it.euclidianDistance),
|
|
164
|
-
R.head,
|
|
165
|
-
R.values,
|
|
166
|
-
R.groupBy((it) => it.distance)
|
|
167
|
-
)(distances);
|
|
168
|
-
|
|
169
|
-
return match ? match.target : null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Find focusable node in direction from currentFocusedNode.
|
|
174
|
-
* If it does not find a node in current group it seach parent node
|
|
175
|
-
* incuding deep search inside simbilngs of parent. Search goes up the tree
|
|
176
|
-
* until find next focusable item or tree ends.
|
|
177
|
-
* @public
|
|
178
|
-
* @param {Object} direction of the navigation, which led to this focus change
|
|
179
|
-
* @param {Object} currentFocusNode currently focused node as start point of search
|
|
180
|
-
* @returns {Object} focusable node in direction.
|
|
181
|
-
*/
|
|
182
|
-
export async function findFocusableNode(direction, currentFocusNode) {
|
|
183
|
-
const currentFocusable = currentFocusNode.component || null;
|
|
184
|
-
|
|
185
|
-
if (currentFocusable) {
|
|
186
|
-
const currentFocusableRect = await currentFocusable.getRect();
|
|
187
|
-
|
|
188
|
-
let focusableNode = await getTargetInDirection(
|
|
189
|
-
direction,
|
|
190
|
-
currentFocusNode,
|
|
191
|
-
currentFocusNode.parent.children,
|
|
192
|
-
currentFocusableRect
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
const parentHasPriority =
|
|
196
|
-
currentFocusNode.parent.component &&
|
|
197
|
-
hasPriorityInDirection(direction, currentFocusNode.parent.component);
|
|
198
|
-
|
|
199
|
-
const canFindParentSibling = await findFocusableNode(
|
|
200
|
-
direction,
|
|
201
|
-
currentFocusNode.parent
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
if (parentHasPriority && canFindParentSibling) {
|
|
205
|
-
return canFindParentSibling;
|
|
206
|
-
} else if (focusableNode && focusableNode.component) {
|
|
207
|
-
// inside group
|
|
208
|
-
return focusableNode;
|
|
209
|
-
} else {
|
|
210
|
-
// outside group
|
|
211
|
-
let parentFocusableNode = currentFocusNode;
|
|
212
|
-
|
|
213
|
-
// going up the structure untill sibling node
|
|
214
|
-
while (
|
|
215
|
-
!focusableNode &&
|
|
216
|
-
parentFocusableNode &&
|
|
217
|
-
parentFocusableNode.parent &&
|
|
218
|
-
parentFocusableNode.parent.parent
|
|
219
|
-
) {
|
|
220
|
-
parentFocusableNode = parentFocusableNode.parent;
|
|
221
|
-
|
|
222
|
-
focusableNode = await getTargetInDirection(
|
|
223
|
-
direction,
|
|
224
|
-
parentFocusableNode, // excluded sibling parent of current focuable
|
|
225
|
-
parentFocusableNode.parent.children, // siblings of parent
|
|
226
|
-
currentFocusableRect
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (focusableNode) {
|
|
231
|
-
const preferred = findPriorityItem(focusableNode.children);
|
|
232
|
-
|
|
233
|
-
return preferred[0];
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Checks of component has priority in the direction. It is used to navigate
|
|
241
|
-
* outside of the group if group has priotity in specified direction.
|
|
242
|
-
* @public
|
|
243
|
-
* @param {Object} direction of the navigation, which led to this focus change
|
|
244
|
-
* @param {Object} component - object to check props.prioritiseFocusOn
|
|
245
|
-
* @returns {Boolean} TRUE if object has priority in direction.
|
|
246
|
-
* @returns {Boolean} FALSE if object has NO priority in direction.
|
|
247
|
-
*/
|
|
248
|
-
export function hasPriorityInDirection(direction, component) {
|
|
249
|
-
const { prioritiseFocusOn = 0 } = component.props;
|
|
250
|
-
|
|
251
|
-
const directionMapper = {
|
|
252
|
-
left: 1,
|
|
253
|
-
up: 2,
|
|
254
|
-
right: 4,
|
|
255
|
-
down: 8,
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
const mappedDirection = directionMapper[direction.value];
|
|
259
|
-
|
|
260
|
-
return (prioritiseFocusOn & mappedDirection) > 0;
|
|
261
|
-
}
|