@tantawowa/hosanna-ui 2.0.4 → 2.2.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.
- package/dist-manifest.json +33 -29
- package/package.json +1 -1
- package/src/hosanna-bridge-core/color.ts +140 -0
- package/src/hosanna-bridge-targets/web/brs/WebRoBitmap.ts +14 -0
- package/src/hosanna-bridge-targets/web/sg/WebSGPoster.ts +1 -1
- package/src/hosanna-game/color.ts +3 -115
- package/src/hosanna-list/BaseCell.ts +4 -0
- package/src/hosanna-list/BaseCollectionViewLayout.ts +59 -6
- package/src/hosanna-list/CollectionView.ts +14 -5
- package/src/hosanna-list/CollectionViewAPI.ts +41 -5
- package/src/hosanna-list/CollectionViewFocusManager.ts +415 -6
- package/src/hosanna-list/CollectionViewSupplementaryView.ts +49 -1
- package/src/hosanna-list/DynamicCell.ts +132 -2
- package/src/hosanna-list/EPGProgramLayout.ts +1 -0
- package/src/hosanna-list/GridRowLayout.ts +1 -0
- package/src/hosanna-list/HorizontalRowLayout.ts +1 -0
- package/src/hosanna-list/ListRowLayout.ts +1 -0
- package/src/hosanna-ui/app-roku/HosannaApp.xml +2 -1
- package/src/hosanna-ui/async/ImageGeneratorCommands.ts +0 -20
- package/src/hosanna-ui/lib/BaseApp.ts +11 -6
- package/src/hosanna-ui/lib/ConfigurationLoader.ts +11 -3
- package/src/hosanna-ui/lib/FragmentUtils.ts +26 -10
- package/src/hosanna-ui/lib/animation.ts +358 -235
- package/src/hosanna-ui/lib/shapes/ShapeLoader.ts +22 -27
- package/src/hosanna-ui/views/controls/Button.ts +16 -1
- package/src/hosanna-ui/views/lib/AppConfig.ts +26 -0
- package/src/hosanna-ui/views/lib/BaseView.ts +98 -21
- package/src/hosanna-ui/views/lib/ViewFragmentProvider.ts +39 -5
- package/src/hosanna-ui/views/primitives/Image.ts +1 -1
- package/src/hosanna-ui/views/primitives/Label.ts +3 -3
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
CollectionViewFocusIndicatorTransitionType,
|
|
9
9
|
ICollectionView,
|
|
10
10
|
ICollectionViewFocusManager,
|
|
11
|
+
ICollectionViewCell,
|
|
12
|
+
ICollectionViewFocusPercentRegistration,
|
|
13
|
+
ICollectionViewRowFocusPercentHeader,
|
|
11
14
|
IFocusInfo,
|
|
12
15
|
createFocusInfo,
|
|
13
16
|
} from './CollectionViewAPI';
|
|
@@ -15,6 +18,7 @@ import { BaseCollectionViewLayout } from './BaseCollectionViewLayout';
|
|
|
15
18
|
import { BaseCollectionViewRow } from './BaseCollectionViewRow';
|
|
16
19
|
import type { BaseView } from '@hs-src/hosanna-ui/views/lib/BaseView';
|
|
17
20
|
import type { IHosannaView, ViewState } from '@hs-src/hosanna-ui/views/lib/view-api';
|
|
21
|
+
import { getUniqueViewId } from '@hs-src/hosanna-ui/views/lib/view-api';
|
|
18
22
|
import {
|
|
19
23
|
ContinuousFocusTransitionStrategy,
|
|
20
24
|
ICollectionViewFocusTransitionHost,
|
|
@@ -23,6 +27,22 @@ import {
|
|
|
23
27
|
StartEndFocusTransitionStrategy,
|
|
24
28
|
} from './focusTransitions/CollectionViewFocusTransitionStrategy';
|
|
25
29
|
|
|
30
|
+
interface FocusPercentEndpoint {
|
|
31
|
+
rowKey: string;
|
|
32
|
+
itemIndex: number;
|
|
33
|
+
itemStart: number;
|
|
34
|
+
rowStart: number;
|
|
35
|
+
hasRecipients: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface FocusPercentRowRecipients {
|
|
39
|
+
cells: Record<string, ICollectionViewFocusPercentRegistration>;
|
|
40
|
+
rowCells: ICollectionViewFocusPercentRegistration[];
|
|
41
|
+
cellCount: number;
|
|
42
|
+
header?: ICollectionViewRowFocusPercentHeader;
|
|
43
|
+
lastRowPercent: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
26
46
|
/**
|
|
27
47
|
* `CollectionViewFocusManager` manages the focus rectangle and animations for a collection view.
|
|
28
48
|
* It handles focus transitions, rendering, and applying focus to rows and items.
|
|
@@ -50,9 +70,22 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
50
70
|
private isAnimatingFocus = false;
|
|
51
71
|
|
|
52
72
|
/**
|
|
53
|
-
* The
|
|
73
|
+
* The shared movement clock for the indicator and opt-in percentage recipients.
|
|
74
|
+
* A settled or reset manager has no transition in flight.
|
|
54
75
|
*/
|
|
55
|
-
private focusPercent: number =
|
|
76
|
+
private focusPercent: number = 1;
|
|
77
|
+
|
|
78
|
+
// Keep endpoint history even without recipients for late acquisition and reversals.
|
|
79
|
+
private percentSource: FocusPercentEndpoint | undefined;
|
|
80
|
+
private percentTarget: FocusPercentEndpoint | undefined;
|
|
81
|
+
private percentInFocusChain = false;
|
|
82
|
+
private percentSupplementaryRowKey = '';
|
|
83
|
+
private percentOwnerId = '';
|
|
84
|
+
private percentRows: Record<string, FocusPercentRowRecipients> = {};
|
|
85
|
+
private percentHeaderRows: Record<string, string> = {};
|
|
86
|
+
private percentRecipientCount = 0;
|
|
87
|
+
private percentHasActiveRecipients = false;
|
|
88
|
+
private percentSupplementaryHasRecipients = false;
|
|
56
89
|
|
|
57
90
|
/** Internal transition strategies share this manager's one pooled focus-indicator poster. */
|
|
58
91
|
private continuousTransitionStrategy: ContinuousFocusTransitionStrategy;
|
|
@@ -266,6 +299,7 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
266
299
|
return;
|
|
267
300
|
}
|
|
268
301
|
this.nextFocusInfo = info;
|
|
302
|
+
this.acceptFocusPercentTarget(info);
|
|
269
303
|
this.selectTransitionStrategy(info);
|
|
270
304
|
this.activeTransitionStrategy.onTargetAccepted();
|
|
271
305
|
}
|
|
@@ -275,7 +309,7 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
275
309
|
* @param info - The focus information to set and render.
|
|
276
310
|
* @returns
|
|
277
311
|
*/
|
|
278
|
-
setAndRenderFocusInfo(info: IFocusInfo | undefined): void {
|
|
312
|
+
setAndRenderFocusInfo(info: IFocusInfo | undefined, preserveFocusPercentTransition = false): void {
|
|
279
313
|
if (info === undefined) {
|
|
280
314
|
info = this.nullFocusInfo;
|
|
281
315
|
}
|
|
@@ -286,6 +320,11 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
286
320
|
}
|
|
287
321
|
this.focusInfo = info;
|
|
288
322
|
this.nextFocusInfo = info;
|
|
323
|
+
if (!preserveFocusPercentTransition || this.percentTarget === undefined || this.focusPercent >= 1) {
|
|
324
|
+
this.acceptFocusPercentTarget(info);
|
|
325
|
+
this.focusPercent = 1;
|
|
326
|
+
if (this.percentHasActiveRecipients) this.publishFocusPercents();
|
|
327
|
+
}
|
|
289
328
|
this.selectTransitionStrategy(info);
|
|
290
329
|
this.activeTransitionStrategy.onFocusRendered();
|
|
291
330
|
this.renderTransitionAppearance(1);
|
|
@@ -300,8 +339,9 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
300
339
|
*/
|
|
301
340
|
renderWhileMovingBetweenItems(percent: number): void {
|
|
302
341
|
this.focusPercent = percent;
|
|
303
|
-
this.
|
|
304
|
-
|
|
342
|
+
if (this.percentHasActiveRecipients) this.publishFocusPercents();
|
|
343
|
+
this.activeTransitionStrategy.onProgress(percent);
|
|
344
|
+
if (percent >= 1.0) {
|
|
305
345
|
this.setFocusComplete();
|
|
306
346
|
}
|
|
307
347
|
}
|
|
@@ -413,6 +453,8 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
413
453
|
* Marks the focus transition as complete and applies the focus to the row.
|
|
414
454
|
*/
|
|
415
455
|
setFocusComplete(): void {
|
|
456
|
+
this.focusPercent = 1;
|
|
457
|
+
if (this.percentHasActiveRecipients) this.publishFocusPercents();
|
|
416
458
|
console.debug('CollectionViewFocusManager: Focus transition complete');
|
|
417
459
|
|
|
418
460
|
if (this.focusInfo) {
|
|
@@ -446,6 +488,9 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
446
488
|
if (this.textToSpeechManager.getEnabled()) {
|
|
447
489
|
console.debug('CollectionViewFocusManager: Speaking focus information');
|
|
448
490
|
const focusedRow = this.collectionView.getFocusedRow();
|
|
491
|
+
if (!focusedRow) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
449
494
|
const item = this.collectionView.getFocusedDataSourceItem();
|
|
450
495
|
const currentRowIndex = this.focusInfo.rowIndex;
|
|
451
496
|
const currentItemIndex = this.focusInfo.itemIndex;
|
|
@@ -527,6 +572,22 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
527
572
|
* Called when the collection view is cleared (e.g. DataSourceChangeType.Clear).
|
|
528
573
|
*/
|
|
529
574
|
reset(): void {
|
|
575
|
+
// Invalidate active bindings without delivering into released presentation objects.
|
|
576
|
+
for (const rowKey in this.percentRows) {
|
|
577
|
+
const row = this.percentRows[rowKey];
|
|
578
|
+
for (const itemKey in row.cells) {
|
|
579
|
+
row.cells[itemKey].owner = undefined;
|
|
580
|
+
row.cells[itemKey].cell = undefined;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
this.percentRows = {};
|
|
584
|
+
this.percentHeaderRows = {};
|
|
585
|
+
this.percentRecipientCount = 0;
|
|
586
|
+
this.percentHasActiveRecipients = false;
|
|
587
|
+
this.percentSupplementaryHasRecipients = false;
|
|
588
|
+
this.percentSource = undefined;
|
|
589
|
+
this.percentTarget = undefined;
|
|
590
|
+
this.percentSupplementaryRowKey = '';
|
|
530
591
|
this.focusInfo = this.nullFocusInfo;
|
|
531
592
|
this.nextFocusInfo = this.nullFocusInfo;
|
|
532
593
|
this.isAnimatingFocus = false;
|
|
@@ -534,13 +595,361 @@ export class CollectionViewFocusManager implements ICollectionViewFocusManager,
|
|
|
534
595
|
this.instantTransitionStrategy.reset();
|
|
535
596
|
this.startEndTransitionStrategy.reset();
|
|
536
597
|
this.activeTransitionStrategy = this.continuousTransitionStrategy;
|
|
537
|
-
this.focusPercent =
|
|
598
|
+
this.focusPercent = 1;
|
|
538
599
|
this.lastSpokenRowIndex = -1;
|
|
539
600
|
this.lastSpokenItemIndex = -1;
|
|
540
601
|
this.isFocusShown = false;
|
|
541
602
|
this.updateFocusIndicatorPosterVisibility();
|
|
542
603
|
}
|
|
543
604
|
|
|
605
|
+
/** Registers only realized, opted-in cells. Called after content/style binding. */
|
|
606
|
+
registerFocusPercentCell(cell: ICollectionViewCell, force = false): void {
|
|
607
|
+
if ((!cell.supportsFocusPercent && !cell.supportsRowFocusPercent) || !cell.setFocusPercents) {
|
|
608
|
+
cell._focusPercentRegistration?.owner?.unregisterFocusPercentCell?.(cell);
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
if (this.percentOwnerId === '') this.percentOwnerId = `${getUniqueViewId()}`;
|
|
612
|
+
// Layout already bound this row; do not resolve it again through the collection.
|
|
613
|
+
const cellRow = cell.row;
|
|
614
|
+
const rowKey = cellRow.content?.id || cellRow.id || cellRow.index.toString();
|
|
615
|
+
let registration = cell._focusPercentRegistration;
|
|
616
|
+
if (registration?.owner !== undefined) {
|
|
617
|
+
if (registration.ownerId !== this.percentOwnerId || registration.rowKey !== rowKey || registration.itemIndex !== cell.index
|
|
618
|
+
|| registration.supportsFocusPercent !== (cell.supportsFocusPercent === true)
|
|
619
|
+
|| registration.supportsRowFocusPercent !== (cell.supportsRowFocusPercent === true)) {
|
|
620
|
+
registration.owner.unregisterFocusPercentCell?.(cell);
|
|
621
|
+
} else if (!force
|
|
622
|
+
&& !registration.needsInitialization
|
|
623
|
+
&& (!cell.supportsFocusPercent || cell.focusPercent !== undefined)
|
|
624
|
+
&& (!cell.supportsRowFocusPercent || cell.rowFocusPercent !== undefined)) {
|
|
625
|
+
// Retained bindings receive movement/focus updates through dispatch. Hide,
|
|
626
|
+
// rebind and reset detach them; forced or uninitialized bindings continue below.
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (registration === undefined) {
|
|
631
|
+
registration = {
|
|
632
|
+
cell, rowKey, itemIndex: cell.index, rowCellIndex: -1, ownerId: '',
|
|
633
|
+
supportsFocusPercent: cell.supportsFocusPercent === true,
|
|
634
|
+
supportsRowFocusPercent: cell.supportsRowFocusPercent === true,
|
|
635
|
+
needsInitialization: true,
|
|
636
|
+
};
|
|
637
|
+
cell._focusPercentRegistration = registration;
|
|
638
|
+
}
|
|
639
|
+
if (registration.owner === undefined) {
|
|
640
|
+
registration.owner = this;
|
|
641
|
+
registration.cell = cell;
|
|
642
|
+
registration.ownerId = this.percentOwnerId;
|
|
643
|
+
registration.rowKey = rowKey;
|
|
644
|
+
registration.itemIndex = cell.index;
|
|
645
|
+
registration.rowCellIndex = -1;
|
|
646
|
+
registration.supportsFocusPercent = cell.supportsFocusPercent === true;
|
|
647
|
+
registration.supportsRowFocusPercent = cell.supportsRowFocusPercent === true;
|
|
648
|
+
const row = this.getFocusPercentRowRecipients(rowKey);
|
|
649
|
+
row.cells[cell.index.toString()] = registration;
|
|
650
|
+
row.cellCount++;
|
|
651
|
+
if (cell.supportsRowFocusPercent) {
|
|
652
|
+
registration.rowCellIndex = row.rowCells.length;
|
|
653
|
+
row.rowCells.push(registration);
|
|
654
|
+
// Inactive rows stop sampling. A newly initialized recipient must not
|
|
655
|
+
// inherit the row's old delivery cache, especially across a subsequent blur.
|
|
656
|
+
row.lastRowPercent = -1;
|
|
657
|
+
}
|
|
658
|
+
this.percentRecipientCount++;
|
|
659
|
+
this.refreshFocusPercentRecipients(rowKey);
|
|
660
|
+
force = true;
|
|
661
|
+
}
|
|
662
|
+
force = force || registration.needsInitialization;
|
|
663
|
+
registration.needsInitialization = false;
|
|
664
|
+
this.percentInFocusChain = this.collectionView.isInFocusChain();
|
|
665
|
+
this.publishFocusPercentCell(registration, force);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
unregisterFocusPercentCell(cell: ICollectionViewCell): void {
|
|
669
|
+
const registration = cell._focusPercentRegistration;
|
|
670
|
+
if (registration?.owner === undefined || registration.ownerId !== this.percentOwnerId) return;
|
|
671
|
+
const row = this.percentRows[registration.rowKey];
|
|
672
|
+
if (row !== undefined) {
|
|
673
|
+
delete row.cells[registration.itemIndex.toString()];
|
|
674
|
+
const index = registration.rowCellIndex;
|
|
675
|
+
if (index >= 0) {
|
|
676
|
+
// Cross-cell callback order is unspecified. Keep removal constant-time,
|
|
677
|
+
// and skip the row array entirely for item-only recipients.
|
|
678
|
+
const last = row.rowCells.pop();
|
|
679
|
+
if (last !== undefined && index < row.rowCells.length) {
|
|
680
|
+
row.rowCells[index] = last;
|
|
681
|
+
last.rowCellIndex = index;
|
|
682
|
+
}
|
|
683
|
+
registration.rowCellIndex = -1;
|
|
684
|
+
}
|
|
685
|
+
row.cellCount--;
|
|
686
|
+
if (row.cellCount === 0 && !row.header) delete this.percentRows[registration.rowKey];
|
|
687
|
+
}
|
|
688
|
+
registration.owner = undefined;
|
|
689
|
+
// Break the cell -> storage -> cell cycle while the storage stays reusable.
|
|
690
|
+
registration.cell = undefined;
|
|
691
|
+
this.percentRecipientCount--;
|
|
692
|
+
this.refreshFocusPercentRecipients(registration.rowKey);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
registerRowFocusPercentHeader(rowIndex: number, header: ICollectionViewRowFocusPercentHeader, force = false): void {
|
|
696
|
+
if (!header.supportsRowFocusPercent) return;
|
|
697
|
+
if (!header._hid) header._hid = `${getUniqueViewId()}`;
|
|
698
|
+
const rowKey = this.getFocusPercentRowKey(rowIndex);
|
|
699
|
+
const previousRowKey = this.percentHeaderRows[header._hid];
|
|
700
|
+
if (previousRowKey !== undefined && previousRowKey !== rowKey) {
|
|
701
|
+
this.unregisterRowFocusPercentHeader(header);
|
|
702
|
+
}
|
|
703
|
+
const row = this.getFocusPercentRowRecipients(rowKey);
|
|
704
|
+
if (row.header?._hid !== header._hid) {
|
|
705
|
+
if (!row.header) this.percentRecipientCount++;
|
|
706
|
+
if (row.header?._hid) delete this.percentHeaderRows[row.header._hid];
|
|
707
|
+
row.header = header;
|
|
708
|
+
this.percentHeaderRows[header._hid] = rowKey;
|
|
709
|
+
row.lastRowPercent = -1;
|
|
710
|
+
this.refreshFocusPercentRecipients(rowKey);
|
|
711
|
+
force = true;
|
|
712
|
+
}
|
|
713
|
+
this.percentInFocusChain = this.collectionView.isInFocusChain();
|
|
714
|
+
header.setRowFocusPercent(this.getPublishedRowFocusPercent(rowKey), force);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
unregisterRowFocusPercentHeader(header: ICollectionViewRowFocusPercentHeader): void {
|
|
718
|
+
const id = header._hid;
|
|
719
|
+
if (!id) return;
|
|
720
|
+
const rowKey = this.percentHeaderRows[id];
|
|
721
|
+
if (rowKey === undefined) return;
|
|
722
|
+
delete this.percentHeaderRows[id];
|
|
723
|
+
// Visibility changes detach headers during rendering. Use the saved row,
|
|
724
|
+
// not the header's mutable row binding or a scan of unrelated recipients.
|
|
725
|
+
const row = this.percentRows[rowKey];
|
|
726
|
+
if (row?.header?._hid !== id) return;
|
|
727
|
+
row.header = undefined;
|
|
728
|
+
this.percentRecipientCount--;
|
|
729
|
+
if (row.cellCount === 0) delete this.percentRows[rowKey];
|
|
730
|
+
this.refreshFocusPercentRecipients(rowKey);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
syncFocusPercentFocusChain(): void {
|
|
734
|
+
if (!this.percentHasActiveRecipients) return;
|
|
735
|
+
if (this.percentInFocusChain === this.collectionView.isInFocusChain()) return;
|
|
736
|
+
this.publishFocusPercents();
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
setFocusPercentSupplementary(rowIndex = -1): void {
|
|
740
|
+
const rowKey = rowIndex < 0 ? '' : this.getFocusPercentRowKey(rowIndex);
|
|
741
|
+
if (this.percentSupplementaryRowKey === rowKey) return;
|
|
742
|
+
const previousRowKey = this.percentSupplementaryRowKey;
|
|
743
|
+
this.percentSupplementaryRowKey = rowKey;
|
|
744
|
+
if (this.percentRecipientCount === 0) return;
|
|
745
|
+
this.refreshFocusPercentRecipients();
|
|
746
|
+
this.publishFocusPercents();
|
|
747
|
+
if (previousRowKey !== '') this.publishFocusPercentRow(previousRowKey);
|
|
748
|
+
if (rowKey !== '') this.publishFocusPercentRow(rowKey);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
private getFocusPercentRowKey(rowIndex: number): string {
|
|
752
|
+
const row = this.collectionView.getRowForIndex(rowIndex);
|
|
753
|
+
const contentId = row?.content?.id;
|
|
754
|
+
if (contentId) return contentId;
|
|
755
|
+
const rowId = row?.id;
|
|
756
|
+
if (rowId) return rowId;
|
|
757
|
+
return rowIndex.toString();
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
private getFocusPercentRowRecipients(rowKey: string): FocusPercentRowRecipients {
|
|
761
|
+
let row = this.percentRows[rowKey];
|
|
762
|
+
if (row === undefined) {
|
|
763
|
+
row = { cells: {}, rowCells: [], cellCount: 0, lastRowPercent: -1 };
|
|
764
|
+
this.percentRows[rowKey] = row;
|
|
765
|
+
}
|
|
766
|
+
return row;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/** Membership changes at target/registration boundaries, never on movement ticks. */
|
|
770
|
+
private refreshFocusPercentRecipients(changedRowKey?: string): void {
|
|
771
|
+
const source = this.percentSource;
|
|
772
|
+
const target = this.percentTarget;
|
|
773
|
+
if (source !== undefined && (changedRowKey === undefined || source.rowKey === changedRowKey)) {
|
|
774
|
+
source.hasRecipients = this.hasFocusPercentRecipients(source);
|
|
775
|
+
}
|
|
776
|
+
if (target !== undefined && (changedRowKey === undefined || target.rowKey === changedRowKey)) {
|
|
777
|
+
target.hasRecipients = this.hasFocusPercentRecipients(target);
|
|
778
|
+
}
|
|
779
|
+
if (changedRowKey === undefined || this.percentSupplementaryRowKey === changedRowKey) {
|
|
780
|
+
const supplementary = this.percentRows[this.percentSupplementaryRowKey];
|
|
781
|
+
this.percentSupplementaryHasRecipients = supplementary !== undefined
|
|
782
|
+
&& (supplementary.rowCells.length > 0 || supplementary.header !== undefined);
|
|
783
|
+
}
|
|
784
|
+
this.percentHasActiveRecipients = source?.hasRecipients === true
|
|
785
|
+
|| target?.hasRecipients === true
|
|
786
|
+
|| this.percentSupplementaryHasRecipients;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
private hasFocusPercentRecipients(endpoint: FocusPercentEndpoint): boolean {
|
|
790
|
+
if (this.percentRecipientCount === 0) return false;
|
|
791
|
+
const row = this.percentRows[endpoint.rowKey];
|
|
792
|
+
if (row === undefined) return false;
|
|
793
|
+
if (row.rowCells.length > 0 || row.header !== undefined) return true;
|
|
794
|
+
return row.cells[endpoint.itemIndex.toString()]?.cell?.supportsFocusPercent === true;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
private acceptFocusPercentTarget(info: IFocusInfo): void {
|
|
798
|
+
const rowKey = this.getFocusPercentRowKey(info.rowIndex);
|
|
799
|
+
const previousTarget = this.percentTarget;
|
|
800
|
+
if (previousTarget !== undefined) {
|
|
801
|
+
if (previousTarget.rowKey === rowKey) {
|
|
802
|
+
if (previousTarget.itemIndex === info.itemIndex) return;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
const previousSource = this.percentSource;
|
|
806
|
+
// Save the retiring identity before reusing the records. A third destination
|
|
807
|
+
// must still clear its old source even when the new pair has no listeners.
|
|
808
|
+
const retiredRowKey = previousSource?.rowKey;
|
|
809
|
+
const retiredItemIndex = previousSource?.itemIndex ?? -1;
|
|
810
|
+
const retireSource = previousSource?.hasRecipients === true;
|
|
811
|
+
// A completed transition has only one focused endpoint. Only interruptions need
|
|
812
|
+
// interpolation; normal focus changes can use the known settled values directly.
|
|
813
|
+
const isSettled = this.focusPercent >= 1;
|
|
814
|
+
const targetItemStart = isSettled ? 0 : this.getLogicalItemFocusPercent(rowKey, info.itemIndex);
|
|
815
|
+
let targetRowStart = 0;
|
|
816
|
+
if (isSettled) {
|
|
817
|
+
if (previousTarget !== undefined) {
|
|
818
|
+
if (previousTarget.rowKey === rowKey) targetRowStart = 1;
|
|
819
|
+
}
|
|
820
|
+
} else {
|
|
821
|
+
targetRowStart = this.getLogicalRowFocusPercent(rowKey);
|
|
822
|
+
}
|
|
823
|
+
let source: FocusPercentEndpoint | undefined;
|
|
824
|
+
if (previousTarget !== undefined) {
|
|
825
|
+
const itemStart = isSettled ? 1 : this.getLogicalItemFocusPercent(previousTarget.rowKey, previousTarget.itemIndex);
|
|
826
|
+
const rowStart = isSettled ? 1 : this.getLogicalRowFocusPercent(previousTarget.rowKey);
|
|
827
|
+
// Sample both endpoints before mutating either retained record.
|
|
828
|
+
if (previousSource !== undefined) {
|
|
829
|
+
source = previousSource;
|
|
830
|
+
source.rowKey = previousTarget.rowKey;
|
|
831
|
+
source.itemIndex = previousTarget.itemIndex;
|
|
832
|
+
source.itemStart = itemStart;
|
|
833
|
+
source.rowStart = rowStart;
|
|
834
|
+
} else {
|
|
835
|
+
source = { rowKey: previousTarget.rowKey, itemIndex: previousTarget.itemIndex, itemStart, rowStart, hasRecipients: false };
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
this.percentSource = source;
|
|
839
|
+
if (previousTarget !== undefined) {
|
|
840
|
+
previousTarget.rowKey = rowKey;
|
|
841
|
+
previousTarget.itemIndex = info.itemIndex;
|
|
842
|
+
previousTarget.itemStart = targetItemStart;
|
|
843
|
+
previousTarget.rowStart = targetRowStart;
|
|
844
|
+
} else {
|
|
845
|
+
this.percentTarget = { rowKey, itemIndex: info.itemIndex, itemStart: targetItemStart, rowStart: targetRowStart, hasRecipients: false };
|
|
846
|
+
}
|
|
847
|
+
this.focusPercent = 0;
|
|
848
|
+
// Keep transition history for first acquisition and reversals, but do not
|
|
849
|
+
// resolve membership in an empty registry. Registration refreshes it when
|
|
850
|
+
// the first recipient arrives; final removal clears the cached flags.
|
|
851
|
+
if (this.percentRecipientCount === 0) return;
|
|
852
|
+
this.refreshFocusPercentRecipients();
|
|
853
|
+
this.publishFocusPercents();
|
|
854
|
+
// Third destinations retire old endpoints once; no growing collection of trailing animations.
|
|
855
|
+
if (retireSource && retiredRowKey !== undefined) {
|
|
856
|
+
this.publishFocusPercentRow(retiredRowKey);
|
|
857
|
+
this.publishFocusPercentEndpoint(retiredRowKey, retiredItemIndex);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
private getLogicalItemFocusPercent(rowKey: string, itemIndex: number): number {
|
|
862
|
+
// Bound samples on consumption, not on callbacks-disabled movement ticks. The
|
|
863
|
+
// indicator retains its original progress semantics, including the negative guard.
|
|
864
|
+
const progress = this.focusPercent;
|
|
865
|
+
const target = this.percentTarget;
|
|
866
|
+
if (target?.rowKey === rowKey && target.itemIndex === itemIndex) {
|
|
867
|
+
if (progress >= 1) return 1;
|
|
868
|
+
if (progress <= 0) return target.itemStart;
|
|
869
|
+
return target.itemStart + (1 - target.itemStart) * progress;
|
|
870
|
+
}
|
|
871
|
+
const source = this.percentSource;
|
|
872
|
+
if (source?.rowKey === rowKey && source.itemIndex === itemIndex) {
|
|
873
|
+
if (progress >= 1) return 0;
|
|
874
|
+
if (progress <= 0) return source.itemStart;
|
|
875
|
+
return source.itemStart * (1 - progress);
|
|
876
|
+
}
|
|
877
|
+
return 0;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
private getLogicalRowFocusPercent(rowKey: string): number {
|
|
881
|
+
const progress = this.focusPercent;
|
|
882
|
+
const target = this.percentTarget;
|
|
883
|
+
if (target?.rowKey === rowKey) {
|
|
884
|
+
if (progress >= 1) return 1;
|
|
885
|
+
if (progress <= 0) return target.rowStart;
|
|
886
|
+
return target.rowStart + (1 - target.rowStart) * progress;
|
|
887
|
+
}
|
|
888
|
+
const source = this.percentSource;
|
|
889
|
+
if (source?.rowKey === rowKey) {
|
|
890
|
+
if (progress >= 1) return 0;
|
|
891
|
+
if (progress <= 0) return source.rowStart;
|
|
892
|
+
return source.rowStart * (1 - progress);
|
|
893
|
+
}
|
|
894
|
+
return 0;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
private getPublishedRowFocusPercent(rowKey: string): number {
|
|
898
|
+
if (!this.percentInFocusChain) return 0;
|
|
899
|
+
if (this.percentSupplementaryRowKey !== '') return this.percentSupplementaryRowKey === rowKey ? 1 : 0;
|
|
900
|
+
return this.getLogicalRowFocusPercent(rowKey);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
private publishFocusPercentCell(registration: ICollectionViewFocusPercentRegistration, force = false): void {
|
|
904
|
+
// Only active row membership reaches publication.
|
|
905
|
+
const cell = registration.cell!;
|
|
906
|
+
const itemPercent = this.percentInFocusChain && this.percentSupplementaryRowKey === ''
|
|
907
|
+
? this.getLogicalItemFocusPercent(registration.rowKey, registration.itemIndex)
|
|
908
|
+
: 0;
|
|
909
|
+
const rowPercent = this.getPublishedRowFocusPercent(registration.rowKey);
|
|
910
|
+
if (!force
|
|
911
|
+
&& (!cell.supportsFocusPercent || cell.focusPercent === itemPercent)
|
|
912
|
+
&& (!cell.supportsRowFocusPercent || cell.rowFocusPercent === rowPercent)) return;
|
|
913
|
+
cell.setFocusPercents?.(itemPercent, rowPercent, force);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
private publishFocusPercentEndpoint(rowKey: string, itemIndex: number): void {
|
|
917
|
+
const registration = this.percentRows[rowKey]?.cells[itemIndex.toString()];
|
|
918
|
+
if (registration?.cell?.supportsFocusPercent) this.publishFocusPercentCell(registration);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
private publishFocusPercentRow(rowKey: string): void {
|
|
922
|
+
const row = this.percentRows[rowKey];
|
|
923
|
+
if (!row) return;
|
|
924
|
+
const rowPercent = this.getPublishedRowFocusPercent(rowKey);
|
|
925
|
+
if (row.lastRowPercent === rowPercent) return;
|
|
926
|
+
row.lastRowPercent = rowPercent;
|
|
927
|
+
// Swap-removal during a callback can only move an already visited tail into
|
|
928
|
+
// an earlier slot. Equal samples are skipped, so remaining cells are not missed.
|
|
929
|
+
for (let index = row.rowCells.length - 1; index >= 0; index--) {
|
|
930
|
+
const registration = row.rowCells[index];
|
|
931
|
+
// A callback may remove several cells and shorten the array past this slot.
|
|
932
|
+
if (registration !== undefined) this.publishFocusPercentCell(registration);
|
|
933
|
+
}
|
|
934
|
+
row.header?.setRowFocusPercent(rowPercent);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
private publishFocusPercents(): void {
|
|
938
|
+
if (!this.percentHasActiveRecipients) return;
|
|
939
|
+
this.percentInFocusChain = this.collectionView.isInFocusChain();
|
|
940
|
+
const source = this.percentSource;
|
|
941
|
+
const target = this.percentTarget;
|
|
942
|
+
if (source?.hasRecipients) {
|
|
943
|
+
this.publishFocusPercentRow(source.rowKey);
|
|
944
|
+
this.publishFocusPercentEndpoint(source.rowKey, source.itemIndex);
|
|
945
|
+
}
|
|
946
|
+
if (target?.hasRecipients) {
|
|
947
|
+
this.publishFocusPercentRow(target.rowKey);
|
|
948
|
+
this.publishFocusPercentEndpoint(target.rowKey, target.itemIndex);
|
|
949
|
+
}
|
|
950
|
+
if (this.percentSupplementaryHasRecipients) this.publishFocusPercentRow(this.percentSupplementaryRowKey);
|
|
951
|
+
}
|
|
952
|
+
|
|
544
953
|
/**
|
|
545
954
|
* Applies focus to the currently focused row in the collection view.
|
|
546
955
|
* @param focused - Whether the collection view remains in the focus chain.
|
|
@@ -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
|
|