@applicaster/zapp-react-native-utils 16.0.0-alpha.1833861900 → 16.0.0-alpha.1852433906

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 (245) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/ActionExecutor.ts +57 -12
  3. package/actionsExecutor/ActionExecutorContext.tsx +113 -314
  4. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  5. package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
  6. package/actionsExecutor/__tests__/feedDecorator.test.ts +91 -0
  7. package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -0
  8. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
  9. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  10. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  11. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  12. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +267 -0
  13. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +100 -0
  14. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +372 -0
  15. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  16. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  17. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  18. package/actionsExecutor/actions/appRestart.ts +24 -0
  19. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  20. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  21. package/actionsExecutor/actions/goBack.ts +60 -0
  22. package/actionsExecutor/actions/goHome.ts +31 -0
  23. package/actionsExecutor/actions/index.ts +42 -0
  24. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  25. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  26. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  27. package/actionsExecutor/actions/navigateToScreen.ts +121 -0
  28. package/actionsExecutor/actions/openBottomSheet.ts +340 -0
  29. package/actionsExecutor/actions/presentScreen.ts +78 -0
  30. package/actionsExecutor/actions/refreshComponent.ts +85 -0
  31. package/actionsExecutor/actions/screenSetVariable.ts +35 -0
  32. package/actionsExecutor/actions/screenToggleFlag.ts +36 -0
  33. package/actionsExecutor/actions/sendCloudEvent.ts +93 -0
  34. package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
  35. package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
  36. package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
  37. package/actionsExecutor/actions/showAlert.ts +51 -0
  38. package/actionsExecutor/actions/showToast.ts +87 -0
  39. package/actionsExecutor/actions/switchLayout.ts +40 -0
  40. package/actionsExecutor/consts.ts +27 -0
  41. package/actionsExecutor/feedDecorator.ts +12 -6
  42. package/actionsExecutor/types.ts +59 -0
  43. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
  44. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  45. package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
  46. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
  47. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
  48. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
  49. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
  50. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
  51. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
  52. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
  53. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
  54. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
  55. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
  56. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
  57. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
  58. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
  59. package/analyticsUtils/__tests__/fixtures/index.js +20 -0
  60. package/analyticsUtils/analyticsMapper.ts +4 -1
  61. package/appUtils/HooksManager/index.ts +9 -0
  62. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +2 -23
  63. package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
  64. package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
  65. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -26
  66. package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
  67. package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
  68. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  69. package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
  70. package/appUtils/contextKeysManager/index.ts +29 -130
  71. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
  72. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  73. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  74. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  75. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  76. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  77. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  78. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  79. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  80. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  81. package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
  82. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  83. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  84. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  85. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
  86. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  87. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  88. package/appUtils/playerManager/{conts.ts → const.ts} +33 -0
  89. package/appUtils/playerManager/index.ts +8 -1
  90. package/appUtils/playerManager/player.ts +140 -3
  91. package/appUtils/playerManager/playerFactory.ts +1 -1
  92. package/appUtils/playerManager/playerNative.ts +28 -4
  93. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  94. package/appUtils/playerManager/playerToolbox.ts +196 -0
  95. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  96. package/appUtils/playerManager/usePlayerControllerSetup.tsx +7 -1
  97. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  98. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  99. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  100. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  101. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  102. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  103. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  104. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  105. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  106. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  107. package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
  108. package/arrayUtils/__tests__/sample.test.ts +61 -0
  109. package/arrayUtils/index.ts +119 -20
  110. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  111. package/bottomSheet/index.ts +17 -0
  112. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  113. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  114. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  115. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  116. package/cellUtils/index.ts +73 -8
  117. package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
  118. package/colorUtils/__tests__/isValidColor.test.ts +70 -0
  119. package/colorUtils/index.ts +50 -0
  120. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  121. package/configurationUtils/__tests__/modalBlocksParser.test.ts +403 -0
  122. package/configurationUtils/manifestKeyParser.ts +50 -10
  123. package/configurationUtils/modalBlocksParser.ts +252 -0
  124. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  125. package/entryActions/aliasPresentation.ts +108 -0
  126. package/entryActions/buildEntryActions.ts +167 -0
  127. package/entryActions/index.ts +15 -0
  128. package/entryActions/types.ts +39 -0
  129. package/focusManager/FocusManager.ts +26 -0
  130. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  131. package/localizationUtils/index.ts +12 -6
  132. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  133. package/logger/xrayToolbox.ts +67 -0
  134. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  135. package/manifestUtils/_internals/index.js +14 -3
  136. package/manifestUtils/defaultManifestConfigurations/generalContent.js +41 -0
  137. package/manifestUtils/defaultManifestConfigurations/player.js +357 -20
  138. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
  139. package/manifestUtils/fieldUtils/index.js +125 -0
  140. package/manifestUtils/index.js +3 -0
  141. package/manifestUtils/keys.js +16 -2
  142. package/manifestUtils/mobileAction/button/index.js +16 -0
  143. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  144. package/manifestUtils/mobileAction/container/index.js +3 -1
  145. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  146. package/manifestUtils/mobileAction/groups/defaults.js +5 -2
  147. package/manifestUtils/modalBlocks.js +304 -0
  148. package/manifestUtils/platformIsTV.js +1 -0
  149. package/modalState/ContentViewModel.ts +113 -0
  150. package/modalState/EditableCollection.ts +17 -0
  151. package/modalState/EditableCollectionRegistry.ts +51 -0
  152. package/modalState/ModalOrchestrator.ts +213 -0
  153. package/modalState/RemoteEditableCollection.ts +235 -0
  154. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  155. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  156. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  157. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +86 -0
  158. package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
  159. package/modalState/__tests__/index.test.ts +30 -1
  160. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  161. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  162. package/modalState/index.ts +37 -83
  163. package/modalState/store.ts +109 -0
  164. package/modalState/types.ts +173 -0
  165. package/modalState/useBottomSheetContent.ts +109 -0
  166. package/navigationUtils/xrayNavigator.ts +12 -0
  167. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  168. package/numberUtils/__tests__/isZero.test.ts +27 -0
  169. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  170. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  171. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  172. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  173. package/numberUtils/index.ts +27 -8
  174. package/package.json +3 -2
  175. package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
  176. package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
  177. package/pipesUtils/index.ts +1 -0
  178. package/pipesUtils/withPipesEndpoint.tsx +54 -0
  179. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  180. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  181. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  182. package/playerUtils/contentDataKeys.ts +134 -0
  183. package/playerUtils/index.ts +37 -16
  184. package/playerUtils/isAudioItem.ts +26 -0
  185. package/playerUtils/resolvePlayerActions.ts +71 -0
  186. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  187. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  188. package/pluginUtils/index.ts +29 -0
  189. package/quickBrickAssets/__tests__/index.test.ts +18 -0
  190. package/quickBrickAssets/index.ts +35 -0
  191. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  192. package/reactHooks/actions/index.ts +124 -3
  193. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  194. package/reactHooks/cell-click/index.ts +39 -24
  195. package/reactHooks/connection/index.tsx +8 -5
  196. package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
  197. package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
  198. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
  199. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  200. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  201. package/reactHooks/feed/index.ts +5 -1
  202. package/reactHooks/feed/useBatchLoading.ts +9 -1
  203. package/reactHooks/feed/useFeedLoader.tsx +28 -1
  204. package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
  205. package/reactHooks/feed/useMarkPipesDataStale.ts +97 -0
  206. package/reactHooks/index.ts +2 -0
  207. package/reactHooks/layout/index.ts +1 -1
  208. package/reactHooks/navigation/__mocks__/index.ts +4 -0
  209. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  210. package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
  211. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  212. package/reactHooks/navigation/index.ts +3 -1
  213. package/reactHooks/navigation/useIsScreenActive.ts +29 -8
  214. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  215. package/reactHooks/navigation/useRoute.ts +22 -5
  216. package/reactHooks/state/useComponentScreenState.ts +1 -1
  217. package/reactHooks/usePluginConfiguration.ts +88 -47
  218. package/reactHooks/utils/__tests__/index.test.js +22 -2
  219. package/reactHooks/utils/index.ts +13 -2
  220. package/riverComponetsMeasurementProvider/index.tsx +15 -9
  221. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  222. package/stringUtils/index.ts +2 -2
  223. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  224. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  225. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  226. package/uiActionsRegistrator/index.ts +25 -0
  227. package/uiActionsRegistrator/registry.ts +351 -0
  228. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  229. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  230. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  231. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  232. package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
  233. package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
  234. package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
  235. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
  236. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
  237. package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
  238. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
  239. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
  240. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  241. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  242. package/playerUtils/getPlayerActionButtons.ts +0 -17
  243. package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
  244. package/reactHooks/feed/usePipesCacheReset.ts +0 -44
  245. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -0,0 +1,82 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+
