@applicaster/zapp-react-native-utils 16.0.0-alpha.4115436491 → 16.0.0-alpha.4182314481

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 (197) hide show
  1. package/actionsExecutor/ActionExecutor.ts +47 -11
  2. package/actionsExecutor/ActionExecutorContext.tsx +111 -315
  3. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  4. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
  5. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  6. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  7. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  8. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
  9. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
  10. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +212 -0
  11. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  12. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  13. package/actionsExecutor/actions/appRestart.ts +24 -0
  14. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  15. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  16. package/actionsExecutor/actions/goBack.ts +60 -0
  17. package/actionsExecutor/actions/goHome.ts +31 -0
  18. package/actionsExecutor/actions/index.ts +40 -0
  19. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  20. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  21. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  22. package/actionsExecutor/actions/navigateToScreen.ts +137 -0
  23. package/actionsExecutor/actions/openBottomSheet.ts +325 -0
  24. package/actionsExecutor/actions/presentScreen.ts +78 -0
  25. package/actionsExecutor/actions/refreshComponent.ts +85 -0
  26. package/actionsExecutor/actions/screenSetVariable.ts +35 -0
  27. package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
  28. package/actionsExecutor/actions/sendCloudEvent.ts +93 -0
  29. package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
  30. package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
  31. package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
  32. package/actionsExecutor/actions/showToast.ts +87 -0
  33. package/actionsExecutor/actions/switchLayout.ts +40 -0
  34. package/actionsExecutor/consts.ts +26 -0
  35. package/actionsExecutor/feedDecorator.ts +6 -6
  36. package/actionsExecutor/types.ts +59 -0
  37. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
  38. package/analyticsUtils/PlayerAnalyticsManager.ts +12 -2
  39. package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
  40. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
  41. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
  42. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
  43. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
  44. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
  45. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
  46. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
  47. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
  48. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
  49. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
  50. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
  51. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
  52. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
  53. package/analyticsUtils/__tests__/fixtures/index.js +20 -0
  54. package/analyticsUtils/analyticsMapper.ts +4 -1
  55. package/analyticsUtils/playerAnalyticsTracker.ts +26 -3
  56. package/appUtils/HooksManager/index.ts +12 -8
  57. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
  58. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
  59. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  60. package/appUtils/contextKeysManager/index.ts +1 -1
  61. package/appUtils/contextKeysManager/utils/index.ts +38 -25
  62. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -53
  63. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  64. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +49 -0
  65. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  66. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  67. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
  68. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  69. package/appUtils/playerManager/OverlayObserver/utils.ts +54 -20
  70. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  71. package/appUtils/playerManager/__tests__/playerFactory.test.ts +150 -0
  72. package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
  73. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  74. package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
  75. package/appUtils/playerManager/index.ts +1 -1
  76. package/appUtils/playerManager/player.ts +115 -3
  77. package/appUtils/playerManager/playerFactory.ts +18 -35
  78. package/appUtils/playerManager/playerNative.ts +6 -4
  79. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  80. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  81. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  82. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  83. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  84. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  85. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  86. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  87. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  88. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  89. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  90. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  91. package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
  92. package/arrayUtils/__tests__/sample.test.ts +61 -0
  93. package/arrayUtils/index.ts +136 -20
  94. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  95. package/bottomSheet/index.ts +17 -0
  96. package/cellUtils/index.ts +33 -8
  97. package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
  98. package/colorUtils/__tests__/isValidColor.test.ts +70 -0
  99. package/colorUtils/index.ts +50 -0
  100. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  101. package/configurationUtils/__tests__/modalBlocksParser.test.ts +260 -0
  102. package/configurationUtils/manifestKeyParser.ts +50 -10
  103. package/configurationUtils/modalBlocksParser.ts +296 -0
  104. package/entryActions/__tests__/buildEntryActions.test.ts +156 -0
  105. package/entryActions/aliasPresentation.ts +124 -0
  106. package/entryActions/buildEntryActions.ts +166 -0
  107. package/entryActions/index.ts +17 -0
  108. package/entryActions/types.ts +39 -0
  109. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  110. package/manifestUtils/_internals/index.js +14 -3
  111. package/manifestUtils/defaultManifestConfigurations/generalContent.js +35 -0
  112. package/manifestUtils/defaultManifestConfigurations/player.js +349 -20
  113. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
  114. package/manifestUtils/fieldUtils/index.js +125 -0
  115. package/manifestUtils/index.js +3 -0
  116. package/manifestUtils/keys.js +9 -0
  117. package/manifestUtils/mobileAction/button/index.js +16 -0
  118. package/manifestUtils/mobileAction/container/index.js +3 -1
  119. package/manifestUtils/mobileAction/groups/defaults.js +3 -1
  120. package/manifestUtils/modalBlocks.js +304 -0
  121. package/manifestUtils/platformIsTV.js +1 -0
  122. package/modalState/ContentViewModel.ts +113 -0
  123. package/modalState/EditableCollection.ts +17 -0
  124. package/modalState/EditableCollectionRegistry.ts +51 -0
  125. package/modalState/ModalOrchestrator.ts +211 -0
  126. package/modalState/RemoteEditableCollection.ts +227 -0
  127. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  128. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  129. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  130. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
  131. package/modalState/__tests__/RemoteEditableCollection.test.ts +326 -0
  132. package/modalState/__tests__/index.test.ts +30 -1
  133. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  134. package/modalState/index.ts +35 -83
  135. package/modalState/store.ts +102 -0
  136. package/modalState/types.ts +159 -0
  137. package/modalState/useBottomSheetContent.ts +109 -0
  138. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  139. package/numberUtils/__tests__/isZero.test.ts +27 -0
  140. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  141. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  142. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  143. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  144. package/numberUtils/index.ts +27 -8
  145. package/package.json +2 -2
  146. package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
  147. package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
  148. package/pipesUtils/index.ts +1 -0
  149. package/pipesUtils/withPipesEndpoint.tsx +54 -0
  150. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  151. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  152. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  153. package/playerUtils/contentDataKeys.ts +134 -0
  154. package/playerUtils/index.ts +58 -15
  155. package/playerUtils/isAudioItem.ts +26 -0
  156. package/playerUtils/resolvePlayerActions.ts +71 -0
  157. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  158. package/reactHooks/actions/index.ts +117 -2
  159. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  160. package/reactHooks/cell-click/index.ts +39 -24
  161. package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
  162. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  163. package/reactHooks/feed/index.ts +5 -1
  164. package/reactHooks/feed/useBatchLoading.ts +9 -1
  165. package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
  166. package/reactHooks/index.ts +2 -0
  167. package/reactHooks/layout/index.ts +1 -1
  168. package/reactHooks/navigation/__mocks__/index.ts +4 -0
  169. package/reactHooks/navigation/__tests__/index.test.tsx +48 -0
  170. package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
  171. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  172. package/reactHooks/navigation/index.ts +3 -1
  173. package/reactHooks/navigation/useIsScreenActive.ts +29 -8
  174. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  175. package/reactHooks/navigation/useRoute.ts +28 -15
  176. package/reactHooks/state/useComponentScreenState.ts +1 -1
  177. package/reactHooks/usePluginConfiguration.ts +4 -1
  178. package/reactHooks/utils/__tests__/index.test.js +22 -2
  179. package/reactHooks/utils/index.ts +13 -2
  180. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +22 -4
  181. package/riverComponetsMeasurementProvider/index.tsx +12 -8
  182. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  183. package/stringUtils/index.ts +2 -2
  184. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  185. package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
  186. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  187. package/uiActionsRegistrator/index.ts +25 -0
  188. package/uiActionsRegistrator/registry.ts +335 -0
  189. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  190. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  191. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  192. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  193. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  194. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  195. package/playerUtils/getPlayerActionButtons.ts +0 -17
  196. package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
  197. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -4,6 +4,7 @@ import * as React from "react";
