@applicaster/zapp-react-native-utils 16.0.0-alpha.1232235100 → 16.0.0-alpha.1314750780

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 (213) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/ActionExecutor.ts +57 -12
  3. package/actionsExecutor/ActionExecutorContext.tsx +110 -333
  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 +314 -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 +127 -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 +66 -0
  43. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  44. package/appUtils/HooksManager/index.ts +9 -0
  45. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +2 -23
  46. package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
  47. package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
  48. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -26
  49. package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
  50. package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
  51. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  52. package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
  53. package/appUtils/contextKeysManager/index.ts +29 -130
  54. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
  55. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  56. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  57. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  58. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  59. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  60. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  61. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  62. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  63. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  64. package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
  65. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  66. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  67. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  68. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
  69. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  70. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  71. package/appUtils/playerManager/{conts.ts → const.ts} +33 -0
  72. package/appUtils/playerManager/index.ts +8 -1
  73. package/appUtils/playerManager/player.ts +140 -3
  74. package/appUtils/playerManager/playerFactory.ts +1 -1
  75. package/appUtils/playerManager/playerNative.ts +28 -4
  76. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  77. package/appUtils/playerManager/playerToolbox.ts +196 -0
  78. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  79. package/appUtils/playerManager/usePlayerControllerSetup.tsx +7 -1
  80. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  81. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  82. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  83. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  84. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  85. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  86. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  87. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  88. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  89. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  90. package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
  91. package/arrayUtils/__tests__/sample.test.ts +61 -0
  92. package/arrayUtils/index.ts +119 -20
  93. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  94. package/bottomSheet/index.ts +17 -0
  95. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  96. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  97. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  98. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  99. package/cellUtils/index.ts +70 -3
  100. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  101. package/configurationUtils/__tests__/modalBlocksParser.test.ts +403 -0
  102. package/configurationUtils/manifestKeyParser.ts +50 -10
  103. package/configurationUtils/modalBlocksParser.ts +252 -0
  104. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  105. package/entryActions/aliasPresentation.ts +108 -0
  106. package/entryActions/buildEntryActions.ts +167 -0
  107. package/entryActions/index.ts +15 -0
  108. package/entryActions/types.ts +39 -0
  109. package/focusManager/FocusManager.ts +26 -0
  110. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  111. package/localizationUtils/index.ts +12 -6
  112. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  113. package/logger/xrayToolbox.ts +67 -0
  114. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  115. package/manifestUtils/_internals/index.js +8 -3
  116. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  117. package/manifestUtils/defaultManifestConfigurations/player.js +357 -20
  118. package/manifestUtils/index.js +3 -0
  119. package/manifestUtils/keys.js +15 -2
  120. package/manifestUtils/mobileAction/button/index.js +16 -0
  121. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  122. package/manifestUtils/mobileAction/container/index.js +3 -1
  123. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  124. package/manifestUtils/mobileAction/groups/defaults.js +5 -2
  125. package/manifestUtils/modalBlocks.js +304 -0
  126. package/modalState/ContentViewModel.ts +113 -0
  127. package/modalState/EditableCollection.ts +17 -0
  128. package/modalState/EditableCollectionRegistry.ts +51 -0
  129. package/modalState/ModalOrchestrator.ts +213 -0
  130. package/modalState/RemoteEditableCollection.ts +235 -0
  131. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  132. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  133. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  134. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +86 -0
  135. package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
  136. package/modalState/__tests__/index.test.ts +30 -1
  137. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  138. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  139. package/modalState/index.ts +37 -83
  140. package/modalState/store.ts +109 -0
  141. package/modalState/types.ts +173 -0
  142. package/modalState/useBottomSheetContent.ts +109 -0
  143. package/navigationUtils/xrayNavigator.ts +12 -0
  144. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  145. package/numberUtils/__tests__/isZero.test.ts +27 -0
  146. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  147. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  148. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  149. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  150. package/numberUtils/index.ts +27 -8
  151. package/package.json +3 -2
  152. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  153. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  154. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  155. package/playerUtils/contentDataKeys.ts +134 -0
  156. package/playerUtils/index.ts +37 -16
  157. package/playerUtils/isAudioItem.ts +26 -0
  158. package/playerUtils/resolvePlayerActions.ts +71 -0
  159. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  160. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  161. package/pluginUtils/index.ts +29 -0
  162. package/quickBrickAssets/__tests__/index.test.ts +18 -0
  163. package/quickBrickAssets/index.ts +35 -0
  164. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  165. package/reactHooks/actions/index.ts +124 -3
  166. package/reactHooks/cell-click/__tests__/index.test.js +131 -1
  167. package/reactHooks/cell-click/index.ts +33 -18
  168. package/reactHooks/connection/index.tsx +8 -5
  169. package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
  170. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
  171. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  172. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  173. package/reactHooks/feed/useFeedLoader.tsx +28 -1
  174. package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
  175. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  176. package/reactHooks/index.ts +2 -0
  177. package/reactHooks/layout/index.ts +1 -1
  178. package/reactHooks/navigation/__mocks__/index.ts +4 -0
  179. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  180. package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
  181. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  182. package/reactHooks/navigation/index.ts +3 -1
  183. package/reactHooks/navigation/useIsScreenActive.ts +29 -8
  184. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  185. package/reactHooks/navigation/useRoute.ts +22 -5
  186. package/reactHooks/state/useComponentScreenState.ts +1 -1
  187. package/reactHooks/usePluginConfiguration.ts +88 -47
  188. package/reactHooks/utils/__tests__/index.test.js +22 -2
  189. package/reactHooks/utils/index.ts +11 -1
  190. package/riverComponetsMeasurementProvider/index.tsx +3 -1
  191. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  192. package/stringUtils/index.ts +2 -2
  193. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  194. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  195. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  196. package/uiActionsRegistrator/index.ts +25 -0
  197. package/uiActionsRegistrator/registry.ts +351 -0
  198. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  199. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  200. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  201. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  202. package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
  203. package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
  204. package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
  205. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
  206. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
  207. package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
  208. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
  209. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
  210. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  211. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  212. package/playerUtils/getPlayerActionButtons.ts +0 -17
  213. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -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,14 +30,17 @@ 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
 
