@tantawowa/hosanna-ui 2.1.0 → 2.3.0

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.
@@ -7,7 +7,7 @@ import {
7
7
  CollectionViewItemBounds,
8
8
  } from './CollectionViewAPI';
9
9
  import { IAudioGuideItem, IReusable } from '@hs-src/hosanna-ui/hosanna-api';
10
- import { IViewFragment } from '@hs-src/hosanna-ui/views/lib/AppConfig';
10
+ import { IViewFragment, ViewFragmentFocusPercentCallbackHandler } from '@hs-src/hosanna-ui/views/lib/AppConfig';
11
11
  import { IViewFragmentProvider } from '@hs-src/hosanna-ui/views/lib/ViewFragmentProvider';
12
12
  import { applyDataMap } from '@hs-src/hosanna-ui/lib/FragmentUtils';
13
13
  import { applyFragmentConstraints } from '@hs-src/hosanna-ui/lib/FragmentConstraints';
@@ -56,6 +56,12 @@ export class CollectionViewSupplementaryView implements IReusable {
56
56
  private renderedX = 0;
57
57
  private renderedY = 0;
58
58
 
59
+ /** Override with true for a custom controller hook; fragment callbacks opt in automatically. */
60
+ supportsRowFocusPercent = false;
61
+ rowFocusPercent: number | undefined;
62
+ private customSupportsRowFocusPercent: boolean | undefined;
63
+ private rowFocusPercentCallbacks: ViewFragmentFocusPercentCallbackHandler[] | undefined;
64
+
59
65
  /**
60
66
  * Mounts this controller for a row and creates its fragment, when configured.
61
67
  * This is layout infrastructure; subclasses should use {@link onConfigure}.
@@ -84,6 +90,15 @@ export class CollectionViewSupplementaryView implements IReusable {
84
90
  }
85
91
 
86
92
  this.onConfigure();
93
+ if (this.customSupportsRowFocusPercent === undefined) {
94
+ this.customSupportsRowFocusPercent = this.supportsRowFocusPercent;
95
+ }
96
+ this.rowFocusPercentCallbacks = this.fragment?.callbacks?.onRowFocusPercentChanged;
97
+ this.supportsRowFocusPercent = this.customSupportsRowFocusPercent || (this.rowFocusPercentCallbacks?.length ?? 0) > 0;
98
+ this.rowFocusPercent = undefined;
99
+ if (this.fragment?.rowFocusPercent !== undefined) {
100
+ this.fragment.rowFocusPercent = undefined;
101
+ }
87
102
  this.measuredHeight = Math.max(0, this.measureHeight());
88
103
  this.displayable = this.shouldDisplay();
89
104
  }
@@ -143,6 +158,30 @@ export class CollectionViewSupplementaryView implements IReusable {
143
158
  this.applyContent();
144
159
  }
145
160
 
161
+ /** Receives row focus without triggering content binding, measurement, or presentation updates. */
162
+ setRowFocusPercent(value: number, force = false): void {
163
+ if (!this.supportsRowFocusPercent || (!force && this.rowFocusPercent === value)) {
164
+ return;
165
+ }
166
+ this.rowFocusPercent = value;
167
+ const fragment = this.fragment;
168
+ if (fragment !== undefined && this.rowFocusPercentCallbacks && this.rowFocusPercentCallbacks.length > 0) {
169
+ fragment.rowFocusPercent = value;
170
+ for (const callback of this.rowFocusPercentCallbacks) {
171
+ callback(fragment, value);
172
+ }
173
+ }
174
+ if (this.customSupportsRowFocusPercent) {
175
+ this.onRowFocusPercentChanged(value);
176
+ }
177
+ }
178
+
179
+ /** Custom controllers opt in with supportsRowFocusPercent and update retained presentation here. */
180
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
181
+ protected onRowFocusPercentChanged(_value: number): void {
182
+ // Optional subclass hook.
183
+ }
184
+
146
185
  /** Returns one optional audio-guide announcement for the whole supplementary. */
147
186
  getAudioGuideItem(): IAudioGuideItem | undefined {
148
187
  return undefined;
@@ -238,6 +277,9 @@ export class CollectionViewSupplementaryView implements IReusable {
238
277
 
239
278
  onWillRelease(): void {
240
279
  if (this.fragment) {
280
+ if (this.fragment.rowFocusPercent !== undefined) {
281
+ this.fragment.rowFocusPercent = undefined;
282
+ }
241
283
  this.fragment.view.visible = false;
242
284
  this.viewFragmentProvider.markFragmentForRemoval(this.fragment);
243
285
  this.viewFragmentProvider.releaseFragment(this.fragment);
@@ -250,6 +292,9 @@ export class CollectionViewSupplementaryView implements IReusable {
250
292
  this.presentationState = undefined;
251
293
  this.renderedX = 0;
252
294
  this.renderedY = 0;
295
+ this.rowFocusPercent = undefined;
296
+ this.rowFocusPercentCallbacks = undefined;
297
+ this.supportsRowFocusPercent = this.customSupportsRowFocusPercent ?? this.supportsRowFocusPercent;
253
298
  this.resetPresentationState();
254
299
  }
255
300
 
@@ -262,6 +307,9 @@ export class CollectionViewSupplementaryView implements IReusable {
262
307
  this.presentationState = undefined;
263
308
  this.renderedX = 0;
264
309
  this.renderedY = 0;
310
+ this.rowFocusPercent = undefined;
311
+ this.rowFocusPercentCallbacks = undefined;
312
+ this.supportsRowFocusPercent = this.customSupportsRowFocusPercent ?? this.supportsRowFocusPercent;
265
313
  this.resetPresentationState();
266
314
  }
267
315
 
@@ -1,7 +1,7 @@
1
1
  import { inject } from '@hs-src/hosanna-bridge-core/decorators';
2
2
  import { BaseCell } from './BaseCell';
3
3
  import { IViewFragmentProvider } from '@hs-src/hosanna-ui/views/lib/ViewFragmentProvider';
4
- import { IAppConfig, IViewFragment, IViewFragmentStyle, ViewFragmentCallbackHandler, ViewFragmentCallbackType } from '@hs-src/hosanna-ui/views/lib/AppConfig';
4
+ import { IAppConfig, IViewFragment, IViewFragmentStyle, ViewFragmentCallbackHandler, ViewFragmentCallbackType, ViewFragmentFocusPercentCallbackHandler } from '@hs-src/hosanna-ui/views/lib/AppConfig';
5
5
  import { applyDataMap } from '@hs-src/hosanna-ui/lib/FragmentUtils';
6
6
  import { scrollJankChildCount, scrollJankDuration, scrollJankLog, scrollJankNodeId, scrollJankNow } from '@hs-src/hosanna-ui/lib/ScrollJankLogger';
7
7
  import {
@@ -22,7 +22,7 @@ import { ViewStatus } from '@hs-src/hosanna-ui/hosanna-api';
22
22
  import { IIdentifiable } from '@hs-src/hosanna-bridge-core/brs-api';
23
23
  import { ISGNGroup } from '@hs-src/hosanna-bridge-targets/common/sg-api';
24
24
  import { JsonData } from '@hs-src/hosanna-ui/async/AsyncApi';
25
- import { IBaseCollectionViewRow, ILoadingItem } from './CollectionViewAPI';
25
+ import { IBaseCollectionViewRow, ICollectionViewFocusManager, ILoadingItem } from './CollectionViewAPI';
26
26
 
27
27
  /**
28
28
  * `DynamicCell` is an extension of `BaseCell` that dynamically manages its view fragment.
@@ -48,11 +48,31 @@ export class DynamicCell extends BaseCell {
48
48
 
49
49
  private constraintSession: FragmentConstraintSession | undefined;
50
50
 
51
+ /** Cached fragment capabilities; unsupported cells never receive progress work. */
52
+ supportsFocusPercent = false;
53
+ supportsRowFocusPercent = false;
54
+ focusPercent: number | undefined;
55
+ rowFocusPercent: number | undefined;
56
+ private focusPercentCallbacks: ViewFragmentFocusPercentCallbackHandler[] | undefined;
57
+ private rowFocusPercentCallbacks: ViewFragmentFocusPercentCallbackHandler[] | undefined;
58
+ private focusPercentManager: ICollectionViewFocusManager | undefined;
59
+
51
60
  /**
52
61
  * Handles content changes for the cell.
53
62
  * Updates the view fragment and applies the current view status.
54
63
  */
55
64
  protected changeRowHidden(item: IIdentifiable | undefined) {
65
+ // BaseCell has assigned the new row already; detach through the previous binding's owner.
66
+ if (this.focusPercentManager !== undefined) {
67
+ this.detachFocusPercent();
68
+ } else if (this._focusPercentRegistration?.owner !== undefined) {
69
+ this.detachFocusPercent();
70
+ }
71
+ if (this.supportsFocusPercent) {
72
+ this.clearFocusPercentValues();
73
+ } else if (this.supportsRowFocusPercent) {
74
+ this.clearFocusPercentValues();
75
+ }
56
76
  let scrollJankStartMs = 0;
57
77
  if (__SCROLL_JANK_TELEMETRY__) {
58
78
  scrollJankStartMs = scrollJankNow();
@@ -89,6 +109,7 @@ export class DynamicCell extends BaseCell {
89
109
  }
90
110
 
91
111
  this.viewFragment = this.viewFragmentProvider.getViewFragmentByStyleKey(styleKey);
112
+ this.cacheFocusPercentCallbacks();
92
113
  if (__SCROLL_JANK_TELEMETRY__) {
93
114
  scrollJankLog('fragment-acquire-for-cell', `rowIndex=${row.index} rowId=${row.id} cellIndex=${this.index} itemId=${item?.id ?? ''} styleKey=${styleKey} fragmentId=${this.viewFragment?.id ?? ''} viewId=${scrollJankNodeId(this.viewFragment?.view)} parentId=${scrollJankNodeId(this.viewFragment?.view?.getParent?.())}`);
94
115
  }
@@ -352,6 +373,13 @@ export class DynamicCell extends BaseCell {
352
373
  * @param visible - Whether the cell should be visible.
353
374
  */
354
375
  override setVisible(visible: boolean) {
376
+ if (!visible) {
377
+ if (this.focusPercentManager !== undefined) {
378
+ this.detachFocusPercent();
379
+ } else if (this._focusPercentRegistration?.owner !== undefined) {
380
+ this.detachFocusPercent();
381
+ }
382
+ }
355
383
  if (this.viewFragment) {
356
384
  this.viewFragment.view.visible = visible;
357
385
  }
@@ -364,6 +392,97 @@ export class DynamicCell extends BaseCell {
364
392
  }
365
393
  }
366
394
 
395
+ /** Applies only requested progress fields, without replaying content, status, or layout. */
396
+ setFocusPercents(focusPercent: number, rowFocusPercent: number, force = false): void {
397
+ const fragment = this.viewFragment;
398
+ if (fragment === undefined) {
399
+ return;
400
+ }
401
+ const focusChanged = this.supportsFocusPercent && (force || this.focusPercent !== focusPercent);
402
+ const rowFocusChanged = this.supportsRowFocusPercent && (force || this.rowFocusPercent !== rowFocusPercent);
403
+ if (!focusChanged && !rowFocusChanged) {
404
+ return;
405
+ }
406
+ if (this.focusPercentManager === undefined) {
407
+ this.focusPercentManager = this.row?.parent?.getFocusManager?.();
408
+ }
409
+ // Publish both values before either callback so combined effects see one sample.
410
+ if (focusChanged) {
411
+ this.focusPercent = focusPercent;
412
+ fragment.focusPercent = focusPercent;
413
+ }
414
+ if (rowFocusChanged) {
415
+ this.rowFocusPercent = rowFocusPercent;
416
+ fragment.rowFocusPercent = rowFocusPercent;
417
+ }
418
+ if (focusChanged && this.focusPercentCallbacks) {
419
+ for (const callback of this.focusPercentCallbacks) {
420
+ callback(fragment, focusPercent);
421
+ }
422
+ }
423
+ if (rowFocusChanged && this.rowFocusPercentCallbacks) {
424
+ for (const callback of this.rowFocusPercentCallbacks) {
425
+ callback(fragment, rowFocusPercent);
426
+ }
427
+ }
428
+ }
429
+
430
+ private cacheFocusPercentCallbacks(): void {
431
+ this.focusPercentCallbacks = this.viewFragment?.callbacks?.onFocusPercentChanged;
432
+ this.rowFocusPercentCallbacks = this.viewFragment?.callbacks?.onRowFocusPercentChanged;
433
+ this.supportsFocusPercent = false;
434
+ if (this.focusPercentCallbacks !== undefined) {
435
+ this.supportsFocusPercent = this.focusPercentCallbacks.length > 0;
436
+ }
437
+ this.supportsRowFocusPercent = false;
438
+ if (this.rowFocusPercentCallbacks !== undefined) {
439
+ this.supportsRowFocusPercent = this.rowFocusPercentCallbacks.length > 0;
440
+ }
441
+ if (this.supportsFocusPercent) {
442
+ this.clearFocusPercentValues();
443
+ } else if (this.supportsRowFocusPercent) {
444
+ this.clearFocusPercentValues();
445
+ }
446
+ }
447
+
448
+ private detachFocusPercent(): void {
449
+ const registration = this._focusPercentRegistration;
450
+ const manager = registration !== undefined ? registration.owner : this.focusPercentManager;
451
+ this.focusPercentManager = undefined;
452
+ if (manager) {
453
+ manager.unregisterFocusPercentCell?.(this);
454
+ }
455
+ }
456
+
457
+ private clearFocusPercentValues(): void {
458
+ if (this.supportsFocusPercent) {
459
+ this.focusPercent = undefined;
460
+ if (this.viewFragment !== undefined) {
461
+ this.viewFragment.focusPercent = undefined;
462
+ }
463
+ }
464
+ if (this.supportsRowFocusPercent) {
465
+ this.rowFocusPercent = undefined;
466
+ if (this.viewFragment !== undefined) {
467
+ this.viewFragment.rowFocusPercent = undefined;
468
+ }
469
+ }
470
+ }
471
+
472
+ override onWillRelease(): void {
473
+ if (this.focusPercentManager !== undefined) {
474
+ this.detachFocusPercent();
475
+ } else if (this._focusPercentRegistration?.owner !== undefined) {
476
+ this.detachFocusPercent();
477
+ }
478
+ super.onWillRelease();
479
+ if (this.supportsFocusPercent) {
480
+ this.clearFocusPercentValues();
481
+ } else if (this.supportsRowFocusPercent) {
482
+ this.clearFocusPercentValues();
483
+ }
484
+ }
485
+
367
486
  protected override isSameContainer(row: IBaseCollectionViewRow): boolean {
368
487
  if (!this.viewFragment) {
369
488
  return true;
@@ -372,6 +491,16 @@ export class DynamicCell extends BaseCell {
372
491
  }
373
492
 
374
493
  override reset(): void {
494
+ if (this.focusPercentManager !== undefined) {
495
+ this.detachFocusPercent();
496
+ } else if (this._focusPercentRegistration?.owner !== undefined) {
497
+ this.detachFocusPercent();
498
+ }
499
+ if (this.supportsFocusPercent) {
500
+ this.clearFocusPercentValues();
501
+ } else if (this.supportsRowFocusPercent) {
502
+ this.clearFocusPercentValues();
503
+ }
375
504
  let rowIndex = -1;
376
505
  let rowId = '';
377
506
  let cellIndex = -1;
@@ -423,6 +552,7 @@ export class DynamicCell extends BaseCell {
423
552
  this.viewFragmentProvider.releaseFragment(this.viewFragment);
424
553
  this.viewFragment = undefined;
425
554
  this.currentStyle = '';
555
+ this.cacheFocusPercentCallbacks();
426
556
  }
427
557
  if (__SCROLL_JANK_TELEMETRY__) {
428
558
  scrollJankLog('dynamic-cell-recycle-end', `rowIndex=${rowIndex} rowId=${rowId} cellIndex=${cellIndex} itemId=${itemId} hasFragment=${this.viewFragment !== undefined}`);
@@ -326,6 +326,7 @@ export class EPGProgramLayout extends BaseCollectionViewLayout {
326
326
  for (const key in cellsToRemoveById) {
327
327
  const cell = cellsToRemoveById[key];
328
328
  delete this.cellsByIndex[key];
329
+ cell._focusPercentRegistration?.owner?.unregisterFocusPercentCell?.(cell);
329
330
  cell.setVisible(false);
330
331
  this.instancePool.release(cell);
331
332
  }
@@ -195,6 +195,7 @@ export class GridRowLayout extends BaseCollectionViewLayout {
195
195
 
196
196
  if (cellsToRemove.length > 0) {
197
197
  for (const cell of cellsToRemove) {
198
+ cell._focusPercentRegistration?.owner?.unregisterFocusPercentCell?.(cell);
198
199
  cell.setVisible(false);
199
200
  this.instancePool.release(cell);
200
201
  }
@@ -249,6 +249,7 @@ export class HorizontalRowLayout extends BaseCollectionViewLayout {
249
249
  if (__SCROLL_JANK_TELEMETRY__) {
250
250
  scrollJankLog('cell-flag-remove', `layout=horizontal rowIndex=${row.index} rowId=${row.id} cellIndex=${cell.index} itemId=${cell.item?.id ?? ''} reason=not-visible`);
251
251
  }
252
+ cell._focusPercentRegistration?.owner?.unregisterFocusPercentCell?.(cell);
252
253
  cell.setVisible(false);
253
254
  this.instancePool.release(cell);
254
255
  if (__SCROLL_JANK_TELEMETRY__) {
@@ -169,6 +169,7 @@ export class ListRowLayout extends BaseCollectionViewLayout {
169
169
 
170
170
  if (cellsToRemove.length > 0) {
171
171
  for (const cell of cellsToRemove) {
172
+ cell._focusPercentRegistration?.owner?.unregisterFocusPercentCell?.(cell);
172
173
  cell.setVisible(false);
173
174
  this.instancePool.release(cell);
174
175
  }
@@ -18,8 +18,6 @@ import {
18
18
  * @returns The value at the specified path, or the default value if not found.
19
19
  */
20
20
  export function getPath<T>(content: unknown, path: string, defaultValue: unknown = undefined, disableIndexing: boolean = false): T {
21
- //FIXME - on roku, this function does not work!
22
- // hs_native_roku(`return hs_getPath(content, path, defaultValue, disableIndexing)`)
23
21
  if (!path) {
24
22
  return defaultValue as T;
25
23
  }
@@ -38,18 +36,36 @@ export function getPath<T>(content: unknown, path: string, defaultValue: unknown
38
36
  // eslint-disable-next-line @hosanna-eslint/no-unsafe-number-parsing
39
37
  part = Array.isArray(part) ? part[Number(key)] : undefined;
40
38
  } else {
41
- // Check if current part has the key directly
42
39
  const partRecord = part as Record<string, unknown>;
43
- const partKeys = Object.keys(partRecord);
44
- if (partKeys.includes(key)) {
45
- part = partRecord[key];
46
- } else {
47
- // Try concatenated key for remaining parts if direct access fails
40
+ if (__ROKU__) {
41
+ if (typeof part !== 'object' || Array.isArray(part)) {
42
+ return defaultValue as T;
43
+ }
44
+ // AA lookup is case-insensitive; dot assignment can change enumerated key casing.
45
+ // hasOwnProperty lowers to doesExist on Roku, including shadowed data keys.
46
+ if (partRecord.hasOwnProperty(key)) {
47
+ part = partRecord[key];
48
+ continue;
49
+ }
48
50
  const concatenatedKey = parts.slice(i).join('.');
49
- if (partKeys.includes(concatenatedKey)) {
51
+ if (partRecord.hasOwnProperty(concatenatedKey)) {
50
52
  return partRecord[concatenatedKey] as T;
51
53
  }
52
- return defaultValue as T; // Key does not exist at this level
54
+ return defaultValue as T;
55
+ }
56
+ if (!__ROKU__) {
57
+ // Preserve enumerable-own lookup for browser records, including shadowed helpers.
58
+ const partKeys = Object.keys(partRecord);
59
+ if (partKeys.includes(key)) {
60
+ part = partRecord[key];
61
+ } else {
62
+ // Try concatenated key for remaining parts if direct access fails
63
+ const concatenatedKey = parts.slice(i).join('.');
64
+ if (partKeys.includes(concatenatedKey)) {
65
+ return partRecord[concatenatedKey] as T;
66
+ }
67
+ return defaultValue as T; // Key does not exist at this level
68
+ }
53
69
  }
54
70
  }
55
71
  }