3
+ const plugin = {
4
+ identifier: "cast",
5
+ configuration: {
6
+ title: "Configured",
7
+ localizations: { fr: { close: "Fermer" } },
8
+ },
9
+ };
10
+
11
+ jest.mock("@applicaster/zapp-react-native-redux/hooks", () => ({
12
+ usePlugins: () => [plugin],
13
+ }));
14
+
15
+ jest.mock(
16
+ "@applicaster/zapp-react-native-utils/appUtils/localizationsHelper",
17
+ () => ({ getUILanguage: () => "fr" })
18
+ );
19
+
20
+ import {
21
+ getPluginConfiguration,
22
+ mergeLocalizations,
23
+ usePluginConfiguration,
24
+ } from "../usePluginConfiguration";
25
+
26
+ const manifest = {
27
+ custom_configuration_fields: [
28
+ { key: "title", initial_value: "Default" },
29
+ { key: "color", initial_value: "red" },
30
+ ],
31
+ localizations: {
32
+ fields: [
33
+ { key: "close", initial_value: "Close" },
34
+ { key: "cancel", initial_value: "Cancel" },
35
+ ],
36
+ },
37
+ };
38
+
39
+ it("matches usePluginConfiguration outside React", () => {
40
+ const { result } = renderHook(() => usePluginConfiguration("cast", manifest));
41
+
42
+ expect(getPluginConfiguration(plugin, manifest)).toEqual(result.current);
43
+ });
44
+
45
+ // Expected values are what R.mergeDeepWith((l, r) => (isNil(l) ? r : l)) returned before ramda was removed
46
+ describe("mergeLocalizations", () => {
47
+ const defaults = { en: { close: "Close", cancel: "Cancel" } };
48
+
49
+ it("returns the defaults when nothing is configured", () => {
50
+ expect(mergeLocalizations(undefined, defaults)).toEqual(defaults);
51
+ });
52
+
53
+ it("keeps configured values, fills nil ones and missing keys from defaults", () => {
54
+ expect(
55
+ mergeLocalizations(
56
+ { en: { close: null, extra: "X" }, fr: { close: "Fermer" } },
57
+ defaults
58
+ )
59
+ ).toEqual({
60
+ en: { close: "Close", extra: "X", cancel: "Cancel" },
61
+ fr: { close: "Fermer" },
62
+ });
63
+ });
64
+
65
+ it("does not merge arrays", () => {
66
+ expect(
67
+ mergeLocalizations(
68
+ { en: { close: ["a"] } },
69
+ { en: { close: ["b"], cancel: "C" } }
70
+ )
71
+ ).toEqual({ en: { close: ["a"], cancel: "C" } });
72
+ });
73
+ });
74
+
75
+ it("keeps configured languages first, so the fallback language stays the configured one", () => {
76
+ const merged = mergeLocalizations(
77
+ { he: { close: "סגור" }, en: { close: "Close it" } },
78
+ { en: { close: "Close" } }
79
+ );
80
+
81
+ expect(Object.keys(merged)).toEqual(["he", "en"]);
82
+ });
@@ -1,8 +1,13 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
  /* eslint-disable @typescript-eslint/no-unused-vars */
