@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.
Files changed (30) hide show
  1. package/dist-manifest.json +33 -29
  2. package/package.json +1 -1
  3. package/src/hosanna-bridge-core/color.ts +140 -0
  4. package/src/hosanna-bridge-targets/web/brs/WebRoBitmap.ts +14 -0
  5. package/src/hosanna-bridge-targets/web/sg/WebSGPoster.ts +1 -1
  6. package/src/hosanna-game/color.ts +3 -115
  7. package/src/hosanna-list/BaseCell.ts +4 -0
  8. package/src/hosanna-list/BaseCollectionViewLayout.ts +59 -6
  9. package/src/hosanna-list/CollectionView.ts +14 -5
  10. package/src/hosanna-list/CollectionViewAPI.ts +41 -5
  11. package/src/hosanna-list/CollectionViewFocusManager.ts +415 -6
  12. package/src/hosanna-list/CollectionViewSupplementaryView.ts +49 -1
  13. package/src/hosanna-list/DynamicCell.ts +132 -2
  14. package/src/hosanna-list/EPGProgramLayout.ts +1 -0
  15. package/src/hosanna-list/GridRowLayout.ts +1 -0
  16. package/src/hosanna-list/HorizontalRowLayout.ts +1 -0
  17. package/src/hosanna-list/ListRowLayout.ts +1 -0
  18. package/src/hosanna-ui/app-roku/HosannaApp.xml +2 -1
  19. package/src/hosanna-ui/async/ImageGeneratorCommands.ts +0 -20
  20. package/src/hosanna-ui/lib/BaseApp.ts +11 -6
  21. package/src/hosanna-ui/lib/ConfigurationLoader.ts +11 -3
  22. package/src/hosanna-ui/lib/FragmentUtils.ts +26 -10
  23. package/src/hosanna-ui/lib/animation.ts +358 -235
  24. package/src/hosanna-ui/lib/shapes/ShapeLoader.ts +22 -27
  25. package/src/hosanna-ui/views/controls/Button.ts +16 -1
  26. package/src/hosanna-ui/views/lib/AppConfig.ts +26 -0
  27. package/src/hosanna-ui/views/lib/BaseView.ts +98 -21
  28. package/src/hosanna-ui/views/lib/ViewFragmentProvider.ts +39 -5
  29. package/src/hosanna-ui/views/primitives/Image.ts +1 -1
  30. package/src/hosanna-ui/views/primitives/Label.ts +3 -3