4
4
  import * as R from "ramda";
5
5
  import { handleActionSchemeUrl } from "@applicaster/quick-brick-core/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useUrlSchemeHandler";
6
6
  import { CellTapContext } from "@applicaster/zapp-react-native-ui-components/Contexts/CellTapContext";
7
+ import { useUIComponentContext } from "@applicaster/zapp-react-native-ui-components/Contexts/UIComponentContext";
7
8
  import {
8
9
  useNavigation,
9
10
  useProfilerLogging,
@@ -28,7 +29,6 @@ import { useScreenStateStore } from "../navigation/useScreenStateStore";
28
29
  type Props = {
29
30
  item?: ZappEntry;
30
31
  index?: number;
31
- component?: ZappUIComponent;
32
32
  zappPipesData?: ZappPipesData;
33
33
  };
34
34
 
@@ -37,24 +37,25 @@ type onPressReturnFn =
37
37
  | (() => void);
38
38
 
39
39
  export const useCellClick = ({
40
- component,
41
40
  zappPipesData,
42
41
  item,
43
- }: Props): onPressReturnFn => {
42
+ }: Props = {}): onPressReturnFn => {
44
43
  const { push, currentRoute } = useNavigation();
45
44
  const { pathname } = useRoute();
46
45
  const screenStateStore = useScreenStateStore();
47
46
 
48
47
  const onCellTap: Option<Function> = React.useContext(CellTapContext);
49
48
  const actionExecutor = React.useContext(ActionExecutorContext);
49
+ const component = useUIComponentContext();
50
50
  const screenData = useCurrentScreenData();
51
51
  const screenState = useScreenContext()?.options;
52
+ const entry = useScreenContext()?.entry;
52
53
 
53
54
  const cellSelectable = toBooleanWithDefaultTrue(
54
55
  component?.rules?.component_cells_selectable
55
56
  );
56
57
 
57
- const [entryContext, setEntryContext] =
58
+ const [_entryContext, setEntryContext] =
58
59
  ZappPipesEntryContext.useZappPipesContext(pathname);
59
60
 
60
61
  const logTimestamp = useProfilerLogging();
@@ -82,6 +83,12 @@ export const useCellClick = ({
82
83
 
83
84
  logOnPress(selectedItem, pathname, component, onCellTap);
84
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
+
85
92
  if (selectedItem) {
86
93
  await actionExecutor?.handleEntryActions(selectedItem, {
87
94
  component,
@@ -89,7 +96,8 @@ export const useCellClick = ({
89
96
  screenState,
90
97
  screenRoute: pathname,
91
98
  screenStateStore,
92
- entryContext,
99
+ entryContext: selectedItem,
100
+ screenEntry: entry,
93
101
  });
94
102
  }
95
103
 
@@ -99,32 +107,39 @@ export const useCellClick = ({
99
107
  url: selectedItem.link.href,
100
108
  });
101
109
  }
102
- } else {
103
- if (isFunction(onCellTap)) {
104
- onCellTap?.(selectedItem, _index);
105
- } else {
106
- if (currentRoute === pathname || pathname.includes("video-modal")) {
107
- const targetScreen = component?.data?.target;
108
-
109
- push(
110
- R.when(
111
- () => targetScreen,
112
- R.mergeLeft({ screen_type: targetScreen })
113
- )(selectedItem)
114
- );
115
- }
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
+ );
116
125
  }
117
126
  }
118
127
  },
119
128
  [
120
- onCellTap,
121
- currentRoute,
129
+ item,
122
130
  setEntryContext,
123
- pathname,
124
- push,
125
131
  sendAnalyticsOnPress,
132
+ logTimestamp,
133
+ pathname,
134
+ component,
135
+ onCellTap,
136
+ entry,
137
+ actionExecutor,
126
138
  screenData,
127
139
  screenState,
140
+ screenStateStore,
141
+ currentRoute,
142
+ push,
128
143
  ]
129
144
  );
