@applicaster/zapp-react-native-utils 16.0.0-alpha.8154281859 → 16.0.0-alpha.8225069933

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 (172) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/ActionExecutor.ts +50 -3
  3. package/actionsExecutor/ActionExecutorContext.tsx +99 -17
  4. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  5. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  6. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
  7. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  8. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  9. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  10. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +267 -0
  11. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +100 -0
  12. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +300 -0
  13. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  14. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  15. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  16. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  17. package/actionsExecutor/actions/goBack.ts +60 -0
  18. package/actionsExecutor/actions/goHome.ts +31 -0
  19. package/actionsExecutor/actions/index.ts +12 -0
  20. package/actionsExecutor/actions/navigateToScreen.ts +43 -45
  21. package/actionsExecutor/actions/openBottomSheet.ts +339 -0
  22. package/actionsExecutor/actions/presentScreen.ts +78 -0
  23. package/actionsExecutor/actions/refreshComponent.ts +6 -0
  24. package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
  25. package/actionsExecutor/actions/showAlert.ts +51 -0
  26. package/actionsExecutor/actions/showToast.ts +64 -8
  27. package/actionsExecutor/consts.ts +27 -0
  28. package/actionsExecutor/feedDecorator.ts +6 -6
  29. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  30. package/appUtils/HooksManager/index.ts +9 -0
  31. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
  32. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  33. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  34. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  35. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  36. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  37. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  38. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  39. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  40. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  41. package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
  42. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  43. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  44. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  45. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
  46. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  47. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  48. package/appUtils/playerManager/{conts.ts → const.ts} +33 -0
  49. package/appUtils/playerManager/index.ts +8 -1
  50. package/appUtils/playerManager/player.ts +140 -3
  51. package/appUtils/playerManager/playerFactory.ts +1 -1
  52. package/appUtils/playerManager/playerNative.ts +28 -4
  53. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  54. package/appUtils/playerManager/playerToolbox.ts +196 -0
  55. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  56. package/appUtils/playerManager/usePlayerControllerSetup.tsx +7 -1
  57. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  58. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  59. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  60. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  61. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  62. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  63. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  64. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  65. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  66. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  67. package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
  68. package/arrayUtils/__tests__/sample.test.ts +61 -0
  69. package/arrayUtils/index.ts +119 -20
  70. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  71. package/bottomSheet/index.ts +17 -0
  72. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  73. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  74. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  75. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  76. package/cellUtils/index.ts +70 -3
  77. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  78. package/configurationUtils/__tests__/modalBlocksParser.test.ts +392 -0
  79. package/configurationUtils/manifestKeyParser.ts +50 -10
  80. package/configurationUtils/modalBlocksParser.ts +252 -0
  81. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  82. package/entryActions/aliasPresentation.ts +108 -0
  83. package/entryActions/buildEntryActions.ts +167 -0
  84. package/entryActions/index.ts +15 -0
  85. package/entryActions/types.ts +39 -0
  86. package/focusManager/FocusManager.ts +26 -0
  87. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  88. package/localizationUtils/index.ts +12 -6
  89. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  90. package/logger/xrayToolbox.ts +67 -0
  91. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  92. package/manifestUtils/_internals/index.js +8 -3
  93. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  94. package/manifestUtils/defaultManifestConfigurations/player.js +342 -5
  95. package/manifestUtils/index.js +3 -0
  96. package/manifestUtils/keys.js +7 -2
  97. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  98. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  99. package/manifestUtils/mobileAction/groups/defaults.js +2 -1
  100. package/manifestUtils/modalBlocks.js +304 -0
  101. package/modalState/ContentViewModel.ts +113 -0
  102. package/modalState/EditableCollection.ts +17 -0
  103. package/modalState/EditableCollectionRegistry.ts +51 -0
  104. package/modalState/ModalOrchestrator.ts +212 -0
  105. package/modalState/RemoteEditableCollection.ts +235 -0
  106. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  107. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  108. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  109. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +63 -0
  110. package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
  111. package/modalState/__tests__/index.test.ts +30 -1
  112. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  113. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  114. package/modalState/index.ts +35 -83
  115. package/modalState/store.ts +109 -0
  116. package/modalState/types.ts +162 -0
  117. package/modalState/useBottomSheetContent.ts +109 -0
  118. package/navigationUtils/xrayNavigator.ts +12 -0
  119. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  120. package/numberUtils/__tests__/isZero.test.ts +27 -0
  121. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  122. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  123. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  124. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  125. package/numberUtils/index.ts +27 -8
  126. package/package.json +3 -2
  127. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  128. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  129. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  130. package/playerUtils/contentDataKeys.ts +134 -0
  131. package/playerUtils/index.ts +37 -16
  132. package/playerUtils/isAudioItem.ts +26 -0
  133. package/playerUtils/resolvePlayerActions.ts +71 -0
  134. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  135. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  136. package/pluginUtils/index.ts +29 -0
  137. package/quickBrickAssets/__tests__/index.test.ts +18 -0
  138. package/quickBrickAssets/index.ts +35 -0
  139. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  140. package/reactHooks/actions/index.ts +74 -3
  141. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  142. package/reactHooks/cell-click/index.ts +21 -14
  143. package/reactHooks/connection/index.tsx +8 -5
  144. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  145. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  146. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  147. package/reactHooks/index.ts +2 -0
  148. package/reactHooks/layout/index.ts +1 -1
  149. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  150. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  151. package/reactHooks/navigation/index.ts +2 -0
  152. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  153. package/reactHooks/navigation/useRoute.ts +22 -5
  154. package/reactHooks/usePluginConfiguration.ts +88 -47
  155. package/reactHooks/utils/__tests__/index.test.js +22 -2
  156. package/reactHooks/utils/index.ts +11 -1
  157. package/riverComponetsMeasurementProvider/index.tsx +3 -1
  158. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  159. package/stringUtils/index.ts +2 -2
  160. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  161. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  162. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  163. package/uiActionsRegistrator/index.ts +25 -203
  164. package/uiActionsRegistrator/registry.ts +351 -0
  165. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  166. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  167. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  168. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  169. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  170. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  171. package/playerUtils/getPlayerActionButtons.ts +0 -17
  172. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -6,6 +6,7 @@ import { ActionsContext } from "@applicaster/zapp-react-native-ui-components/Con