@@ -109,12 +109,6 @@ function validateMaskEntry(styleKey: string, entry: ShapeStyleEntry): void {
109
109
  /**
110
110
  * Compiles `theme.shapes` into `theme.compiledShapes`.
111
111
  *
112
- * On Roku each entry is pre-rendered to a nine-patch image by the
113
- * imageGenerator task and compiles to `{ uri, translationOffset, sizeOffset }`.
114
- * On all other platforms shapes draw natively, so each entry compiles to its
115
- * resolved shape fields and no task work is done. Build-generated image
116
- * metadata is retained so Image consumers can use the same packaged assets.
117
- *
118
112
  * Safe to call at any time. Must be re-run after a config reload
119
113
  * (`setConfig` replaces styles wholesale, wiping `theme.compiledShapes`);
120
114
  * fragments created before that re-run must be recreated to pick up changes.
@@ -130,27 +124,6 @@ export function loadShapesForAppConfig(appConfig: IAppConfig): HsPromise<void> {
130
124
 
131
125
  const resolverOptions = getResolverOptions(appConfig, shapes);
132
126
 
133
- if (!__ROKU__) {
134
- const supplied = appConfig.get<Record<string, CompiledShape>>(THEME_COMPILED_SHAPES_KEY, {});
135
- const compiled: Record<string, CompiledShape> = { ...supplied };
136
- for (const styleKey in shapes) {
137
- validateMaskEntry(styleKey, shapes[styleKey]);
138
- const spec = resolveShapeSpecFields(shapes[styleKey], resolverOptions);
139
- compiled[styleKey] = {
140
- ...supplied[styleKey],
141
- kind: spec.kind,
142
- fillColor: spec.fillColor,
143
- cornerRadius: spec.cornerRadius,
144
- strokeColor: spec.strokeColor,
145
- strokeWidth: spec.strokeWidth,
146
- shadows: spec.shadows,
147
- };
148
- }
149
- storeCompiledShapes(appConfig, compiled);
150
- resolve();
151
- return;
152
- }
153
-
154
127
  const requests: Record<string, ShapePatchRequest> = {};
155
128
  const supplied = appConfig.get<Record<string, CompiledShape>>(THEME_COMPILED_SHAPES_KEY, {});
156
129
  const compiled: Record<string, CompiledShape> = { ...supplied };
@@ -203,11 +176,33 @@ export function loadShapesForAppConfig(appConfig: IAppConfig): HsPromise<void> {
203
176
  requestCount++;
204
177
  }
205
178
 
179
+ if (!__ROKU__) {
180
+ for (const styleKey in shapes) {
181
+ const spec = resolveShapeSpecFields(shapes[styleKey], resolverOptions);
182
+ compiled[styleKey] = {
183
+ ...compiled[styleKey],
184
+ kind: spec.kind,
185
+ fillColor: spec.fillColor,
186
+ cornerRadius: spec.cornerRadius,
187
+ strokeColor: spec.strokeColor,
188
+ strokeWidth: spec.strokeWidth,
189
+ shadows: spec.shadows,
190
+ };
191
+ }
192
+ }
193
+
206
194
  // uris and offsets are deterministic from the spec, so the compiled map is
207
195
  // valid before generation completes; the promise gates on the task so
208
196
  // callers can await the images existing on disk.
209
197
  storeCompiledShapes(appConfig, compiled);
210
198
 
199
+ if (!__ROKU__) {
200
+ if (requestCount === 0) {
201
+ resolve();
202
+ return;
203
+ }
204
+ }
205
+
211
206
  const compileState: {
212
207
  settled: boolean;
213
208
  timeoutHandle?: ReturnType<typeof setTimeout>;
@@ -288,7 +288,14 @@ export class ButtonView<T extends ButtonState = ButtonState, R extends ISGNGroup
288
288
  }
289
289
 
290
290
  protected override updateViewStatus(viewStatus: ViewStatus) {
291
- super.updateViewStatus(this.isSelected && viewStatus === ViewStatus.Normal ? ViewStatus.Selected : viewStatus);
291
+ let resolvedStatus = viewStatus;
292
+ if (this.isSelected) {
293
+ if (viewStatus === ViewStatus.Normal) resolvedStatus = ViewStatus.Selected;
294
+ if (viewStatus === ViewStatus.Focused && this.activeStyle?.animated && this.activeStyle.focusSelected) {
295
+ resolvedStatus = ViewStatus.FocusSelected;
296
+ }
297
+ }
298
+ super.updateViewStatus(resolvedStatus);
292
299
  }
293
300
 
294
301
  /**
@@ -308,8 +315,16 @@ export class ButtonView<T extends ButtonState = ButtonState, R extends ISGNGroup
308
315
  override applyStateChanges(nextState?: T): void {
309
316
  const pendingSelected = this.pendingState.isSelected;
310
317
  const wasSelected = this.state.isSelected === true;
318
+ if (this.viewPhase === ViewPhase.Initial && pendingSelected === true && this.activeStyle?.animated) {
319
+ if (this.pendingState.viewStatus === undefined || this.pendingState.viewStatus === ViewStatus.Normal) {
320
+ this.pendingState.viewStatus = ViewStatus.Selected;
321
+ }
322
+ }
311
323
  super.applyStateChanges(nextState);
312
324
  if (this.isFocused) {
325
+ if (pendingSelected !== undefined && this.activeStyle?.animated && this.activeStyle.focusSelected) {
326
+ this.updateViewStatus(this.isSelected ? ViewStatus.FocusSelected : ViewStatus.Focused);
327
+ }
313
328
  return;
314
329
  }
315
330
  if (pendingSelected === true) {
@@ -74,6 +74,12 @@ export type ViewFragmentCallbackHandler = (
74
74
  args?: unknown[],
75
75
  ) => void;
76
76
 
77
+ /** CollectionView presentation callback; receives a normalized focus value without rebinding content. */
78
+ export type ViewFragmentFocusPercentCallbackHandler = (
79
+ viewFragment: IViewFragment,
80
+ percent: number,
81
+ ) => void;
82
+
77
83
  export type ISpecificViewFragmentCallbackHandler = (
78
84
  data: JsonData,
79
85
  view: ISGNNode,
@@ -87,6 +93,8 @@ export enum ViewFragmentCallbackType {
87
93
  OnApplyViewStatus = 'onApplyViewStatus',
88
94
  OnDataChange = 'onDataChange',
89
95
  OnSpecificViewDataChange = 'onSpecificViewDataChange',
96
+ OnFocusPercentChanged = 'onFocusPercentChanged',
97
+ OnRowFocusPercentChanged = 'onRowFocusPercentChanged',
90
98
  }
91
99
 
92
100
  export interface IViewFragmentCallbackMap {
@@ -95,10 +103,13 @@ export interface IViewFragmentCallbackMap {
95
103
  onApplyViewStatus?: ViewFragmentCallbackHandler[];
96
104
  onDataChange?: ViewFragmentCallbackHandler[];
97
105
  onSpecificViewDataChange?: ISpecificViewFragmentCallbackHandler[];
106
+ onFocusPercentChanged?: ViewFragmentFocusPercentCallbackHandler[];
107
+ onRowFocusPercentChanged?: ViewFragmentFocusPercentCallbackHandler[];
98
108
  }
99
109
 
100
110
  export type FragmentCallbackEntry = string | AsyncFunctionPointer<ViewFragmentCallbackHandler>;
101
111
  export type SpecificFragmentCallbackEntry = string | AsyncFunctionPointer<ISpecificViewFragmentCallbackHandler>;
112
+ export type FocusPercentFragmentCallbackEntry = string | AsyncFunctionPointer<ViewFragmentFocusPercentCallbackHandler>;
102
113
 
103
114
  export interface IViewFragmentCallbackNameMap {
104
115
  onMount?: FragmentCallbackEntry[];
@@ -106,6 +117,8 @@ export interface IViewFragmentCallbackNameMap {
106
117
  onApplyViewStatus?: FragmentCallbackEntry[];
107
118
  onDataChange?: FragmentCallbackEntry[];
108
119
  onSpecificViewDataChange?: SpecificFragmentCallbackEntry[];
120
+ onFocusPercentChanged?: FocusPercentFragmentCallbackEntry[];
121
+ onRowFocusPercentChanged?: FocusPercentFragmentCallbackEntry[];
109
122
  }
110
123
 
111
124
  export interface IParsedFunctionMapping {
@@ -127,6 +140,10 @@ export interface IViewFragment {
127
140
  styleKey: string;
128
141
  view: ISGNGroup;
129
142
  viewStatus: ViewStatus;
143
+ /** CollectionView-owned item focus from 0 to 1; present only for an opted-in cell fragment. */
144
+ focusPercent?: number;
145
+ /** CollectionView-owned row focus from 0 to 1; present only for an opted-in cell or header fragment. */
146
+ rowFocusPercent?: number;
130
147
  dataMap: IViewFragmentDataMap;
131
148
  /** Shared from the provider's resolved-style cache; avoids rebuilding the data/fn binding-id set per fragment and bind. */
132
149
  dataMapBindingViewIds?: string[];
@@ -400,6 +417,13 @@ export type IStyle =
400
417
  | IStyleDictionary;
401
418
 
402
419
 
420
+ /** Provisional focus-transition descriptor; endpoint values stay in the status styles. */
421
+ export interface IViewStyleAnimation {
422
+ properties: string[];
423
+ focusInMs: number;
424
+ focusOutMs: number;
425
+ }
426
+
403
427
  export interface IStatefulStyle {
404
428
  none?: IStyleDictionary;
405
429
  normal: IStyleDictionary;
@@ -408,6 +432,8 @@ export interface IStatefulStyle {
408
432
  error?: IStyleDictionary;
409
433
  disabled?: IStyleDictionary;
410
434
  focuseeSelected?: IStyleDictionary;
435
+ focusSelected?: IStyleDictionary;
436
+ animated?: IViewStyleAnimation;
411
437
  }
412
438
 
413
439
  export interface IFunctionMapping {
@@ -217,6 +217,8 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
217
217
  // passed in through view state belongs to the caller and is only suspended.
218
218
  private disposesViewModelOnUnmount = true;
219
219
  private hasStartedViewModel = false;
220
+ private isViewModelSuspended = false;
221
+ private hasReleasedViewModel = false;
220
222
  private boundViewModelHid = '';
221
223
  private isApplyingViewModelFocus = false;
222
224
  private lastReportedViewModelFocusId = '';
@@ -271,6 +273,11 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
271
273
  protected _rendereredTranslationValue: [number, number] = [0, 0];
272
274
 
273
275
  get _rendereredTranslation(): [number, number] {
276
+ const transition = this.activeAnimation;
277
+ if (transition && transition.ownsField(this as unknown as BaseView<ViewState>, 'translation')) {
278
+ const renderer = this.renderer;
279
+ if (renderer) return renderer.translation as [number, number];
280
+ }
274
281
  return this._rendereredTranslationValue;
275
282
  }
276
283
 
@@ -392,6 +399,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
392
399
  }
393
400
 
394
401
  set renderer(value: R | undefined) {
402
+ this.activeAnimation?.releaseView(this as unknown as BaseView<ViewState>);
395
403
  if (this._renderer) {
396
404
  // hs:exclude-from-platform roku - web only
397
405
  this._renderer.boundView = undefined;
@@ -673,13 +681,15 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
673
681
  if (!style) return undefined;
674
682
 
675
683
  // Return the resolved style for the current viewStatus
676
- this.activeStyleDictionary = style[this.viewStatus as keyof typeof style] ?? style['normal'];
684
+ this.activeStyleDictionary = ((style as JsonData)[this.viewStatus] ?? style.normal) as IStyleDictionary;
677
685
  }
678
686
 
679
687
  protected applyActiveStyleDictionary(): void {
680
688
 
681
689
 
682
690
  if (this.activeStyle && (this.activeStyleViewStatus === ViewStatus.None || this.activeStyleViewStatus !== this.activeViewStatus)) {
691
+ const previousStatus = this.activeStyleViewStatus;
692
+ const previousTransition = this.activeAnimation;
683
693
  if (this.activeViewStatus) {
684
694
  this.activeStyleViewStatus = this.activeViewStatus;
685
695
  } else {
@@ -719,6 +729,24 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
719
729
  }
720
730
  }
721
731
  const nextState = nextStateData as T;
732
+ const focused = this.activeViewStatus === ViewStatus.Focused || this.activeViewStatus === ViewStatus.FocusSelected;
733
+ const previousWasFocusState = previousStatus === ViewStatus.Normal || previousStatus === ViewStatus.Selected
734
+ || previousStatus === ViewStatus.Focused || previousStatus === ViewStatus.FocusSelected;
735
+ const isFocusState = focused || this.activeViewStatus === ViewStatus.Normal || this.activeViewStatus === ViewStatus.Selected;
736
+ const descriptor = this.activeStyle.animated;
737
+ let transition: HosannaViewAnimator | undefined;
738
+ if (descriptor && previousWasFocusState && isFocusState && this.viewPhase === ViewPhase.Mounted
739
+ && Array.isArray(descriptor.properties)) {
740
+ const targets: JsonData = {};
741
+ for (const property of descriptor.properties) {
742
+ if (property === 'opacity' || property === 'scale' || property === 'labelOpacity'
743
+ || property === 'backgroundColor' || property === 'color' || property === 'translation') {
744
+ targets[property] = nextStateData[property];
745
+ }
746
+ }
747
+ transition = HosannaViewAnimator.prepare(this as unknown as BaseView<ViewState>, targets,
748
+ focused ? descriptor.focusInMs : descriptor.focusOutMs);
749
+ }
722
750
  // this.setState(nextState);
723
751
  let isLayoutDirty = false;
724
752
  const fields = layoutFields;
@@ -742,6 +770,10 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
742
770
  //TODO - should we use the regular state invalidation api here, instead of this
743
771
  //efficient shortcut.
744
772
  this.applyStateChanges(nextState);
773
+ // Composite controls render their children, so their own layout fields also
774
+ // need the configured endpoint. Active transition fields remain excluded.
775
+ if (descriptor || previousTransition) this.applyLayoutStateToNativeRenderer(this.state);
776
+ transition?.startPrepared();
745
777
  }
746
778
  }
747
779
 
@@ -761,9 +793,19 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
761
793
  this.nextViewId = 0;
762
794
 
763
795
  //OPTIMIZE NO POINT MERGING IF WE ARE A NATIVE RENDERER
764
- if (this.pendingState.styleKey) {
796
+ if (this.pendingState.styleKey && this.pendingState.styleKey !== this.activeStyleKey) {
765
797
  console.debug('potential change that affects the style');
766
798
  this.resolveActiveStyleDictionary(this.pendingState);
799
+ this.activeStyleKey = this.pendingState.styleKey;
800
+ if (this.pendingState.viewStatus !== undefined) {
801
+ this.activeViewStatus = this.pendingState.viewStatus;
802
+ delete this.pendingState.viewStatus;
803
+ }
804
+ if (this.activeStyle) {
805
+ this.applyActiveStyleDictionary();
806
+ return;
807
+ }
808
+ this.activeAnimation?.handoff({}, {});
767
809
  }
768
810
 
769
811
  if (this.pendingState.viewStatus !== undefined) {
@@ -794,6 +836,8 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
794
836
  }
795
837
  }
796
838
 
839
+ const cancelledAnimation = this.activeAnimation?.reconcile(this as unknown as BaseView<ViewState>);
840
+
797
841
  //NOTE - REALLY WE WILL WANT TO BE DOING SOMETHIG FAR MORE EFFICIENT HERE.
798
842
  // Now that state is updated, calculate what the views should be
799
843
  //WHAT SHOULD LIKELY HAPPEN HERE IS THAT WE SHOULD HAVE A CACHE OF STRUCTS LOCALLY BY INITIAL ID
@@ -829,7 +873,8 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
829
873
 
830
874
  //TODO we might want to measure and tell the layout manager to lay us out.
831
875
  // this.layoutChildren();
832
- this.applyLayoutStateToNativeRenderer(this.isWaking ? this.buildLayoutStateForWakingNativeRenderer() : this.pendingState);
876
+ this.applyLayoutStateToNativeRenderer(this.isWaking ? this.buildLayoutStateForWakingNativeRenderer()
877
+ : cancelledAnimation ? this.state : this.pendingState);
833
878
  //END: THERE IS AN ARGUMENT TO SAY DONT BOTHER GETTING VIEWS IN THIS CASE
834
879
 
835
880
  // this.applyChildFocus();
@@ -1046,6 +1091,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
1046
1091
  //HACK
1047
1092
  //HACK
1048
1093
  fieldsToUpdate['id'] = this._hid;
1094
+ this.excludeAnimatedRendererFields(fieldsToUpdate);
1049
1095
  this.renderer.update(fieldsToUpdate);
1050
1096
  }
1051
1097
  }
@@ -1058,16 +1104,18 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
1058
1104
  const renderer = this.renderer as any;
1059
1105
  if (renderer) {
1060
1106
  if (renderer.translation) {
1061
- renderer.translation = [x, y];
1107
+ if (!this.activeAnimation?.ownsField(this as unknown as BaseView<ViewState>, 'translation')) renderer.translation = [x, y];
1062
1108
  this._rendereredTranslation = [x, y];
1063
1109
  }
1064
1110
  // Use calculatedWidth/calculatedHeight if available (from measure()), otherwise use width/height
1065
1111
  const width = this.calculatedWidth || this.width;
1066
- if (width !== 0 && renderer.width !== undefined) {
1112
+ if (width !== 0 && renderer.width !== undefined
1113
+ && !this.activeAnimation?.ownsField(this as unknown as BaseView<ViewState>, 'width')) {
1067
1114
  renderer.width = width;
1068
1115
  }
1069
1116
  const height = this.calculatedHeight || this.height;
1070
- if (height !== 0 && renderer.height !== undefined) {
1117
+ if (height !== 0 && renderer.height !== undefined
1118
+ && !this.activeAnimation?.ownsField(this as unknown as BaseView<ViewState>, 'height')) {
1071
1119
  renderer.height = height;
1072
1120
  }
1073
1121
  }
@@ -1857,9 +1905,24 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
1857
1905
  }
1858
1906
  }
1859
1907
 
1908
+ this.excludeAnimatedRendererFields(updateFields);
1860
1909
  this.renderer.update(updateFields);
1861
1910
  }
1862
1911
 
1912
+ private excludeAnimatedRendererFields(fields: Record<string, unknown>): void {
1913
+ const transition = this.activeAnimation;
1914
+ if (!transition) return;
1915
+ for (const field in fields) {
1916
+ if (transition.ownsField(this as unknown as BaseView<ViewState>, field)) delete fields[field];
1917
+ }
1918
+ }
1919
+
1920
+ /** @internal Reconcile remaining presentation after an explicit value cancels a transition. */
1921
+ invalidateAnimationPresentation(): void {
1922
+ this.isDirty = true;
1923
+ this.viewManager.invalidateViewState(this);
1924
+ }
1925
+
1863
1926
  //sets the entire state
1864
1927
  setState(state: Partial<T>): void {
1865
1928
  for (const field in state) {
@@ -2186,6 +2249,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
2186
2249
  * Only runs onReleaseRenderer when renderer is defined; overrides may treat `renderer` as non-null.
2187
2250
  */
2188
2251
  protected releaseRenderer(): void {
2252
+ this.activeAnimation?.releaseView(this as unknown as BaseView<ViewState>);
2189
2253
  const renderer = this.renderer;
2190
2254
  if (renderer === undefined) {
2191
2255
  return;
@@ -2200,6 +2264,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
2200
2264
  * The recipient must eventually unmount and release the returned renderer.
2201
2265
  */
2202
2266
  protected detachRenderer(): R | undefined {
2267
+ this.activeAnimation?.releaseView(this as unknown as BaseView<ViewState>);
2203
2268
  const renderer = this._renderer;
2204
2269
  this._renderer = undefined;
2205
2270
  // hs:exclude-from-platform roku
@@ -2695,6 +2760,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
2695
2760
  * even when the logical value equals the class default.
2696
2761
  */
2697
2762
  onWillReuse(): void {
2763
+ this.activeAnimation?.releaseView(this as unknown as BaseView<ViewState>);
2698
2764
  this.recycleViewModel();
2699
2765
  this.cancelActiveViewDrag();
2700
2766
  const className = this._cacheKey;
@@ -2808,6 +2874,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
2808
2874
  }
2809
2875
 
2810
2876
  onDidRemoveFromAggregateView(view: IAggregateView): void {
2877
+ this.releaseViewModel();
2811
2878
  if (this.eventHandlers['onDidRemoveFromAggregateView']) {
2812
2879
  this.eventHandlers['onDidRemoveFromAggregateView'](view);
2813
2880
  }
@@ -2849,6 +2916,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
2849
2916
  const vm = this.viewModel;
2850
2917
  if (vm) {
2851
2918
  this.bindViewModel();
2919
+ this.isViewModelSuspended = false;
2852
2920
  if (this.hasStartedViewModel) {
2853
2921
  vm.resume(this.getViewModelContext());
2854
2922
  } else {
@@ -2867,9 +2935,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
2867
2935
  if (this.eventHandlers['onDisappear']) {
2868
2936
  this.eventHandlers['onDisappear']();
2869
2937
  }
2870
- if (this.viewModel && this.hasStartedViewModel) {
2871
- this.viewModel.suspend();
2872
- }
2938
+ this.suspendViewModel();
2873
2939
  }
2874
2940
 
2875
2941
  setShowOnScreen(shown: boolean) {
@@ -3450,6 +3516,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
3450
3516
  if (!vm) {
3451
3517
  return;
3452
3518
  }
3519
+ this.hasReleasedViewModel = false;
3453
3520
  vm.addObserver('__internalState', this, (field) => {
3454
3521
  const current = this.viewModel;
3455
3522
  if (!current) {
@@ -3478,13 +3545,15 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
3478
3545
  }
3479
3546
  if (previous) {
3480
3547
  previous.removeObservers(this);
3481
- if (this.disposesViewModelOnUnmount) {
3548
+ if (this.disposesViewModelOnUnmount && !previous.isDisposed) {
3482
3549
  previous.dispose();
3483
3550
  }
3484
3551
  }
3485
3552
  this.viewModel = vm;
3486
3553
  this.disposesViewModelOnUnmount = false;
3487
3554
  this.hasStartedViewModel = false;
3555
+ this.isViewModelSuspended = false;
3556
+ this.hasReleasedViewModel = false;
3488
3557
  this.boundViewModelHid = '';
3489
3558
  this.lastReportedViewModelFocusId = '';
3490
3559
  this.pendingViewModelFocus = '';
@@ -3494,39 +3563,47 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
3494
3563
  /** The view is unmounted: its own model is finished; a parent's model is only paused. */
3495
3564
  private releaseViewModel(): void {
3496
3565
  const vm = this.viewModel;
3497
- if (!vm) {
3566
+ if (!vm || this.hasReleasedViewModel) {
3498
3567
  return;
3499
3568
  }
3569
+ this.hasReleasedViewModel = true;
3500
3570
  vm.removeObservers(this);
3501
3571
  this.boundViewModelHid = '';
3502
3572
  this.lastReportedViewModelFocusId = '';
3503
3573
  this.pendingViewModelFocus = '';
3504
3574
  if (!this.disposesViewModelOnUnmount) {
3505
- if (this.hasStartedViewModel) {
3506
- vm.suspend();
3507
- }
3575
+ this.suspendViewModel();
3508
3576
  return;
3509
3577
  }
3510
- // Dispose only when a fresh model can take its place, so a view that is
3511
- // mounted again never holds a dead one.
3512
3578
  const replacement = this.createViewModel();
3513
- if (replacement) {
3579
+ this.viewModel = replacement;
3580
+ this.hasStartedViewModel = false;
3581
+ this.isViewModelSuspended = false;
3582
+ if (!vm.isDisposed) {
3514
3583
  vm.dispose();
3515
- this.viewModel = replacement;
3516
- this.hasStartedViewModel = false;
3517
- } else if (this.hasStartedViewModel) {
3584
+ }
3585
+ }
3586
+
3587
+ private suspendViewModel(): void {
3588
+ const vm = this.viewModel;
3589
+ if (vm && this.hasStartedViewModel && !this.isViewModelSuspended && !vm.isDisposed) {
3590
+ this.isViewModelSuspended = true;
3518
3591
  vm.suspend();
3519
3592
  }
3520
3593
  }
3521
3594
 
3522
3595
  /** The view instance is being reused for another screen: drop a parent's model and start clean. */
3523
3596
  private recycleViewModel(): void {
3597
+ if (this.hasStartedViewModel || this.boundViewModelHid !== '' || this.viewModel?.isDisposed) {
3598
+ this.releaseViewModel();
3599
+ }
3524
3600
  if (!this.disposesViewModelOnUnmount) {
3525
- this.viewModel?.removeObservers(this);
3526
3601
  this.viewModel = this.createViewModel();
3527
3602
  this.disposesViewModelOnUnmount = true;
3528
3603
  }
3529
3604
  this.hasStartedViewModel = false;
3605
+ this.isViewModelSuspended = false;
3606
+ this.hasReleasedViewModel = false;
3530
3607
  this.boundViewModelHid = '';
3531
3608
  this.lastReportedViewModelFocusId = '';
3532
3609
  this.pendingViewModelFocus = '';
@@ -7,7 +7,7 @@ import { ISGNGroup, ISGNScene, ISGNNode, ISGNPoster } from '@hs-src/hosanna-brid
7
7
  import { IBaseCollectionViewRow } from '@hs-src/hosanna-list/CollectionViewAPI';
8
8
  import { JsonData } from '../../async/AsyncApi';
9
9
  import { ViewStatus } from '../../hosanna-api';
10
- import { IFragmentStyle, IStyleDictionary, IViewFragment, IViewFragmentDataMap, AppConfig, ViewFragmentCallbackHandler, ViewFragmentCallbackType, ISpecificViewFragmentCallbackHandler, IParsedFunctionMapping, FragmentCallbackEntry, SpecificFragmentCallbackEntry } from './AppConfig';
10
+ import { IFragmentStyle, IStyleDictionary, IViewFragment, IViewFragmentDataMap, AppConfig, ViewFragmentCallbackHandler, ViewFragmentCallbackType, ISpecificViewFragmentCallbackHandler, IParsedFunctionMapping, FragmentCallbackEntry, SpecificFragmentCallbackEntry, ViewFragmentFocusPercentCallbackHandler, FocusPercentFragmentCallbackEntry } from './AppConfig';
11
11
  import { findNode, mapChildrenById } from './utils';
12
12
  import { SystemMessageLevel } from '@hs-src/hosanna-bridge-lib/ISystemMessageManager';
13
13
  import { isComputedReference, substituteComputedReferences } from '@hs-src/hosanna-ui/lib/FragmentComputed';
@@ -119,7 +119,7 @@ export interface IViewFragmentProvider {
119
119
  * @param name - The name of the callback handler.
120
120
  * @param handler - The callback handler function.
121
121
  */
122
- registerViewFragmentCallback<T extends ViewFragmentCallbackHandler | ISpecificViewFragmentCallbackHandler>(type: ViewFragmentCallbackType, name: string, handler: T): void;
122
+ registerViewFragmentCallback<T extends ViewFragmentCallbackHandler | ISpecificViewFragmentCallbackHandler | ViewFragmentFocusPercentCallbackHandler>(type: ViewFragmentCallbackType, name: string, handler: T): void;
123
123
 
124
124
  /**
125
125
  * Debug-only: fragments currently checked out (not in available pool) with dangling hints.
@@ -183,7 +183,7 @@ export class ViewFragmentProvider implements IViewFragmentProvider {
183
183
  private viewsThatNeedToBeRemovedById: Record<string, ISGNGroup> = {};
184
184
 
185
185
  /** Registry for callback types and names mapped to handler functions. */
186
- private callbackRegistry: { [type in ViewFragmentCallbackType]?: { [name: string]: ViewFragmentCallbackHandler | ISpecificViewFragmentCallbackHandler } } = {};
186
+ private callbackRegistry: { [type in ViewFragmentCallbackType]?: { [name: string]: ViewFragmentCallbackHandler | ISpecificViewFragmentCallbackHandler | ViewFragmentFocusPercentCallbackHandler } } = {};
187
187
  private uniqueSGId = 0;
188
188
 
189
189
  /** Fragments currently checked out from the available pool (not in free stacks). */
@@ -528,7 +528,7 @@ export class ViewFragmentProvider implements IViewFragmentProvider {
528
528
  viewStatus: ViewStatus.Normal,
529
529
  dataMapViewsById: {} as Record<string, ISGNGroup>,
530
530
  $supportsDataMap: styleJson.$supportsDataMap || false,
531
- callbacks: {} as { [type in ViewFragmentCallbackType]?: ViewFragmentCallbackHandler[] },
531
+ callbacks: {} as { [type in ViewFragmentCallbackType]?: (ViewFragmentCallbackHandler | ViewFragmentFocusPercentCallbackHandler)[] },
532
532
  specificViewCallbacks: {} as { [key: string]: ISpecificViewFragmentCallbackHandler },
533
533
  viewsById: viewsById,
534
534
  refreshEffectStyles: Object.keys(effectStyleKeysById).length ? refreshEffectStyles : undefined,
@@ -563,6 +563,10 @@ export class ViewFragmentProvider implements IViewFragmentProvider {
563
563
  const key = typeKey as ViewFragmentCallbackType;
564
564
  const entries = callbacks[key];
565
565
  if (entries) {
566
+ if (key === ViewFragmentCallbackType.OnFocusPercentChanged || key === ViewFragmentCallbackType.OnRowFocusPercentChanged) {
567
+ fragment.callbacks[key] = this.resolveFocusPercentCallbacks(key, entries as FocusPercentFragmentCallbackEntry[]);
568
+ continue;
569
+ }
566
570
  fragment.callbacks[key] = (entries as (FragmentCallbackEntry | SpecificFragmentCallbackEntry)[]).map(entry => {
567
571
  if (typeof entry === 'string') {
568
572
  const handler = this.callbackRegistry[key]?.[entry];
@@ -684,6 +688,36 @@ export class ViewFragmentProvider implements IViewFragmentProvider {
684
688
  return fragment as unknown as IViewFragment;
685
689
  }
686
690
 
691
+ private resolveFocusPercentCallbacks(
692
+ callbackType: ViewFragmentCallbackType,
693
+ entries: FocusPercentFragmentCallbackEntry[],
694
+ ): ViewFragmentFocusPercentCallbackHandler[] {
695
+ const handlers: ViewFragmentFocusPercentCallbackHandler[] = [];
696
+ for (const entry of entries) {
697
+ let handler: ViewFragmentFocusPercentCallbackHandler | undefined;
698
+ if (typeof entry === 'string') {
699
+ handler = this.callbackRegistry[callbackType]?.[entry] as ViewFragmentFocusPercentCallbackHandler | undefined;
700
+ if (__ROKU__) {
701
+ if (!handler) {
702
+ try {
703
+ handler = hs_resolveAsyncFunctionPointer(entry as unknown as AsyncFunctionPointer<ViewFragmentFocusPercentCallbackHandler>);
704
+ } catch {
705
+ // An unregistered name may not be a resolvable native function pointer.
706
+ }
707
+ }
708
+ }
709
+ } else if (typeof entry === 'function') {
710
+ handler = entry;
711
+ }
712
+ if (handler) {
713
+ handlers.push(handler);
714
+ } else {
715
+ console.error(`Callback for ${callbackType} could not be resolved`);
716
+ }
717
+ }
718
+ return handlers;
719
+ }
720
+
687
721
  /**
688
722
  * Releases a fragment, making it available for reuse.
689
723
  * @param fragment The fragment to release.
@@ -1155,7 +1189,7 @@ export class ViewFragmentProvider implements IViewFragmentProvider {
1155
1189
  * @param name - The name used in style JSON.
1156
1190
  * @param handler - The function implementation.
1157
1191
  */
1158
- registerViewFragmentCallback<T extends ViewFragmentCallbackHandler | ISpecificViewFragmentCallbackHandler>(callbackType: ViewFragmentCallbackType, name: string, handler: T): void {
1192
+ registerViewFragmentCallback<T extends ViewFragmentCallbackHandler | ISpecificViewFragmentCallbackHandler | ViewFragmentFocusPercentCallbackHandler>(callbackType: ViewFragmentCallbackType, name: string, handler: T): void {
1159
1193
  if (!this.callbackRegistry[callbackType]) {
1160
1194
  this.callbackRegistry[callbackType] = {};
1161
1195
  }
@@ -98,7 +98,7 @@ export class ImageView<T extends ImageState = ImageState, R extends ISGNPoster =
98
98
  render(changes: Partial<T>): void {
99
99
  super.render(changes);
100
100
  if (this.renderer) {
101
- this.renderer.blendColor = this.color;
101
+ if (!this.activeAnimation?.ownsField(this, 'blendColor')) this.renderer.blendColor = this.color;
102
102
  this.renderer.loadingBitmapOpacity = this.loadingBitmapOpacity;
103
103
  this.renderer.loadingBitmapUri = this.loadingBitmapUri;
104
104
  this.renderer.failedBitmapOpacity = this.failedBitmapOpacity;
@@ -134,12 +134,12 @@ export class LabelView<T extends LabelState = LabelState, R extends ISGNLabel =
134
134
  this.calculatedY = y;
135
135
 
136
136
  if (this.renderer) {
137
- this.renderer.translation = [x, y];
137
+ if (!this.activeAnimation?.ownsField(this, 'translation')) this.renderer.translation = [x, y];
138
138
  this._rendereredTranslation = [x, y];
139
- if (this.width) {
139
+ if (this.width && !this.activeAnimation?.ownsField(this, 'width')) {
140
140
  this.renderer.width = this.width;
141
141
  }
142
- if (this.height) {
142
+ if (this.height && !this.activeAnimation?.ownsField(this, 'height')) {
143
143
  this.renderer.height = this.height;
144
144
  }
145
145
  }