130
145
 
@@ -138,5 +153,5 @@ export const useCellClick = ({
138
153
  onPressRef.current = onPress;
139
154
  }
140
155
 
141
- return React.useCallback(onPressRef.current, []);
156
+ return React.useCallback(onPressRef.current, [item]);
142
157
  };
@@ -0,0 +1,4 @@
1
+ export const useMarkPipesDataStale = jest.fn();
2
+
3
+ /** @deprecated alias of useMarkPipesDataStale */
4
+ export const usePipesCacheReset = useMarkPipesDataStale;
@@ -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
  });
@@ -6,7 +6,11 @@ export { useEntryScreenId } from "./useEntryScreenId";
6
6
 
7
7
  export { useBuildPipesUrl } from "./useBuildPipesUrl";
8
8
 
9
- export { usePipesCacheReset } from "./usePipesCacheReset";
9
+ export {
10
+ useMarkPipesDataStale,
11
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
12
+ usePipesCacheReset,
13
+ } from "./useMarkPipesDataStale";
10
14
 
11
15
  export { useBatchLoading } from "./useBatchLoading";
12
16
 
@@ -159,9 +159,17 @@ export const useBatchLoading = (
159
159
  options.riverId,
160
160
  ]);
161
161
 
162
+ // Initial preload only. Batch loading warms the first batch of component
163
+ // feeds and signals readiness; the feed set is frozen at mount on purpose.
164
+ // Per-component loads and reloads (including stale revalidation) are owned by
165
+ // useFeedLoader in ZappPipesDataConnector. Re-running on `feeds`/input changes
166
+ // would re-fire on every store update and cause redundant dispatch storms, so
167
+ // this intentionally runs once on mount.
168
+ /* eslint-disable @wogns3623/better-exhaustive-deps/exhaustive-deps */
162
169
  React.useEffect(() => {
163
170
  runBatchLoading();
164
- }, [runBatchLoading]); // Adding runBatchLoading as a dependency to ensure that it reloads feeds when clearPipesData is called
171
+ }, []);
172
+ /* eslint-enable @wogns3623/better-exhaustive-deps/exhaustive-deps */
165
173
 