6
6
  import {
7
7
  observeEntryState,
8
8
  RegisteredActionValue,
9
+ uiActionsRegistry,
9
10
  } from "../../uiActionsRegistrator";
10
11
  import { reactHooksLogger } from "../logger";
11
12
 
@@ -20,21 +21,55 @@ type ActionContexts<T = unknown> = {
20
21
  };
21
22
 
22
23
  /**
23
- * React Hook to subscribe to the custom action context
24
+ * A value that changes whenever a provider is added to or removed from
25
+ * `uiActionsRegistry`.
26
+ *
27
+ * Providers can register after the UI that wants them has rendered - the audio
28
+ * player registers playback speed only once its controller has state, and
29
+ * plugin-backed actions are bridged in from an effect. Put this in the
30
+ * dependency list of anything that resolves actions, so the list is re-read
31
+ * instead of being frozen at first paint.
32
+ */
33
+ export function useRegistryRevision(): number {
34
+ const [revision, setRevision] = useState(0);
35
+
36
+ useEffect(
37
+ () =>
38
+ uiActionsRegistry.subscribe(() => setRevision((current) => current + 1)),
39
+ []
40
+ );
41
+
42
+ return revision;
43
+ }
44
+
45
+ /**
46
+ * Resolves a legacy action context or falls back to the UI action registry.
24
47
  * @param {*} plugId - subscribes to the context of that action plugin
25
48
  * @return {*} - global action provider context or context for specific action plugin
26
49
  */