3
- import { Context, useContext, useState } from "react";
3
+ import { Context, useCallback, useContext, useEffect, useState } from "react";
4
4
  import { ActionsContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ActionsContext";
5
5
 
6
+ import {
7
+ observeEntryState,
8
+ RegisteredActionValue,
9
+ uiActionsRegistry,
10
+ } from "../../uiActionsRegistrator";
6
11
  import { reactHooksLogger } from "../logger";
7
12
 
8
13
  const logger = reactHooksLogger.addSubsystem("actions");
@@ -16,21 +21,55 @@ type ActionContexts<T = unknown> = {
16
21
  };
17
22
 
18
23
  /**
19
- * 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.
20
47
  * @param {*} plugId - subscribes to the context of that action plugin
21
48
  * @return {*} - global action provider context or context for specific action plugin
22
49
  */
23
50
  export function useActions<T = unknown>(plugId: string): any {
24
51
  const [logged, setLogged] = useState(false);
25
52
  const context = useContext<ActionContexts<T>>(ActionsContext);
53
+ useRegistryRevision();
54
+
26
55
  const actionContext = context?.actions?.[plugId]?.module?.context;
27
56
 
28
57
  if (plugId) {
29
58
  if (!actionContext) {
59
+ const registeredAction = uiActionsRegistry.getAction(plugId);
60
+
61
+ if (registeredAction) return registeredAction;
62
+
30
63
  if (!logged) {
31
64
  logger.warning({
32
65
  message: `useActions: Couldn't find an action for ${plugId} plugin`,
33
- 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
+ },
34
73
  });
35
74
 
36
75
  setLogged(true);
@@ -46,3 +85,85 @@ export function useActions<T = unknown>(plugId: string): any {
46
85
 
47
86
  return context;
48
87
  }
88
+
89
+ export type UseEntryActionState = {
90
+ state: CellActionEntryState | undefined;
91
+ invokeAction: (options?: InvokeArgsOptions) => void;
92
+ };
93
+
94
+ /**
95
+ * Subscribes a component to a single action's state for a given `entry`.
96
+ *
97
+ * It observes state changes reactively via `observeEntryState` (which is backed
98
+ * by the action's `addListener`), seeds the initial value synchronously from
99
+ * `initialEntryState`, and returns a memoized `invokeAction` that forwards
100
+ * optimistic `updateState` updates back into local state.
101
+ *
102
+ * This is the single, unified way to drive an action button - it works the same
103
+ * for registry actions, legacy context-provider actions and entry actions.
104
+ */
105
+ export function useEntryActionState(
106
+ action: RegisteredActionValue | undefined,
107
+ entry: ZappEntry | ZappFeed
108
+ ): UseEntryActionState {
109
+ const [state, setState] = useState<CellActionEntryState | undefined>(() =>
110
+ action?.initialEntryState?.(entry)
111
+ );
112
+
113
+ const entryId = (entry as ZappEntry)?.id;
114
+
115
+ useEffect(() => {
116
+ if (!action) return undefined;
117
+
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
+ }
143
+
144
+ return () => subscription.unsubscribe();
145
+ // eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
146
+ }, [action, entryId]);
147
+
148
+ const invokeAction = useCallback(
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
+
162
+ action?.invokeAction?.(entry, { updateState: setState, ...options });
163
+ },
164
+ // eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
165
+ [action, entryId]
166
+ );
167
+
168
+ return { state, invokeAction };
169
+ }
@@ -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
  });
@@ -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
  };
@@ -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
  }
@@ -0,0 +1,4 @@
1
+ export const useMarkPipesDataStale = jest.fn();
2
+
3
+ /** @deprecated alias of useMarkPipesDataStale */
4
+ export const usePipesCacheReset = useMarkPipesDataStale;