166
174
  React.useEffect(() => {
167
175
  // check if all feeds are ready and set hasEverBeenReady to true
@@ -2,17 +2,19 @@ import React from "react";
2
2
 
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
- import { clearPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
5
+ import { markPipesDataStale } from "@applicaster/zapp-react-native-redux/ZappPipes";
6
6
 
7
7
  import { useRoute } from "../navigation";
8
8
  import { useAppDispatch } from "@applicaster/zapp-react-native-redux";
9
9
 
10
10
  /**
11
- * reset river components cache when screen is unmounted
11
+ * Mark a river's `clear_cache_on_reload` feeds as stale when the screen is
12
+ * unmounted. The cached data is kept (so a screen sharing the same feed does
13
+ * not lose it mid-mount) and revalidated on next access.
12
14
  * @param {string} riverId screen id
13
15
  * @param {Array} riverComponents list of UI components
14
16
  */
15
- export const usePipesCacheReset = (riverId, riverComponents) => {
17
+ export const useMarkPipesDataStale = (riverId, riverComponents) => {
16
18
  const dispatch = useAppDispatch();
17
19
  const { screenData, pathname } = useRoute();
18
20
  const pipesContexts = usePipesContexts(riverId, pathname);
@@ -35,10 +37,16 @@ export const usePipesCacheReset = (riverId, riverComponents) => {
35
37
  );
36
38
 
37
39
  if (url) {
38
- dispatch(clearPipesData(url, { riverId }));
40
+ dispatch(markPipesDataStale(url, { riverId }));
39
41
  }
40
42
  }
41
43
  });
42
44
  };
43
45
  }, []);
44
46
  };
47
+
48
+ /**
49
+ * @deprecated Renamed to `useMarkPipesDataStale`. Kept as an alias for backward
50
+ * compatibility with external consumers.
51
+ */
52
+ export const usePipesCacheReset = useMarkPipesDataStale;
@@ -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
 
@@ -38,3 +38,7 @@ export const useNavigationPluginData = jest.fn().mockReturnValue(mockMenu);
38
38
  export const useIsNavBarVisible = jest.fn().mockReturnValue(true);
39
39
 
40
40
  export const useIsScreenActive = jest.fn().mockReturnValue(true);
41
+
42
+ export const isScreenActiveForRoute = jest.fn(
43
+ (route, currentRoute) => route === currentRoute
44
+ );
@@ -7,6 +7,7 @@ import configureMockStore from "redux-mock-store";
7
7
  import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
