@applicaster/zapp-react-native-utils 16.0.0-alpha.2024822855 → 16.0.0-alpha.2105365027

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 (109) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/ActionExecutor.ts +10 -1
  3. package/actionsExecutor/ActionExecutorContext.tsx +29 -1
  4. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  5. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +3 -0
  6. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  7. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  8. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +139 -5
  9. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
  10. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +201 -1
  11. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  12. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  13. package/actionsExecutor/actions/__tests__/showToast.test.ts +2 -2
  14. package/actionsExecutor/actions/dismissBottomSheet.ts +2 -1
  15. package/actionsExecutor/actions/goBack.ts +60 -0
  16. package/actionsExecutor/actions/goHome.ts +31 -0
  17. package/actionsExecutor/actions/index.ts +8 -0
  18. package/actionsExecutor/actions/navigateToScreen.ts +29 -45
  19. package/actionsExecutor/actions/openBottomSheet.ts +35 -16
  20. package/actionsExecutor/actions/presentScreen.ts +78 -0
  21. package/actionsExecutor/actions/showAlert.ts +51 -0
  22. package/actionsExecutor/actions/showToast.ts +2 -2
  23. package/actionsExecutor/consts.ts +4 -0
  24. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +4 -11
  25. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  26. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +9 -2
  27. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +15 -2
  28. package/appUtils/playerManager/OverlayObserver/utils.ts +2 -5
  29. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  30. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  31. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +97 -0
  32. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  33. package/appUtils/playerManager/const.ts +13 -0
  34. package/appUtils/playerManager/index.ts +7 -0
  35. package/appUtils/playerManager/player.ts +10 -0
  36. package/appUtils/playerManager/playerNative.ts +27 -3
  37. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  38. package/appUtils/playerManager/playerToolbox.ts +157 -0
  39. package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
  40. package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
  41. package/arrayUtils/index.ts +26 -43
  42. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  43. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  44. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  45. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  46. package/cellUtils/index.ts +74 -19
  47. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  48. package/configurationUtils/__tests__/modalBlocksParser.test.ts +286 -1
  49. package/configurationUtils/index.ts +77 -73
  50. package/configurationUtils/manifestKeyParser.ts +12 -1
  51. package/configurationUtils/modalBlocksParser.ts +78 -4
  52. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  53. package/entryActions/aliasPresentation.ts +108 -0
  54. package/entryActions/buildEntryActions.ts +167 -0
  55. package/entryActions/index.ts +15 -0
  56. package/entryActions/types.ts +39 -0
  57. package/focusManager/FocusManager.ts +26 -0
  58. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  59. package/localizationUtils/index.ts +12 -6
  60. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  61. package/logger/xrayToolbox.ts +67 -0
  62. package/manifestUtils/_internals/index.js +8 -3
  63. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  64. package/manifestUtils/defaultManifestConfigurations/player.js +30 -1
  65. package/manifestUtils/keys.js +6 -1
  66. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  67. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  68. package/manifestUtils/mobileAction/groups/defaults.js +2 -1
  69. package/modalState/ModalOrchestrator.ts +22 -9
  70. package/modalState/RemoteEditableCollection.ts +9 -1
  71. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +16 -0
  72. package/modalState/__tests__/RemoteEditableCollection.test.ts +90 -1
  73. package/modalState/__tests__/index.test.ts +30 -1
  74. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  75. package/modalState/index.ts +6 -1
  76. package/modalState/store.ts +9 -2
  77. package/modalState/types.ts +31 -2
  78. package/modalState/useBottomSheetContent.ts +24 -17
  79. package/navigationUtils/xrayNavigator.ts +12 -0
  80. package/package.json +2 -2
  81. package/perfTracker.ts +203 -0
  82. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  83. package/playerUtils/index.ts +17 -1
  84. package/playerUtils/resolvePlayerActions.ts +71 -0
  85. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  86. package/pluginUtils/index.ts +29 -0
  87. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  88. package/reactHooks/actions/index.ts +67 -2
  89. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  90. package/reactHooks/cell-click/index.ts +21 -14
  91. package/reactHooks/connection/index.tsx +8 -5
  92. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  93. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  94. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  95. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  96. package/reactHooks/navigation/index.ts +2 -0
  97. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  98. package/reactHooks/navigation/useRoute.ts +22 -5
  99. package/reactHooks/usePluginConfiguration.ts +84 -46
  100. package/riverComponetsMeasurementProvider/index.tsx +8 -1
  101. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  102. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  103. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  104. package/uiActionsRegistrator/index.ts +25 -203
  105. package/uiActionsRegistrator/registry.ts +351 -0
  106. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  107. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  108. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  109. package/playerUtils/getPlayerActionButtons.ts +0 -17