36
+ const mockSetEntryContext = jest.fn();
37
+
34
38
  jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
35
39
  ...jest.requireActual(
36
40
  "@applicaster/zapp-react-native-ui-components/Contexts"
37
41
  ),
38
42
  ZappPipesEntryContext: {
39
- useZappPipesContext: jest.fn(() => [undefined, jest.fn()]),
43
+ useZappPipesContext: jest.fn(() => [undefined, mockSetEntryContext]),
40
44
  },
41
45
  }));
42
46
 
@@ -66,6 +70,12 @@ const wrapper = ({ children }) => (
66
70
  </CellTapContext.Provider>
67
71
  );
68
72
 
73
+ const actionExecutorWrapper = ({ children }) => (
74
+ <ActionExecutorContext.Provider value={actionExecutor}>
75
+ {children}
76
+ </ActionExecutorContext.Provider>
77
+ );
78
+
69
79
  describe("useCellClick", () => {
70
80
  it("returns a function", () => {
71
81
  const { result } = renderHook(() => useCellClick(mockProps));
@@ -95,4 +105,124 @@ describe("useCellClick", () => {
95
105
 
96
106
  cleanup();
97
107
  });
108
+
109
+ it("does not push when the cell finishes a hook", async () => {
110
+ mockNavigator.push.mockClear();
111
+
112
+ const item = {
113
+ id: "profile-1",
114
+ type: { value: "feed" },
115
+ extensions: {
116
+ tap_actions: {
117
+ actions: [
118
+ { type: "sessionStorageSet" },
119
+ { type: "finishHook", options: { success: true } },
120
+ ],
121
+ },
122
+ },
123
+ };
124
+
125
+ const { result } = renderHook(() => useCellClick({ item }), {
126
+ wrapper: actionExecutorWrapper,
127
+ });
128
+
129
+ await result.current();
130
+
131
+ await waitFor(() => {
132
+ expect(actionExecutor.handleEntryActions).toHaveBeenCalled();
133
+ });
134
+
135
+ expect(mockNavigator.push).not.toHaveBeenCalled();
136
+ cleanup();
137
+ });
138
+
139
+ it("pushes after tap actions that do not finish a hook", async () => {
140
+ mockNavigator.push.mockClear();
141
+
142
+ const item = {
143
+ id: "episode-1",
144
+ type: { value: "feed" },
145
+ extensions: {
146
+ tap_actions: {
147
+ actions: [{ type: "sessionStorageSet" }],
148
+ },
149
+ },
150
+ };
151
+
152
+ const { result } = renderHook(() => useCellClick({ item }), {
153
+ wrapper: actionExecutorWrapper,
154
+ });
155
+
156
+ await result.current();
157
+
158
+ await waitFor(() => {
159
+ expect(mockNavigator.push).toHaveBeenCalled();
160
+ });
161
+
162
+ cleanup();
163
+ });
164
+
165
+ describe("entry context", () => {
166
+ const tapWith = async (item) => {
167
+ mockSetEntryContext.mockClear();
168
+ actionExecutor.handleEntryActions.mockClear();
169
+
170
+ const { result } = renderHook(() => useCellClick({ item }), {
171
+ wrapper: actionExecutorWrapper,
172
+ });
173
+
174
+ await result.current();
175
+ cleanup();
176
+ };
177
+
178
+ it("is not set on a tap of an action cell", async () => {
179
+ await tapWith({
180
+ id: "team-1",
181
+ type: { value: "action" },
182
+ extensions: {
183
+ tap_actions: {
184
+ actions: [
185
+ { type: "localStorageToggleFlag" },
186
+ { type: "sendCloudEvent" },
187
+ ],
188
+ },
189
+ },
190
+ });
191
+
192
+ expect(mockSetEntryContext).not.toHaveBeenCalled();
193
+ });
194
+
195
+ it("is handed to the actions so an action can set it", async () => {
196
+ await tapWith({
197
+ id: "link-1",
198
+ type: { value: "action" },
199
+ extensions: {
200
+ tap_actions: { actions: [{ type: "navigateToScreen" }] },
201
+ },
202
+ });
203
+
204
+ expect(actionExecutor.handleEntryActions).toHaveBeenCalledWith(
205
+ expect.objectContaining({ id: "link-1" }),
206
+ expect.objectContaining({ setEntryContext: mockSetEntryContext })
207
+ );
208
+ });
209
+
210
+ it("is set after the actions for any other cell", async () => {
211
+ await tapWith({
212
+ id: "episode-2",
213
+ type: { value: "feed" },
214
+ extensions: {
215
+ tap_actions: { actions: [{ type: "localStorageToggleFlag" }] },
216
+ },
217
+ });
218
+
219
+ expect(mockSetEntryContext).toHaveBeenCalledWith(
220
+ expect.objectContaining({ id: "episode-2" })
221
+ );
222
+
223
+ expect(
224
+ actionExecutor.handleEntryActions.mock.invocationCallOrder[0]
225
+ ).toBeLessThan(mockSetEntryContext.mock.invocationCallOrder[0]);
226
+ });
227
+ });
98
228
  });
@@ -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,16 +37,16 @@ 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
52
  const entry = useScreenContext()?.entry;
@@ -71,7 +71,6 @@ export const useCellClick = ({
71
71
  // Making sure we are not getting GestureResponderEvent in here.
72
72
  const isZappEntry = _item?.id && _item?.type;
73
73
  const selectedItem = isZappEntry ? _item : item;
74
- setEntryContext?.(selectedItem);
75
74
 
76
75
  if (!selectedItem?.type?.value) {
77
76
  warnEmptyContentType(selectedItem);
@@ -83,8 +82,15 @@ export const useCellClick = ({
83
82
 
84
83
  logOnPress(selectedItem, pathname, component, onCellTap);
85
84
 
85
+ const tapActions = selectedItem?.extensions?.tap_actions?.actions;
86
+
87
+ const finishesHook =
88
+ Array.isArray(tapActions) &&
89
+ tapActions.some((action) => action?.type === "finishHook");
90
+
86
91
  if (selectedItem) {
87
92
  await actionExecutor?.handleEntryActions(selectedItem, {
93
+ setEntryContext,
88
94
  component,
89
95
  screenData,
90
96
  screenState,
@@ -101,20 +107,29 @@ 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
+
111
+ // An action cell does not open a screen by itself: the actions that do
112
+ // (navigateToScreen) set the entry context for it.
113
+ return;
114
+ }
115
+
116
+ setEntryContext?.(selectedItem);
117
+
118
+ if (isFunction(onCellTap)) {
119
+ onCellTap?.(selectedItem, _index);
120
+ } else if (!finishesHook) {
121
+ // finishHook already completes the hook and navigates to the original
122
+ // target. Pushing the cell as well stacks a second copy of that screen
123
+ // (e.g. home/home after a profile selector hook).
124
+ if (currentRoute === pathname || pathname.includes("video-modal")) {
125
+ const targetScreen = component?.data?.target;
126
+
127
+ push(
128
+ R.when(
129
+ () => targetScreen,
130
+ R.mergeLeft({ screen_type: targetScreen })
131
+ )(selectedItem)
132
+ );
118
133
  }
119
134
  }
120
135
  },
@@ -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
  }