8
8
  import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/routeTypes";
9
9
  import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
10
+ import { modalStore } from "@applicaster/zapp-react-native-utils/modalState";
10
11
 
11
12
  const plugins = [];
12
13
 
@@ -156,6 +157,20 @@ const videoModalWrapper = ({ children }) => (
156
157
  </Provider>
157
158
  );
158
159
 
160
+ const modalEntry = { id: "modal-entry-1", type: { value: "video" } };
161
+
162
+ const modalPathname = `${ROUTE_TYPES.MODAL}/${rivers["river-general"].id}`;
163
+
164
+ const modalWrapper = ({ children }) => (
165
+ <Provider store={store}>
166
+ <NavigationContext.Provider value={mainStackNavigator}>
167
+ <PathnameContext.Provider value={modalPathname}>
168
+ {children}
169
+ </PathnameContext.Provider>
170
+ </NavigationContext.Provider>
171
+ </Provider>
172
+ );
173
+
159
174
  const hookModalWrapper = ({ children }) => (
160
175
  <Provider store={store}>
161
176
  <NavigationContext.Provider value={hookModalNavigator}>
@@ -188,6 +203,39 @@ describe("navigation", () => {
188
203
  });
189
204
  });
190
205
 
206
+ describe("Modal components", () => {
207
+ beforeEach(() => {
208
+ modalStore.getState().openModal({
209
+ item: rivers["river-general"] as any,
210
+ props: { entry: modalEntry },
211
+ });
212
+ });
213
+
214
+ afterEach(() => {
215
+ modalStore.getState().dismissModal();
216
+ });
217
+
218
+ it("should return a correct pathname", () => {
219
+ const { result } = renderHook(() => useRoute(), {
220
+ wrapper: modalWrapper,
221
+ });
222
+
223
+ expect(result.current.pathname).toEqual(modalPathname);
224
+ });
225
+
226
+ it("should return correct screenData information", () => {
227
+ const { result } = renderHook(() => useRoute(), {
228
+ wrapper: modalWrapper,
229
+ });
230
+
231
+ expect(result.current.screenData.id).toEqual(modalEntry.id);
232
+
233
+ expect(result.current.screenData.targetScreen.id).toEqual(
234
+ rivers["river-general"].id
235
+ );
236
+ });
237
+ });
238
+
191
239
  describe("Hook modal components", () => {
192
240
  it("should return a correct pathname", () => {
193
241
  const { result } = renderHook(() => useRoute(), {
@@ -0,0 +1,42 @@
1
+ import { isScreenActiveForRoute } from "../useIsScreenActive";
2
+
3
+ describe("isScreenActiveForRoute", () => {
4
+ const route = "/river/home/river/tabs";
5
+ const currentRoute = "/river/home/river/tabs";
6
+
7
+ it("returns false when route does not match", () => {
8
+ expect(
9
+ isScreenActiveForRoute(route, "/river/home", { visible: false })
10
+ ).toBe(false);
11
+ });
12
+
13
+ it("keeps underlying screen active when video modal is docked", () => {
14
+ expect(
15
+ isScreenActiveForRoute(route, currentRoute, {
16
+ visible: true,
17
+ mode: "MINIMIZED",
18
+ })
19
+ ).toBe(true);
20
+ });
21
+
22
+ it.each(["FULLSCREEN", "MAXIMIZED", "PIP"])(
23
+ "deactivates underlying screen when video modal is visible",
24
+ (mode) => {
25
+ expect(
26
+ isScreenActiveForRoute(route, currentRoute, {
27
+ visible: true,
28
+ mode,
29
+ })
30
+ ).toBe(false);
31
+ }
32
+ );
33
+
34
+ it("keeps video-modal route active when video modal is open", () => {
35
+ expect(
36
+ isScreenActiveForRoute("video-modal/123", currentRoute, {
37
+ visible: true,
38
+ mode: "FULLSCREEN",
39
+ })
40
+ ).toBe(true);
41
+ });
42
+ });
@@ -0,0 +1,154 @@
1
+ import { modalStore } from "../../../modalState";
2
+ import { isWeb } from "../../../reactUtils";
3
+ import { presentScreen } from "../usePresentScreen";
4
+
5
+ jest.mock("../../../reactUtils", () => ({
6
+ ...jest.requireActual("../../../reactUtils"),
7
+ isWeb: jest.fn(() => false),
8
+ }));
9
+
10
+ const river = { id: "river-parent-lock", type: "parent_lock" } as any;
11
+
12
+ const rivers = { "river-parent-lock": river };
13
+
14
+ const contentTypes = { parent_lock: { screen_id: "river-parent-lock" } };
15
+
16
+ const present = (args = {}) =>
17
+ presentScreen({ typeMapping: "parent_lock", rivers, contentTypes, ...args });
18
+
19
+ const modalState = () => modalStore.getState().modalState;
20
+
21
+ const screenCallback = () => modalState().props?.resultCallback as hookCallback;
22
+
23
+ describe("presentScreen", () => {
24
+ beforeEach(() => {
25
+ jest.clearAllMocks();
26
+ (isWeb as jest.Mock).mockReturnValue(false);
27
+ modalStore.getState().dismissModal();
28
+ });
29
+
30
+ it("opens a modal with the river resolved from typeMapping", () => {
31
+ void present();
32
+
33
+ expect(modalState().visible).toBe(true);
34
+ expect(modalState().screen).toBe(river);
35
+ });
36
+
37
+ it("resolves with success when the presented screen reports success", async () => {
38
+ const result = present();
39
+
40
+ screenCallback()({ success: true, payload: { verified: true } });
41
+
42
+ await expect(result).resolves.toMatchObject({
43
+ success: true,
44
+ cancelled: false,
45
+ payload: { verified: true },
46
+ });
47
+ });
48
+
49
+ it("dismisses the modal once the presented screen reports a result", async () => {
50
+ const result = present();
51
+
52
+ screenCallback()({ success: true, payload: {} });
53
+ await result;
54
+
55
+ expect(modalState().visible).toBe(false);
56
+ });
57
+
58
+ it("resolves as cancelled when the modal is dismissed without a result", async () => {
59
+ const result = present();
60
+
61
+ // What the hardware back button does: RN Modal's onRequestClose resets modal state.
62
+ modalStore.getState().dismissModal();
63
+
64
+ await expect(result).resolves.toMatchObject({
65
+ success: false,
66
+ cancelled: true,
67
+ });
68
+ });
69
+
70
+ it("resolves as cancelled when the presented screen reports cancellation", async () => {
71
+ const result = present();
72
+
73
+ screenCallback()({ success: false, payload: {}, cancelled: true });
74
+
75
+ await expect(result).resolves.toMatchObject({
76
+ success: false,
77
+ cancelled: true,
78
+ });
79
+ });
80
+
81
+ it("resolves as cancelled when another modal replaces the presented screen", async () => {
82
+ const result = present();
83
+
84
+ modalStore.getState().openModal({ item: { id: "other-modal" } as any });
85
+
86
+ await expect(result).resolves.toMatchObject({ cancelled: true });
87
+ });
88
+
89
+ it("leaves the modal that replaced the presented screen open", async () => {
90
+ const result = present();
91
+ const other = { id: "other-modal" } as any;
92
+
93
+ modalStore.getState().openModal({ item: other });
94
+ await result;
95
+
96
+ expect(modalState().screen).toBe(other);
97
+ expect(modalState().visible).toBe(true);
98
+ });
99
+
100
+ it("ignores a result reported after the modal was already cancelled", async () => {
101
+ const result = present();
102
+ const callback = screenCallback();
103
+
104
+ modalStore.getState().dismissModal();
105
+ callback({ success: true, payload: {} });
106
+
107
+ await expect(result).resolves.toMatchObject({
108
+ success: false,
109
+ cancelled: true,
110
+ });
111
+ });
112
+
113
+ it("hands the entry to the ModalProvider so it reaches ScreenDataContext", () => {
114
+ const entry = { id: "entry-1", type: { value: "video" } } as any;
115
+
116
+ void present({ entry });
117
+
118
+ expect(modalState().props?.entry).toBe(entry);
119
+ });
120
+
121
+ it("omits the entry when the screen is presented without one", () => {
122
+ void present();
123
+
124
+ expect(modalState().props).not.toHaveProperty("entry");
125
+ });
126
+
127
+ it("fails without opening a modal when typeMapping has no content type", async () => {
128
+ const result = await present({ typeMapping: "unmapped" });
129
+
130
+ expect(result).toMatchObject({ success: false, cancelled: false });
131
+ expect(result.error).toEqual(expect.any(String));
132
+ expect(modalState().visible).toBe(false);
133
+ });
134
+
135
+ it("fails without opening a modal when the content type resolves to a missing river", async () => {
136
+ const result = await present({
137
+ contentTypes: { parent_lock: { screen_id: "gone" } },
138
+ });
139
+
140
+ expect(result).toMatchObject({ success: false, cancelled: false });
141
+ expect(result.error).toEqual(expect.any(String));
142
+ expect(modalState().visible).toBe(false);
143
+ });
144
+
145
+ it("fails without opening a modal on web, where no modal host exists", async () => {
146
+ (isWeb as jest.Mock).mockReturnValue(true);
147
+
148
+ const result = await present();
149
+
150
+ expect(result).toMatchObject({ success: false, cancelled: false });
151
+ expect(result.error).toEqual(expect.any(String));
152
+ expect(modalState().visible).toBe(false);
153
+ });
154
+ });
@@ -22,6 +22,8 @@ import { useLayoutVersion } from "../layout";
22
22
 
23
23
  export { useNavigation } from "./useNavigation";
24
24
 
25
+ export { usePresentScreen, presentScreen } from "./usePresentScreen";
26
+
25
27
  export { useRoute } from "./useRoute";
26
28
 
27
29
  export { usePathname } from "./usePathname";
@@ -32,7 +34,7 @@ export { useNavigationType } from "./useNavigationType";
32
34
 
33
35
  export { useGetBottomTabBarHeight } from "./useGetBottomTabBarHeight";
34
36
 
35
- export { useIsScreenActive } from "./useIsScreenActive";
37
+ export { useIsScreenActive, isScreenActiveForRoute } from "./useIsScreenActive";
36
38
 
37
39
  export { useProfilerLogging } from "./useProfilerLogging";
38
40
 
@@ -2,20 +2,41 @@ import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtil
2
2
  import { useNavigation } from "./useNavigation";
3
3
  import { usePathname } from "./usePathname";
4
4
 
5
- // If current screen is active/focused (visible to the user)
6
- export const useIsScreenActive = () => {
7
- const pathname = usePathname();
8
- const { currentRoute, videoModalState } = useNavigation();
5
+ type VideoModalState = {
6
+ visible?: boolean;
7
+ mode?: string;
8
+ } | null;
9
9
 
10
- if (videoModalState.visible) {
11
- if (pathname.includes(ROUTE_TYPES.VIDEO_MODAL)) {
10
+ /**
11
+ * Whether a navigation route should be treated as the active/focused screen.
12
+ * Docked (MINIMIZED) video modal does not deactivate the underlying screen —
13
+ * only FULLSCREEN / MAXIMIZED / PIP do.
14
+ */
15
+ export function isScreenActiveForRoute(
16
+ route: string,
17
+ currentRoute: string,
18
+ videoModalState: VideoModalState
19
+ ) {
20
+ if (videoModalState?.visible) {
21
+ if (route.includes(ROUTE_TYPES.VIDEO_MODAL)) {
12
22
  return true;
13
23
  }
14
24
 
15
- if (["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)) {
25
+ if (
26
+ ["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode ?? "")
27
+ ) {
16
28
  return false;
17
29
  }
30
+ // MINIMIZED (docked): fall through — underlying screen stays active
18
31
  }
19
32
 
20
- return pathname === currentRoute;
33
+ return route === currentRoute;
34
+ }
35
+
36
+ // If current screen is active/focused (visible to the user)
37
+ export const useIsScreenActive = () => {
38
+ const pathname = usePathname();
39
+ const { currentRoute, videoModalState } = useNavigation();
40
+
41
+ return isScreenActiveForRoute(pathname, currentRoute, videoModalState);
21
42
  };