27
50
  export function useActions<T = unknown>(plugId: string): any {
28
51
  const [logged, setLogged] = useState(false);
29
52
  const context = useContext<ActionContexts<T>>(ActionsContext);
53
+ useRegistryRevision();
54
+
30
55
  const actionContext = context?.actions?.[plugId]?.module?.context;
31
56
 
32
57
  if (plugId) {
33
58
  if (!actionContext) {
59
+ const registeredAction = uiActionsRegistry.getAction(plugId);
60
+
61
+ if (registeredAction) return registeredAction;
62
+
34
63
  if (!logged) {
35
64
  logger.warning({
36
65
  message: `useActions: Couldn't find an action for ${plugId} plugin`,
37
- data: { actions: context?.actions },
66
+ // Identifiers only. The action map holds every plugin's module and
67
+ // live React context, which is far too large for a log line and can
68
+ // carry whatever state those plugins hold.
69
+ data: {
70
+ plugId,
71
+ availableActions: Object.keys(context?.actions ?? {}),
72
+ },
38
73
  });
39
74
 
40
75
  setLogged(true);
@@ -80,7 +115,31 @@ export function useEntryActionState(
80
115
  useEffect(() => {
81
116
  if (!action) return undefined;
82
117
 
83
- const subscription = observeEntryState(action, entry).subscribe(setState);
118
+ // An action's stream is third-party code. Subscribing with only a `next`
119
+ // handler lets RxJS rethrow an error notification asynchronously, where no
120
+ // error boundary catches it - one plugin faulting would take the app down
121
+ // rather than this one button. The button keeps its last known state.
122
+ let subscription;
123
+
124
+ try {
125
+ subscription = observeEntryState(action, entry).subscribe({
126
+ next: setState,
127
+ error: (error) =>
128
+ logger.warning({
129
+ message:
130
+ "useEntryActionState: the action's state stream failed - the button keeps its last state",
131
+ data: { entryId, error },
132
+ }),
133
+ });
134
+ } catch (error) {
135
+ logger.warning({
136
+ message:
137
+ "useEntryActionState: could not observe the action - the button keeps its initial state",
138
+ data: { entryId, error },
139
+ });
140
+
141
+ return undefined;
142
+ }
84
143
 
85
144
  return () => subscription.unsubscribe();
86
145
  // eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
@@ -88,6 +147,18 @@ export function useEntryActionState(
88
147
 
89
148
  const invokeAction = useCallback(
90
149
  (options: InvokeArgsOptions = {}) => {
150
+ if (typeof action?.invokeAction !== "function") {
151
+ // A button was rendered and pressed, and the press goes nowhere. Only
152
+ // reachable on a user interaction, so it costs nothing on render. The
153
+ // action value carries no identifier, so the label is what locates the
154
+ // button that misbehaved.
155
+ logger.warning({
156
+ message:
157
+ "useEntryActionState: the pressed action has no invokeAction - the press did nothing",
158
+ data: { entryId, label: state?.label },
159
+ });
160
+ }
161
+
91
162
  action?.invokeAction?.(entry, { updateState: setState, ...options });
92
163
  },
93
164
  // eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
@@ -5,6 +5,7 @@ import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/acti
5
5
 
6
6
  const mockNavigator = {
7
7
  getPathname: () => "pathnameMock",
8
+ currentRoute: "pathnameMock",
8
9
  push: jest.fn(),
9
10
  data: {},
10
11
  };
@@ -29,6 +30,7 @@ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
29
30
  ),
30
31
  useTargetScreenData: jest.fn(() => ({})),
31
32
  useCurrentScreenData: jest.fn(() => ({})),
33
+ useScreenContext: jest.fn(() => ({})),
32
34
  }));
33
35
 
34
36
  jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
@@ -66,6 +68,12 @@ const wrapper = ({ children }) => (
66
68
  </CellTapContext.Provider>
67
69
  );
68
70
 
71
+ const actionExecutorWrapper = ({ children }) => (
72
+ <ActionExecutorContext.Provider value={actionExecutor}>
73
+ {children}
74
+ </ActionExecutorContext.Provider>
75
+ );
76
+
69
77
  describe("useCellClick", () => {
70
78
  it("returns a function", () => {
71
79
  const { result } = renderHook(() => useCellClick(mockProps));
@@ -95,4 +103,60 @@ describe("useCellClick", () => {
95
103
 
96
104
  cleanup();
97
105
  });
106
+
107
+ it("does not push when the cell finishes a hook", async () => {
108
+ mockNavigator.push.mockClear();
109
+
110
+ const item = {
111
+ id: "profile-1",
112
+ type: { value: "feed" },
113
+ extensions: {
114
+ tap_actions: {
115
+ actions: [
116
+ { type: "sessionStorageSet" },
117
+ { type: "finishHook", options: { success: true } },
118
+ ],
119
+ },
120
+ },
121
+ };
122
+
123
+ const { result } = renderHook(() => useCellClick({ item }), {
124
+ wrapper: actionExecutorWrapper,
125
+ });
126
+
127
+ await result.current();
128
+
129
+ await waitFor(() => {
130
+ expect(actionExecutor.handleEntryActions).toHaveBeenCalled();
131
+ });
132
+
133
+ expect(mockNavigator.push).not.toHaveBeenCalled();
134
+ cleanup();
135
+ });
136
+
137
+ it("pushes after tap actions that do not finish a hook", async () => {
138
+ mockNavigator.push.mockClear();
139
+
140
+ const item = {
141
+ id: "episode-1",
142
+ type: { value: "feed" },
143
+ extensions: {
144
+ tap_actions: {
145
+ actions: [{ type: "sessionStorageSet" }],
146
+ },
147
+ },
148
+ };
149
+
150
+ const { result } = renderHook(() => useCellClick({ item }), {
151
+ wrapper: actionExecutorWrapper,
152
+ });
153
+
154
+ await result.current();
155
+
156
+ await waitFor(() => {
157
+ expect(mockNavigator.push).toHaveBeenCalled();
158
+ });
159
+
160
+ cleanup();
161
+ });
98
162
  });
@@ -83,6 +83,12 @@ export const useCellClick = ({
83
83
 
84
84
  logOnPress(selectedItem, pathname, component, onCellTap);
85
85
 
86
+ const tapActions = selectedItem?.extensions?.tap_actions?.actions;
87
+
88
+ const finishesHook =
89
+ Array.isArray(tapActions) &&
90
+ tapActions.some((action) => action?.type === "finishHook");
91
+
86
92
  if (selectedItem) {
87
93
  await actionExecutor?.handleEntryActions(selectedItem, {
88
94
  component,
@@ -101,20 +107,21 @@ export const useCellClick = ({
101
107
  url: selectedItem.link.href,
102
108
  });
103
109
  }
104
- } else {
105
- if (isFunction(onCellTap)) {
106
- onCellTap?.(selectedItem, _index);
107
- } else {
108
- if (currentRoute === pathname || pathname.includes("video-modal")) {
109
- const targetScreen = component?.data?.target;
110
-
111
- push(
112
- R.when(
113
- () => targetScreen,
114
- R.mergeLeft({ screen_type: targetScreen })
115
- )(selectedItem)
116
- );
117
- }
110
+ } else if (isFunction(onCellTap)) {
111
+ onCellTap?.(selectedItem, _index);
112
+ } else if (!finishesHook) {
113
+ // finishHook already completes the hook and navigates to the original
114
+ // target. Pushing the cell as well stacks a second copy of that screen
115
+ // (e.g. home/home after a profile selector hook).
116
+ if (currentRoute === pathname || pathname.includes("video-modal")) {
117
+ const targetScreen = component?.data?.target;
118
+
119
+ push(
120
+ R.when(
121
+ () => targetScreen,
122
+ R.mergeLeft({ screen_type: targetScreen })
123
+ )(selectedItem)
124
+ );
118
125
  }
119
126
  }
120
127
  },
@@ -4,6 +4,11 @@ import { NetInfoState } from "@react-native-community/netinfo";
4
4
  import { NetworkStatusContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NetworkStatusContext";
5
5
  import { isOnline } from "@applicaster/quick-brick-core/App/NetworkStatusProvider/utils";
6
6
 
7
+ type ConnectionInfo = NetInfoState & {
8
+ deviceStatus: NetStatus;
9
+ stillOfflineAfterResumeCount?: number;
10
+ };
11
+
7
12
  /**
8
13
  * This hook returns connection type from RN NetInfo component or boolean for iConnected if justOnlineStatus flag is set
9
14
  * @param {boolean} justOnlineStatus - flag if to return boolean for isConnected
@@ -12,16 +17,14 @@ import { isOnline } from "@applicaster/quick-brick-core/App/NetworkStatusProvide
12
17
 
13
18
  export function useConnectionInfo(justOnlineStatus: true): boolean;
14
19
 
15
- export function useConnectionInfo(
16
- justOnlineStatus: false
17
- ): NetInfoState & { deviceStatus: NetStatus };
20
+ export function useConnectionInfo(justOnlineStatus: false): ConnectionInfo;
18
21
 
19
22
  export function useConnectionInfo(
20
23
  justOnlineStatus: boolean
21
- ): boolean | (NetInfoState & { deviceStatus: NetStatus }) {
24
+ ): boolean | ConnectionInfo {
22
25
  const connectionInfo = React.useContext(
23
26
  NetworkStatusContext
24
- ) as NetInfoState & { deviceStatus: NetStatus };
27
+ ) as ConnectionInfo;
25
28
 
26
29
  return justOnlineStatus ? isOnline(connectionInfo) === true : connectionInfo;
27
30
  }
@@ -242,4 +242,29 @@ describe("useGetUrlInflater", () => {
242
242
  const url = result.current(source, mapping);
243
243
  expect(url).toBe("https://foo.com/shows/A123?q=user%20query");
244
244
  });
245
+
246
+ it("handles search queries with apostrophes without HTML entity escaping or URL truncation", () => {
247
+ const source =
248
+ "https://api.pc-cms.tele.quebec/api/applicaster/v1/mobile/search?q={{q}}";
249
+
250
+ const mapping = {
251
+ q: { source: "search", property: "q" },
252
+ };
253
+
254
+ const searchContext = getSearchContext("L'aventure", mapping);
255
+
256
+ const result = getInflatedDataSourceUrl({
257
+ source,
258
+ contexts: {
259
+ search: searchContext,
260
+ },
261
+ mapping,
262
+ });
263
+
264
+ expect(result).toBe(
265
+ "https://api.pc-cms.tele.quebec/api/applicaster/v1/mobile/search?q=L'aventure"
266
+ );
267
+
268
+ expect(result).not.toContain("&#x27;");
269
+ });
245
270
  });
@@ -0,0 +1,243 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+ import * as zappPipesModule from "@applicaster/zapp-react-native-redux/ZappPipes";
3
+ import * as useRouteHook from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useRoute";
4
+ import * as useNavigationHooks from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
5
+ import * as useIsScreenActiveHook from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useIsScreenActive";
6
+ import { refreshCoordinator } from "../../../refreshUtils/RefreshCoordinator";
7
+ import { useMarkPipesDataStale } from "../useMarkPipesDataStale";
8
+
9
+ const mockDispatch = jest.fn();
10
+
11
+ jest.mock("@applicaster/zapp-react-native-redux", () => ({
12
+ ...jest.requireActual("@applicaster/zapp-react-native-redux"),
13
+ useAppDispatch: () => mockDispatch,
14
+ }));
15
+
16
+ jest.mock(
17
+ "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/getDatasourceUrl",
18
+ () => ({
19
+ getDatasourceUrl: jest.fn(
20
+ (_ctx, component) => component?.data?.source || null
21
+ ),
22
+ })
23
+ );
24
+
25
+ jest.mock(
26
+ "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/usePipesContexts",
27
+ () => ({
28
+ usePipesContexts: jest.fn(() => ({})),
29
+ })
30
+ );
31
+
32
+ describe("useMarkPipesDataStale", () => {
33
+ let mockNavigator: any;
34
+ let mockRoute: any;
35
+ let mockIsActive: boolean;
36
+
37
+ const riverId = "river-123";
38
+
39
+ const refreshableComponent: any = {
40
+ id: "comp-1",
41
+ rules: { clear_cache_on_reload: true },
42
+ data: { source: "https://feed.example.com/data1" },
43
+ };
44
+
45
+ const stringBooleanComponent: any = {
46
+ id: "comp-2",
47
+ rules: { clear_cache_on_reload: "true" },
48
+ data: { source: "https://feed.example.com/data2" },
49
+ };
50
+
51
+ const nonRefreshableComponent: any = {
52
+ id: "comp-3",
53
+ rules: { clear_cache_on_reload: false },
54
+ data: { source: "https://feed.example.com/data3" },
55
+ };
56
+
57
+ const noSourceComponent: any = {
58
+ id: "comp-4",
59
+ rules: { clear_cache_on_reload: true },
60
+ };
61
+
62
+ const allComponents = [
63
+ refreshableComponent,
64
+ stringBooleanComponent,
65
+ nonRefreshableComponent,
66
+ noSourceComponent,
67
+ ];
68
+
69
+ beforeEach(() => {
70
+ jest.clearAllMocks();
71
+
72
+ mockIsActive = true;
73
+
74
+ mockNavigator = {
75
+ currentRoute: "river/river-123",
76
+ };
77
+
78
+ mockRoute = {
79
+ pathname: "river/river-123",
80
+ screenData: { id: riverId },
81
+ };
82
+
83
+ jest
84
+ .spyOn(useNavigationHooks, "useNavigation")
85
+ .mockImplementation(() => mockNavigator);
86
+
87
+ jest.spyOn(useRouteHook, "useRoute").mockImplementation(() => mockRoute);
88
+
89
+ jest
90
+ .spyOn(useIsScreenActiveHook, "useIsScreenActive")
91
+ .mockImplementation(() => mockIsActive);
92
+
93
+ jest
94
+ .spyOn(refreshCoordinator, "triggerRefresh")
95
+ .mockImplementation(jest.fn());
96
+
97
+ jest
98
+ .spyOn(zappPipesModule, "markPipesDataStale")
99
+ .mockImplementation(
100
+ (url, opts) => ({ type: "MARK_STALE", url, opts }) as any
101
+ );
102
+ });
103
+
104
+ describe("on unmount", () => {
105
+ it("marks clear_cache_on_reload feeds stale on unmount", () => {
106
+ const { unmount } = renderHook(() =>
107
+ useMarkPipesDataStale(riverId, allComponents)
108
+ );
109
+
110
+ expect(mockDispatch).not.toHaveBeenCalled();
111
+
112
+ unmount();
113
+
114
+ expect(zappPipesModule.markPipesDataStale).toHaveBeenCalledWith(
115
+ "https://feed.example.com/data1",
116
+ { riverId }
117
+ );
118
+
119
+ expect(zappPipesModule.markPipesDataStale).toHaveBeenCalledWith(
120
+ "https://feed.example.com/data2",
121
+ { riverId }
122
+ );
123
+
124
+ expect(zappPipesModule.markPipesDataStale).not.toHaveBeenCalledWith(
125
+ "https://feed.example.com/data3",
126
+ expect.anything()
127
+ );
128
+
129
+ expect(mockDispatch).toHaveBeenCalledTimes(2);
130
+ });
131
+
132
+ it("does not mark stale on unmount if pathname includes videoModal", () => {
133
+ mockRoute.pathname = "videoModal/item-123";
134
+
135
+ const { unmount } = renderHook(() =>
136
+ useMarkPipesDataStale(riverId, allComponents)
137
+ );
138
+
139
+ unmount();
140
+
141
+ expect(mockDispatch).not.toHaveBeenCalled();
142
+ });
143
+ });
144
+
145
+ describe("on screen return (screen not unmounted in Transitioner)", () => {
146
+ it("does not trigger refresh on initial mount", () => {
147
+ renderHook(() => useMarkPipesDataStale(riverId, allComponents));
148
+
149
+ expect(refreshCoordinator.triggerRefresh).not.toHaveBeenCalled();
150
+ expect(mockDispatch).not.toHaveBeenCalled();
151
+ });
152
+
153
+ it("triggers refresh and marks stale when returning from a deeper screen", () => {
154
+ const { rerender } = renderHook(() =>
155
+ useMarkPipesDataStale(riverId, allComponents)
156
+ );
157
+
158
+ // 1. User navigates away to a deeper screen
159
+ mockNavigator.currentRoute = "river/deeper-screen";
160
+ mockIsActive = false;
161
+ rerender({});
162
+
163
+ expect(refreshCoordinator.triggerRefresh).not.toHaveBeenCalled();
164
+ expect(mockDispatch).not.toHaveBeenCalled();
165
+
166
+ // 2. User presses back and returns to original screen
167
+ mockNavigator.currentRoute = "river/river-123";
168
+ mockIsActive = true;
169
+ rerender({});
170
+
171
+ expect(refreshCoordinator.triggerRefresh).toHaveBeenCalledTimes(1);
172
+
173
+ expect(refreshCoordinator.triggerRefresh).toHaveBeenCalledWith(
174
+ [refreshableComponent, stringBooleanComponent],
175
+ riverId
176
+ );
177
+
178
+ expect(zappPipesModule.markPipesDataStale).toHaveBeenCalledWith(
179
+ "https://feed.example.com/data1",
180
+ { riverId }
181
+ );
182
+
183
+ expect(zappPipesModule.markPipesDataStale).toHaveBeenCalledWith(
184
+ "https://feed.example.com/data2",
185
+ { riverId }
186
+ );
187
+
188
+ expect(mockDispatch).toHaveBeenCalledTimes(2);
189
+ });
190
+
191
+ it("does not trigger duplicate refreshes on subsequent re-renders on the same screen", () => {
192
+ const { rerender } = renderHook(() =>
193
+ useMarkPipesDataStale(riverId, allComponents)
194
+ );
195
+
196
+ // Navigate away
197
+ mockNavigator.currentRoute = "river/deeper-screen";
198
+ mockIsActive = false;
199
+ rerender({});
200
+
201
+ // Return
202
+ mockNavigator.currentRoute = "river/river-123";
203
+ mockIsActive = true;
204
+ rerender({});
205
+
206
+ expect(refreshCoordinator.triggerRefresh).toHaveBeenCalledTimes(1);
207
+
208
+ // Subsequent re-render without navigation
209
+ rerender({});
210
+ rerender({});
211
+
212
+ expect(refreshCoordinator.triggerRefresh).toHaveBeenCalledTimes(1);
213
+ });
214
+
215
+ it("triggers refresh again if user navigates away a second time and returns", () => {
216
+ const { rerender } = renderHook(() =>
217
+ useMarkPipesDataStale(riverId, allComponents)
218
+ );
219
+
220
+ // First trip: navigate away and return
221
+ mockNavigator.currentRoute = "river/screen-2";
222
+ mockIsActive = false;
223
+ rerender({});
224
+
225
+ mockNavigator.currentRoute = "river/river-123";
226
+ mockIsActive = true;
227
+ rerender({});
228
+
229
+ expect(refreshCoordinator.triggerRefresh).toHaveBeenCalledTimes(1);
230
+
231
+ // Second trip: navigate away to another screen and return
232
+ mockNavigator.currentRoute = "river/screen-3";
233
+ mockIsActive = false;
234
+ rerender({});
235
+
236
+ mockNavigator.currentRoute = "river/river-123";
237
+ mockIsActive = true;
238
+ rerender({});
239
+
240
+ expect(refreshCoordinator.triggerRefresh).toHaveBeenCalledTimes(2);
241
+ });
242
+ });
243
+ });
@@ -3,46 +3,91 @@ import React from "react";
3
3
  import { getDatasourceUrl } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/getDatasourceUrl";
4
4
  import { usePipesContexts } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/usePipesContexts";
5
5
  import { markPipesDataStale } from "@applicaster/zapp-react-native-redux/ZappPipes";
6
-
7
- import { useRoute } from "../navigation";
8
6
  import { useAppDispatch } from "@applicaster/zapp-react-native-redux";
7
+ import { isTrue } from "../../booleanUtils";
8
+ import { refreshCoordinator } from "../../refreshUtils/RefreshCoordinator";
9
+ import { useNavigation, useRoute } from "../navigation";
10
+ import { usePrevious } from "../utils";
11
+
12
+ const getRefreshableComponents = (components: ZappUIComponent[]) =>
13
+ components?.filter(
14
+ (c) => isTrue(c?.rules?.clear_cache_on_reload) && c?.data?.source
15
+ ) || [];
9
16
 
10
17
  /**
11
18
  * Mark a river's `clear_cache_on_reload` feeds as stale when the screen is
12
19
  * unmounted. The cached data is kept (so a screen sharing the same feed does
13
20
  * not lose it mid-mount) and revalidated on next access.
21
+ *
22
+ * Also triggers refresh for mounted components and marks feeds stale when
23
+ * returning back to this screen from a deeper route in the Transitioner
24
+ * (where the screen was kept mounted in the background).
25
+ *
14
26
  * @param {string} riverId screen id
15
27
  * @param {Array} riverComponents list of UI components
16
28
  */
17
- export const useMarkPipesDataStale = (riverId, riverComponents) => {
29
+ export const useMarkPipesDataStale = (
30
+ riverId: string,
31
+ riverComponents: ZappUIComponent[]
32
+ ) => {
18
33
  const dispatch = useAppDispatch();
19
34
  const { screenData, pathname } = useRoute();
20
35
  const pipesContexts = usePipesContexts(riverId, pathname);
36
+ const { currentRoute } = useNavigation();
37
+ const prevRoute = usePrevious(currentRoute);
21
38
 
22
- React.useEffect(() => {
23
- return () => {
24
- riverComponents.forEach((component) => {
25
- if (
26
- component?.rules?.clear_cache_on_reload &&
27
- component?.data?.source &&
28
- // We don't want to refresh cache when closing/minimising videoModal
29
- !pathname.includes("videoModal")
30
- ) {
31
- const url = getDatasourceUrl(
32
- {
33
- screenData,
34
- ...pipesContexts,
35
- },
36
- component
37
- );
38
-
39
- if (url) {
40
- dispatch(markPipesDataStale(url, { riverId }));
41
- }
39
+ const isBackToScreen = Boolean(
40
+ prevRoute && prevRoute !== currentRoute && currentRoute === pathname
41
+ );
42
+
43
+ const invalidateComponents = React.useCallback(
44
+ (components: ZappUIComponent[]) => {
45
+ components.forEach((component) => {
46
+ const url = getDatasourceUrl(
47
+ { screenData, ...pipesContexts },
48
+ component
49
+ );
50
+
51
+ if (url) {
52
+ dispatch(markPipesDataStale(url, { riverId }));
42
53
  }
43
54
  });
55
+ },
56
+ [dispatch, screenData, pipesContexts, riverId]
57
+ );
58
+
59
+ // Stale invalidation on unmount (existing behavior)
60
+ /* eslint-disable @wogns3623/better-exhaustive-deps/exhaustive-deps */
61
+ React.useEffect(() => {
62
+ return () => {
63
+ if (pathname?.includes("videoModal")) return;
64
+
65
+ invalidateComponents(getRefreshableComponents(riverComponents));
44
66
  };
45
67
  }, []);
68
+ /* eslint-enable @wogns3623/better-exhaustive-deps/exhaustive-deps */
69
+
70
+ // Reload when returning back to this screen from another screen
71
+ React.useEffect(() => {
72
+ if (!isBackToScreen || pathname?.includes("videoModal")) {
73
+ return;
74
+ }
75
+
76
+ const refreshable = getRefreshableComponents(riverComponents);
77
+
78
+ if (refreshable.length === 0) {
79
+ return;
80
+ }
81
+
82
+ invalidateComponents(refreshable);
83
+ refreshCoordinator.triggerRefresh(refreshable, riverId);
84
+ }, [
85
+ isBackToScreen,
86
+ pathname,
87
+ riverComponents,
88
+ riverId,
89
+ invalidateComponents,
90
+ ]);
46
91
  };
47
92
 
48
93
  /**
@@ -17,3 +17,5 @@ export * from "./screen";
17
17
  export * from "./state";
18
18
 
19
19
  export * from "./events";
20
+
21
+ export * from "./utils";
@@ -49,7 +49,7 @@ export function useStatusBarHeight() {
49
49
  });
50
50
  }
51
51
 
52
- const getNavbarHeight = () => {
52
+ export const getNavbarHeight = () => {
53
53
  return isTV() ? 60 : platformSelect({ ios: 44, android: 56 });
54
54
  };
55
55