@@ -0,0 +1,142 @@
1
+ import { act, renderHook } from "@testing-library/react-native";
2
+
3
+ import { modalStore, useModalStoreState } from "../";
4
+
5
+ const item = { id: "river-general", name: "Test Modal" };
6
+ const props = { entry: { id: "modal-entry-1" } };
7
+
8
+ const openModal = () =>
9
+ act(() => {
10
+ modalStore.getState().openModal({ item, props } as any);
11
+ });
12
+
13
+ // Counts every render of the hook so the tests can assert on subscription
14
+ // behaviour, not just on the returned value.
15
+ const renderModalStoreState = (skipSubscription?: boolean) => {
16
+ const renders = { count: 0 };
17
+
18
+ const view = renderHook(() => {
19
+ renders.count += 1;
20
+
21
+ return skipSubscription === undefined
22
+ ? useModalStoreState()
23
+ : useModalStoreState(skipSubscription);
24
+ });
25
+
26
+ return { ...view, renders };
27
+ };
28
+
29
+ describe("useModalStoreState", () => {
30
+ afterEach(() => {
31
+ act(() => {
32
+ modalStore.getState().dismissModal();
33
+ });
34
+ });
35
+
36
+ describe("when subscribed (default)", () => {
37
+ it("returns the live modal state when called without arguments", () => {
38
+ const { result } = renderModalStoreState();
39
+
40
+ expect(result.current.visible).toBe(false);
41
+
42
+ openModal();
43
+
44
+ expect(result.current.visible).toBe(true);
45
+ expect(result.current.screen).toBe(item);
46
+ expect(result.current.props).toBe(props);
47
+ });
48
+
49
+ it("re-renders the consumer when the modal state changes", () => {
50
+ const { renders } = renderModalStoreState(false);
51
+
52
+ const rendersBeforeOpen = renders.count;
53
+
54
+ openModal();
55
+
56
+ expect(renders.count).toBeGreaterThan(rendersBeforeOpen);
57
+ });
58
+
59
+ // Counterpart to "returns a stable reference across store updates": an open
60
+ // modal is the one point where a live subscription and a skipped one hold
61
+ // different references, which is what makes that assertion meaningful.
62
+ it("returns a new reference while the modal is open", () => {
63
+ const { result } = renderModalStoreState(false);
64
+
65
+ const firstValue = result.current;
66
+
67
+ openModal();
68
+
69
+ expect(result.current).not.toBe(firstValue);
70
+ });
71
+ });
72
+
73
+ describe("when subscription is skipped", () => {
74
+ it("reports an empty modal state even while a modal is open", () => {
75
+ openModal();
76
+
77
+ expect(modalStore.getState().modalState.visible).toBe(true);
78
+
79
+ const { result } = renderModalStoreState(true);
80
+
81
+ expect(result.current).toMatchObject({
82
+ visible: false,
83
+ screen: null,
84
+ options: {},
85
+ props: {},
86
+ });
87
+ });
88
+
89
+ it("does not re-render the consumer when the modal state changes", () => {
90
+ const { renders } = renderModalStoreState(true);
91
+
92
+ const rendersBeforeOpen = renders.count;
93
+
94
+ openModal();
95
+
96
+ expect(renders.count).toBe(rendersBeforeOpen);
97
+ });
98
+
99
+ // The skipped branch has to hand back a module-level constant. Returning a
100
+ // fresh object would fail zustand's Object.is check and re-render on every
101
+ // store notification - the opposite of what skipping is for.
102
+ it("returns a stable reference across store updates", () => {
103
+ const { result } = renderModalStoreState(true);
104
+
105
+ const firstValue = result.current;
106
+
107
+ openModal();
108
+
109
+ // Asserted while the modal is open: dismissing resets the store to the
110
+ // very same initialModalState object, so an end-to-end round trip would
111
+ // hold this identity even for a live subscription.
112
+ expect(result.current).toBe(firstValue);
113
+
114
+ act(() => {
115
+ modalStore.getState().dismissModal();
116
+ });
117
+
118
+ expect(result.current).toBe(firstValue);
119
+ });
120
+ });
121
+
122
+ it("picks up the current modal state when it starts subscribing", () => {
123
+ let skipSubscription = true;
124
+
125
+ const { result, rerender } = renderHook(() =>
126
+ useModalStoreState(skipSubscription)
127
+ );
128
+
129
+ openModal();
130
+
131
+ expect(result.current.visible).toBe(false);
132
+
133
+ skipSubscription = false;
134
+
135
+ act(() => {
136
+ rerender(undefined);
137
+ });
138
+
139
+ expect(result.current.visible).toBe(true);
140
+ expect(result.current.screen).toBe(item);
141
+ });
142
+ });
@@ -25,6 +25,11 @@ export type {
25
25
  SelectionBehavior,
26
26
  } from "./types";
27
27
 
28
- export { isPresentSubMenuAction, OPERATIONS, hasOperation } from "./types";
28
+ export {
29
+ isPresentSubMenuAction,
30
+ getMenuItemActions,
31
+ OPERATIONS,
32
+ hasOperation,
33
+ } from "./types";
29
34
 
30
35
  export { useBottomSheetContent } from "./useBottomSheetContent";
@@ -98,5 +98,12 @@ export const openBottomSheetModal = ({
98
98
  });
99
99
  };
100
100
 
101
- export const useModalStoreState = (): ModalState =>
102
- useModalStore<ModalState>((state) => state.modalState);
101
+ /**
102
+ * Pass `skipSubscription` from callers that render outside of a modal: the
103
+ * selector then returns the stable `initialModalState` reference, so the
104
+ * component is never re-rendered by modal state it does not read.
105
+ */
106
+ export const useModalStoreState = (skipSubscription = false): ModalState =>
107
+ useModalStore<ModalState>((state) =>
108
+ skipSubscription ? initialModalState : state.modalState
109
+ );
@@ -37,8 +37,8 @@ export interface MenuItem {
37
37
  summary?: string;
38
38
  icon?: string;
39
39
  isSelected?: boolean;
40
- // When item represents an audio item, clicking on it will start playback
41
- // and secondary action will allow to add it to queue or playlist
40
+ actions?: (Action | PresentSubMenuAction)[];
41
+ /** @deprecated Use `actions` array instead. Maintained for backwards compatibility. */
42
42
  action?: Action | PresentSubMenuAction;
43
43
  secondaryAction?: SecondaryAction;
44
44
  trailingButton?: any;
@@ -118,6 +118,9 @@ export interface Content {
118
118
  dynamicCollection?: DynamicCollectionOptions;
119
119
  themePluginId?: string;
120
120
  styleOverrides?: Record<string, any>;
121
+ /** Shown under Next Up when the queue sheet has no upcoming items. */
122
+ emptyMessage?: string;
123
+ context?: Record<string, any>;
121
124
  }
122
125
 
123
126
  export interface Menu {
@@ -131,3 +134,29 @@ export function isPresentSubMenuAction(
131
134
  ): action is PresentSubMenuAction {
132
135
  return !!action && typeof action === "object" && "menu" in action;
133
136
  }
137
+
138
+ /**
139
+ * Normalizes an item's action/actions into an array of Action items.
140
+ * Supports canonical `actions: Action[]` and backwards-compatible `action: Action | Action[]`.
141
+ */
142
+ export function getMenuItemActions(
143
+ item?: Partial<MenuItem> | null
144
+ ): (Action | PresentSubMenuAction)[] {
145
+ if (!item) {
146
+ return [];
147
+ }
148
+
149
+ if (Array.isArray(item.actions) && item.actions.length > 0) {
150
+ return item.actions;
151
+ }
152
+
153
+ if (Array.isArray((item as any).action)) {
154
+ return (item as any).action;
155
+ }
156
+
157
+ if (item.action) {
158
+ return [item.action];
159
+ }
160
+
161
+ return [];
162
+ }
@@ -1,14 +1,15 @@
1
- import React, { useEffect, useState } from "react";
1
+ import React, { useCallback, useEffect, useState } from "react";
2
2
  import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
3
3
 
4
- import {
5
- isPresentSubMenuAction,
6
- MenuItem,
7
- modalOrchestrator,
8
- } from "./ModalOrchestrator";
4
+ import { MenuItem, modalOrchestrator } from "./ModalOrchestrator";
9
5
 
10
6
  import { ContentViewModel } from "./ContentViewModel";
11
- import type { DynamicCollectionOptions, SelectionBehavior } from "./types";
7
+ import {
8
+ DynamicCollectionOptions,
9
+ getMenuItemActions,
10
+ isPresentSubMenuAction,
11
+ SelectionBehavior,
12
+ } from "./types";
12
13
  import type { EditableCollection } from "./EditableCollection";
13
14
 
14
15
  type Props = {
@@ -44,7 +45,9 @@ export const useBottomSheetContent = (props: Props): Return => {
44
45
  // Subscribe to the viewModel state changes
45
46
  useEffect(() => {
46
47
  return viewModel?.subscribe((nextState) => {
47
- setState(nextState);
48
+ setState((state) => {
49
+ return state === nextState ? state : nextState;
50
+ });
48
51
  });
49
52
  }, [viewModel]);
50
53
 
@@ -64,15 +67,19 @@ export const useBottomSheetContent = (props: Props): Return => {
64
67
  * - If the item was a leaf action (not a submenu), triggers viewModel.refetch()
65
68
  * so that checkmarks (isSelected) reflect the updated server state.
66
69
  */
67
- const handleItemPress = async (item: MenuItem) => {
68
- const isSubMenu = item.action && isPresentSubMenuAction(item.action);
70
+ const handleItemPress = useCallback(
71
+ async (item: MenuItem) => {
72
+ const actions = getMenuItemActions(item);
73
+ const isSubMenu = actions.some(isPresentSubMenuAction);
69
74
 
70
- await onPress(item);
75
+ await onPress(item);
71
76
 
72
- if (!isSubMenu) {
73
- await viewModel?.refetch();
74
- }
75
- };
77
+ if (!isSubMenu) {
78
+ await viewModel?.refetch();
79
+ }
80
+ },
81
+ [onPress, viewModel]
82
+ );
76
83
 
77
84
  const goBackOrClose = React.useCallback(() => {
78
85
  if (modalOrchestrator.canGoBack) {
@@ -80,7 +87,7 @@ export const useBottomSheetContent = (props: Props): Return => {
80
87
  } else {
81
88
  modalOrchestrator.close();
82
89
  }
83
- }, [modalOrchestrator.canGoBack]);
90
+ }, []);
84
91
 
85
92
  return {
86
93
  items: viewModel?.editableCollection ? editableItems : state?.items,
@@ -92,7 +99,7 @@ export const useBottomSheetContent = (props: Props): Return => {
92
99
  canGoBack: modalOrchestrator.canGoBack,
93
100
  handleItemPress,
94
101
  goBackOrClose,
95
- close: () => modalOrchestrator.close(),
102
+ close: useCallback(() => modalOrchestrator.close(), []),
96
103
  role: state?.role,
97
104
  behavior: state?.behavior,
98
105
  dynamicCollection: state?.dynamicCollection,
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The app navigator for the X-Ray toolboxes (nav, screen), which run outside React. The
3
+ * NavigationProvider sets it after each commit; it is a plain module variable, so updating it
4
+ * never renders anything.
5
+ */
6
+ let navigator: QuickBrickAppNavigator | undefined;
7
+
8
+ export const setXrayNavigator = (value: QuickBrickAppNavigator | undefined) => {
9
+ navigator = value;
10
+ };
11
+
12
+ export const getXrayNavigator = () => navigator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "16.0.0-alpha.2024822855",
3
+ "version": "16.0.0-alpha.2105365027",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "16.0.0-alpha.2024822855",
30
+ "@applicaster/applicaster-types": "16.0.0-alpha.2105365027",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
package/perfTracker.ts ADDED
@@ -0,0 +1,203 @@
1
+ import { createLogger } from "./logger";
2
+ import { NativeModules } from "react-native";
3
+
4
+ const { ProfilerBridge } = NativeModules;
5
+
6
+ const loggerObj = createLogger({
7
+ category: "PerfTracker",
8
+ subsystem: "PerfTelemetry",
9
+ });
10
+
11
+ const renderCounts: Record<string, number> = {};
12
+ const cellRenderCounts: Record<string, number> = {};
13
+
14
+ const timingStats: Record<
15
+ string,
16
+ { totalMs: number; count: number; maxMs: number; minMs: number }
17
+ > = {};
18
+
19
+ const t0 = Date.now();
20
+
21
+ export function getDelta(): number {
22
+ return Date.now() - t0;
23
+ }
24
+
25
+ export function recordTiming(
26
+ name: string,
27
+ durationMs: number,
28
+ details?: Record<string, any>
29
+ ): void {
30
+ const rounded = Math.round(durationMs * 100) / 100;
31
+
32
+ if (!timingStats[name]) {
33
+ timingStats[name] = {
34
+ totalMs: rounded,
35
+ count: 1,
36
+ maxMs: rounded,
37
+ minMs: rounded,
38
+ };
39
+ } else {
40
+ const s = timingStats[name];
41
+ s.totalMs = Math.round((s.totalMs + rounded) * 100) / 100;
42
+ s.count += 1;
43
+ if (rounded > s.maxMs) s.maxMs = rounded;
44
+ if (rounded < s.minMs) s.minMs = rounded;
45
+ }
46
+
47
+ const stat = timingStats[name];
48
+ const avg = Math.round((stat.totalMs / stat.count) * 100) / 100;
49
+ const delta = getDelta();
50
+
51
+ if (ProfilerBridge?.updateTimer) {
52
+ try {
53
+ ProfilerBridge.updateTimer("timings", name, rounded);
54
+ } catch (e) {}
55
+ }
56
+
57
+ if (stat.count <= 3 || rounded >= 3 || stat.count % 10 === 0) {
58
+ const msg = `[PERF TIMING #${stat.count}] ${name}: ${rounded}ms (avg: ${avg}ms, max: ${stat.maxMs}ms, total: ${stat.totalMs}ms) (+${delta}ms)`;
59
+
60
+ loggerObj.log_info(msg, {
61
+ timingName: name,
62
+ durationMs: rounded,
63
+ avgMs: avg,
64
+ maxMs: stat.maxMs,
65
+ minMs: stat.minMs,
66
+ totalMs: stat.totalMs,
67
+ count: stat.count,
68
+ deltaMs: delta,
69
+ ...(details || {}),
70
+ });
71
+ }
72
+ }
73
+
74
+ export function measureSync<T>(
75
+ name: string,
76
+ fn: () => T,
77
+ details?: Record<string, any>
78
+ ): T {
79
+ const start =
80
+ typeof performance !== "undefined" && performance.now
81
+ ? performance.now()
82
+ : Date.now();
83
+
84
+ try {
85
+ return fn();
86
+ } finally {
87
+ const end =
88
+ typeof performance !== "undefined" && performance.now
89
+ ? performance.now()
90
+ : Date.now();
91
+
92
+ recordTiming(name, end - start, details);
93
+ }
94
+ }
95
+
96
+ export function startTimer(
97
+ name: string,
98
+ details?: Record<string, any>
99
+ ): (additionalDetails?: Record<string, any>) => number {
100
+ const start =
101
+ typeof performance !== "undefined" && performance.now
102
+ ? performance.now()
103
+ : Date.now();
104
+
105
+ return (additionalDetails?: Record<string, any>) => {
106
+ const end =
107
+ typeof performance !== "undefined" && performance.now
108
+ ? performance.now()
109
+ : Date.now();
110
+
111
+ const duration = end - start;
112
+
113
+ recordTiming(name, duration, {
114
+ ...(details || {}),
115
+ ...(additionalDetails || {}),
116
+ });
117
+
118
+ return duration;
119
+ };
120
+ }
121
+
122
+ export function countRender(
123
+ componentName: string,
124
+ details?: Record<string, any>
125
+ ): number {
126
+ renderCounts[componentName] = (renderCounts[componentName] || 0) + 1;
127
+ const count = renderCounts[componentName];
128
+ const delta = getDelta();
129
+
130
+ if (ProfilerBridge?.updateCounter) {
131
+ try {
132
+ ProfilerBridge.updateCounter("render_count", componentName, count);
133
+ } catch (e) {}
134
+ }
135
+
136
+ const msg = `[PERF RENDER #${count}] ${componentName} (+${delta}ms)`;
137
+
138
+ loggerObj.log_info(msg, {
139
+ component: componentName,
140
+ count,
141
+ deltaMs: delta,
142
+ ...(details || {}),
143
+ });
144
+
145
+ return count;
146
+ }
147
+
148
+ export function countCellRender(
149
+ cellType: string,
150
+ itemId: string | number,
151
+ details?: Record<string, any>
152
+ ): number {
153
+ const key = `${cellType}:${itemId || "unknown"}`;
154
+ cellRenderCounts[key] = (cellRenderCounts[key] || 0) + 1;
155
+ const count = cellRenderCounts[key];
156
+
157
+ renderCounts[cellType] = (renderCounts[cellType] || 0) + 1;
158
+ const totalForType = renderCounts[cellType];
159
+ const delta = getDelta();
160
+
161
+ if (ProfilerBridge?.updateCounter) {
162
+ try {
163
+ ProfilerBridge.updateCounter("cell_render_count", cellType, totalForType);
164
+ } catch (e) {}
165
+ }
166
+
167
+ if (count > 1 || totalForType <= 12 || totalForType % 10 === 0) {
168
+ const msg = `[PERF CELL ${
169
+ count > 1 ? "RE-RENDER" : "RENDER"
170
+ } #${count}] ${cellType} item:${itemId} (total ${cellType}: #${totalForType}) (+${delta}ms)`;
171
+
172
+ loggerObj.log_info(msg, {
173
+ cellType,
174
+ itemId,
175
+ itemRenderCount: count,
176
+ totalForCellType: totalForType,
177
+ deltaMs: delta,
178
+ ...(details || {}),
179
+ });
180
+ }
181
+
182
+ return count;
183
+ }
184
+
185
+ export function dumpSummary(checkpoint: string): void {
186
+ const delta = getDelta();
187
+ let totalRenders = 0;
188
+
189
+ for (const k in renderCounts) {
190
+ totalRenders += renderCounts[k];
191
+ }
192
+
193
+ const summaryMsg = `=== [PERF SUMMARY at ${checkpoint}] total renders: ${totalRenders} (+${delta}ms) ===`;
194
+
195
+ loggerObj.log_info(summaryMsg, {
196
+ checkpoint,
197
+ elapsedMs: delta,
198
+ totalRenders,
199
+ renderCounts,
200
+ cellRenderCounts,
201
+ timingStats,
202
+ });
203
+ }
@@ -0,0 +1,138 @@
1
+ import { resolvePlayerActions } from "../resolvePlayerActions";
2
+ import { selectActionButtons } from "../../conf/player/selectors";
3
+ import { uiActionsRegistry } from "../../uiActionsRegistrator";
4
+
5
+ jest.mock("../../conf/player/selectors", () => ({
6
+ selectActionButtons: jest.fn(),
7
+ }));
8
+
9
+ const action = (identifier: string) =>
10
+ ({ identifier, action: { invokeAction: jest.fn() } }) as any;
11
+
12
+ describe("resolvePlayerActions", () => {
13
+ const entry = {
14
+ id: "e1",
15
+ extensions: {
16
+ entry_action: [
17
+ { button: { alias: "add_to_playlist" }, actions: [{ type: "test" }] },
18
+ { button: { alias: "add_to_queue" }, actions: [{ type: "test" }] },
19
+ ],
20
+ },
21
+ };
22
+
23
+ // The entry's own actions never reach the registry; the caller expands them.
24
+ const expandEntryActions = jest.fn(() => [
25
+ action("entry_action_0"),
26
+ action("entry_action_1"),
27
+ ]);
28
+
29
+ beforeEach(() => {
30
+ expandEntryActions.mockClear();
31
+
32
+ jest
33
+ .spyOn(uiActionsRegistry, "getActions")
34
+ .mockImplementation((name) => [action(name)]);
35
+ });
36
+
37
+ afterEach(() => {
38
+ jest.restoreAllMocks();
39
+ });
40
+
41
+ it("expands entry_actions through the caller and keeps config order", () => {
42
+ (selectActionButtons as jest.Mock).mockReturnValue(
43
+ "entry_actions,local_storage_favourites_action,offline-content-button"
44
+ );
45
+
46
+ const result = resolvePlayerActions({
47
+ configuration: {},
48
+ entry,
49
+ expandEntryActions,
50
+ });
51
+
52
+ expect(expandEntryActions).toHaveBeenCalledWith(entry);
53
+
54
+ expect(uiActionsRegistry.getActions).not.toHaveBeenCalledWith(
55
+ "entry_actions",
56
+ entry
57
+ );
58
+
59
+ expect(result.map((item) => item.identifier)).toEqual([
60
+ "entry_action_0",
61
+ "entry_action_1",
62
+ "local_storage_favourites_action",
63
+ "offline-content-button",
64
+ ]);
65
+ });
66
+
67
+ it.each([undefined, null, ""])(
68
+ "resolves nothing when the config is %p",
69
+ (configured) => {
70
+ (selectActionButtons as jest.Mock).mockReturnValue(configured);
71
+
72
+ expect(
73
+ resolvePlayerActions({ configuration: {}, entry, expandEntryActions })
74
+ ).toEqual([]);
75
+ }
76
+ );
77
+
78
+ it("does not cap the resolved list at two items", () => {
79
+ (selectActionButtons as jest.Mock).mockReturnValue("a,b,c");
80
+
81
+ expect(
82
+ resolvePlayerActions({
83
+ configuration: {},
84
+ entry,
85
+ expandEntryActions,
86
+ }).map((item) => item.identifier)
87
+ ).toEqual(["a", "b", "c"]);
88
+ });
89
+
90
+ it("has no special case for any plugin identifier", () => {
91
+ (selectActionButtons as jest.Mock).mockReturnValue(
92
+ "open-modal-bottom-sheet-cell-action,local_storage_favourites_action"
93
+ );
94
+
95
+ expect(
96
+ resolvePlayerActions({
97
+ configuration: {},
98
+ entry,
99
+ expandEntryActions,
100
+ }).map((item) => item.identifier)
101
+ ).toEqual([
102
+ "open-modal-bottom-sheet-cell-action",
103
+ "local_storage_favourites_action",
104
+ ]);
105
+ });
106
+
107
+ it("collapses a repeated identifier in the config string", () => {
108
+ (selectActionButtons as jest.Mock).mockReturnValue(
109
+ "favorites,favorites,share"
110
+ );
111
+
112
+ expect(
113
+ resolvePlayerActions({
114
+ configuration: {},
115
+ entry,
116
+ expandEntryActions,
117
+ }).map((item) => item.identifier)
118
+ ).toEqual(["favorites", "share"]);
119
+ });
120
+
121
+ it("drops resolved items that cannot be invoked", () => {
122
+ (selectActionButtons as jest.Mock).mockReturnValue("broken,share");
123
+
124
+ (uiActionsRegistry.getActions as jest.Mock).mockImplementation((name) =>
125
+ name === "broken"
126
+ ? [{ identifier: "broken" } as any]
127
+ : [action(name as string)]
128
+ );
129
+
130
+ expect(
131
+ resolvePlayerActions({
132
+ configuration: {},
133
+ entry,
134
+ expandEntryActions,
135
+ }).map((item) => item.identifier)
136
+ ).toEqual(["share"]);
137
+ });
138
+ });
@@ -7,7 +7,23 @@ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
7
7
  import { getBoolFromConfigValue } from "../configurationUtils";
8
8
  import { Dimensions } from "react-native";
9
9
 
10
- export { getPlayerActionButtons } from "./getPlayerActionButtons";
10
+ export { resolvePlayerActions } from "./resolvePlayerActions";
11
+
12
+ export { isEntryAction } from "../entryActions";
13
+
14
+ export {
15
+ parseActionIdentifiers,
16
+ resolveActionIdentifiers,
17
+ } from "../uiActionsRegistrator";
18
+
19
+ export type { ResolveActionIdentifiersParams } from "../uiActionsRegistrator";
20
+
21
+ export type {
22
+ ActionButtonDescriptor,
23
+ OverflowDescriptor,
24
+ PlayerControlDescriptor,
25
+ ResolvePlayerActionsParams,
26
+ } from "./resolvePlayerActions";
11
27
 
12
28
  export {
13
29
  resolvePlayerContentText,