@applicaster/zapp-react-native-utils 16.0.0-alpha.6861239588 → 16.0.0-alpha.6918106967

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 (136) hide show
  1. package/actionsExecutor/ActionExecutor.ts +40 -2
  2. package/actionsExecutor/ActionExecutorContext.tsx +96 -17
  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/dismissBottomSheet.ts +23 -0
  14. package/actionsExecutor/actions/goBack.ts +60 -0
  15. package/actionsExecutor/actions/goHome.ts +31 -0
  16. package/actionsExecutor/actions/index.ts +10 -0
  17. package/actionsExecutor/actions/navigateToScreen.ts +18 -4
  18. package/actionsExecutor/actions/openBottomSheet.ts +325 -0
  19. package/actionsExecutor/actions/presentScreen.ts +78 -0
  20. package/actionsExecutor/actions/refreshComponent.ts +6 -0
  21. package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
  22. package/actionsExecutor/actions/showToast.ts +64 -8
  23. package/actionsExecutor/consts.ts +26 -0
  24. package/actionsExecutor/feedDecorator.ts +6 -6
  25. package/actionsExecutor/types.ts +1 -1
  26. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  27. package/appUtils/HooksManager/index.ts +9 -0
  28. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -53
  29. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  30. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +49 -0
  31. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  32. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  33. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
  34. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  35. package/appUtils/playerManager/OverlayObserver/utils.ts +54 -20
  36. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  37. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  38. package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
  39. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  40. package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
  41. package/appUtils/playerManager/index.ts +1 -1
  42. package/appUtils/playerManager/player.ts +115 -3
  43. package/appUtils/playerManager/playerFactory.ts +1 -1
  44. package/appUtils/playerManager/playerNative.ts +6 -4
  45. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  46. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  47. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  48. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  49. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  50. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  51. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  52. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  53. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  54. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  55. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  56. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  57. package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
  58. package/arrayUtils/__tests__/sample.test.ts +61 -0
  59. package/arrayUtils/index.ts +136 -20
  60. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  61. package/bottomSheet/index.ts +17 -0
  62. package/cellUtils/index.ts +30 -3
  63. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  64. package/configurationUtils/__tests__/modalBlocksParser.test.ts +260 -0
  65. package/configurationUtils/manifestKeyParser.ts +50 -10
  66. package/configurationUtils/modalBlocksParser.ts +296 -0
  67. package/entryActions/__tests__/buildEntryActions.test.ts +156 -0
  68. package/entryActions/aliasPresentation.ts +124 -0
  69. package/entryActions/buildEntryActions.ts +166 -0
  70. package/entryActions/index.ts +17 -0
  71. package/entryActions/types.ts +39 -0
  72. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  73. package/manifestUtils/_internals/index.js +8 -3
  74. package/manifestUtils/defaultManifestConfigurations/player.js +349 -20
  75. package/manifestUtils/index.js +3 -0
  76. package/manifestUtils/modalBlocks.js +304 -0
  77. package/modalState/ContentViewModel.ts +113 -0
  78. package/modalState/EditableCollection.ts +17 -0
  79. package/modalState/EditableCollectionRegistry.ts +51 -0
  80. package/modalState/ModalOrchestrator.ts +211 -0
  81. package/modalState/RemoteEditableCollection.ts +227 -0
  82. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  83. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  84. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  85. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
  86. package/modalState/__tests__/RemoteEditableCollection.test.ts +326 -0
  87. package/modalState/__tests__/index.test.ts +30 -1
  88. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  89. package/modalState/index.ts +35 -83
  90. package/modalState/store.ts +102 -0
  91. package/modalState/types.ts +159 -0
  92. package/modalState/useBottomSheetContent.ts +104 -0
  93. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  94. package/numberUtils/__tests__/isZero.test.ts +27 -0
  95. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  96. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  97. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  98. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  99. package/numberUtils/index.ts +27 -8
  100. package/package.json +2 -2
  101. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  102. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  103. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  104. package/playerUtils/contentDataKeys.ts +134 -0
  105. package/playerUtils/index.ts +37 -16
  106. package/playerUtils/isAudioItem.ts +26 -0
  107. package/playerUtils/resolvePlayerActions.ts +71 -0
  108. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  109. package/reactHooks/actions/index.ts +67 -2
  110. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  111. package/reactHooks/index.ts +2 -0
  112. package/reactHooks/layout/index.ts +1 -1
  113. package/reactHooks/navigation/__tests__/index.test.tsx +48 -0
  114. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  115. package/reactHooks/navigation/index.ts +2 -0
  116. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  117. package/reactHooks/navigation/useRoute.ts +14 -1
  118. package/reactHooks/state/useComponentScreenState.ts +1 -1
  119. package/reactHooks/usePluginConfiguration.ts +4 -1
  120. package/reactHooks/utils/__tests__/index.test.js +22 -2
  121. package/reactHooks/utils/index.ts +11 -1
  122. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  123. package/stringUtils/index.ts +2 -2
  124. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  125. package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
  126. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  127. package/uiActionsRegistrator/index.ts +25 -203
  128. package/uiActionsRegistrator/registry.ts +335 -0
  129. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  130. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  131. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  132. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  133. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  134. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  135. package/playerUtils/getPlayerActionButtons.ts +0 -17
  136. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -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
 
@@ -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,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";
@@ -0,0 +1,157 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { useCallback } from "react";
3
+
4
+ import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
5
+
6
+ import { modalStore } from "../../modalState";
7
+ import { isWeb } from "../../reactUtils";
8
+ import { createLogger } from "../../logger";
9
+ import { useRivers } from "../state";
10
+
11
+ const { log_error, log_info } = createLogger({
12
+ subsystem: "usePresentScreen",
13
+ category: "General",
14
+ });
15
+
16
+ export interface PresentScreenArgs {
17
+ /** The screen type to present (from content types mapping) */
18
+ typeMapping: string;
19
+
20
+ /** Entry to present the screen with. Omit to present the screen on its own. */
21
+ entry?: ZappEntry;
22
+ }
23
+
24
+ export interface PresentScreenResult {
25
+ /** The presented screen completed successfully */
26
+ success: boolean;
27
+
28
+ /** The presented screen was dismissed without completing (e.g. the back button) */
29
+ cancelled: boolean;
30
+
31
+ /** Set when the screen could not be presented at all */
32
+ error?: string;
33
+
34
+ /** Whatever the presented screen reported back */
35
+ payload?: unknown;
36
+ }
37
+
38
+ export type PresentScreenFn = (
39
+ args: PresentScreenArgs
40
+ ) => Promise<PresentScreenResult>;
41
+
42
+ interface Dependencies {
43
+ rivers: Record<string, ZappRiver>;
44
+ contentTypes: ZappContentTypes;
45
+ }
46
+
47
+ const failure = (error: string): Promise<PresentScreenResult> => {
48
+ log_error(`presentScreen: ${error}`);
49
+
50
+ return Promise.resolve({ success: false, cancelled: false, error });
51
+ };
52
+
53
+ /**
54
+ * Presents a screen as a modal and resolves once that screen reports a result
55
+ * or is dismissed.
56
+ *
57
+ * The screen is rendered by the ModalProvider through the regular ScreenResolver,
58
+ * so it receives the `resultCallback` we pass here as its `callback` prop — the
59
+ * same channel hook screens already use to report success and cancellation.
60
+ */
61
+ export const presentScreen = ({
62
+ typeMapping,
63
+ entry,
64
+ rivers,
65
+ contentTypes,
66
+ }: PresentScreenArgs & Dependencies): Promise<PresentScreenResult> => {
67
+ if (!typeMapping) {
68
+ return failure("typeMapping option is missing");
69
+ }
70
+
71
+ // The web ModalProvider renders nothing, so no result could ever arrive and
72
+ // awaiting one would stall the caller indefinitely.
73
+ if (isWeb()) {
74
+ return failure("screens can not be presented as modals on web");
75
+ }
76
+
77
+ const screenId = contentTypes?.[typeMapping]?.screen_id;
78
+
79
+ if (!screenId) {
80
+ return failure(`can not resolve screen type mapping: ${typeMapping}`);
81
+ }
82
+
83
+ const river = rivers?.[screenId];
84
+
85
+ if (!river) {
86
+ return failure(`can not resolve river for screen id: ${screenId}`);
87
+ }
88
+
89
+ return new Promise<PresentScreenResult>((resolve) => {
90
+ let settled = false;
91
+ let unsubscribe: () => void = () => {};
92
+
93
+ const settle = (result: PresentScreenResult) => {
94
+ if (settled) {
95
+ return;
96
+ }
97
+
98
+ settled = true;
99
+ unsubscribe();
100
+ resolve(result);
101
+ };
102
+
103
+ const resultCallback = ({
104
+ success,
105
+ cancelled,
106
+ payload,
107
+ }: hookCallbackArgs) =>
108
+ settle({ success: !!success, cancelled: !!cancelled, payload });
109
+
110
+ const props: Record<string, unknown> = { resultCallback };
111
+
112
+ if (entry) {
113
+ // The ModalProvider turns this into the screen's ScreenDataContext and
114
+ // screenData, so the presented screen reads the entry exactly as it
115
+ // would when navigated to.
116
+ props.entry = entry;
117
+ }
118
+
119
+ log_info(
120
+ `presentScreen: presenting screen type: ${typeMapping}${
121
+ entry ? ` with entry id: ${entry.id}` : ""
122
+ }`
123
+ );
124
+
125
+ modalStore.getState().openModal({ item: river, props });
126
+
127
+ // Covers every dismissal we do not initiate ourselves: the hardware back
128
+ // button (via the Modal's onRequestClose), a swipe dismiss, another modal
129
+ // taking our slot, or dismissModal() called from anywhere else.
130
+ unsubscribe = modalStore.subscribe(({ modalState }) => {
131
+ if (!modalState.visible || modalState.screen !== river) {
132
+ settle({ success: false, cancelled: true });
133
+ }
134
+ });
135
+ }).then((result) => {
136
+ // Only take down our own modal — by now something else may already own the slot.
137
+ if (modalStore.getState().modalState.screen === river) {
138
+ modalStore.getState().dismissModal();
139
+ }
140
+
141
+ return result;
142
+ });
143
+ };
144
+
145
+ /**
146
+ * @returns a function presenting a screen as a modal, resolving with its result.
147
+ */
148
+ export const usePresentScreen = (): PresentScreenFn => {
149
+ const rivers = useRivers();
150
+ const contentTypes = useContentTypes();
151
+
152
+ return useCallback(
153
+ (args: PresentScreenArgs) =>
154
+ presentScreen({ ...args, rivers, contentTypes }),
155
+ [rivers, contentTypes]
156
+ );
157
+ };
@@ -80,7 +80,20 @@ export const useRoute = (
80
80
  // if path is hook grab screenData from screenData
81
81
 
82
82
  if (isModalPathname(pathname)) {
83
- const screenData = modalScreenData ?? ({} as ZappEntry);
83
+ if (!modalScreenData) {
84
+ return { screenData: {} as ZappEntry, pathname };
85
+ }
86
+
87
+ // Mirror the pushed-screen shape ({ ...entry, targetScreen }) so a screen
88
+ // presented as a modal reads its entry the same way it would when
89
+ // navigated to, instead of only seeing the bare river.
90
+ const screenData = legacyScreenData(
91
+ {
92
+ screen: modalScreenData,
93
+ entry: modalState.props?.entry as NavigatorEntry,
94
+ },
95
+ plugins
96
+ );
84
97
 
85
98
  return { screenData, pathname };
86
99
  }
@@ -41,5 +41,5 @@ export const useComponentScreenState = <T = unknown>(
41
41
  [componentId, store]
42
42
  );
43
43
 
44
- return [value, setValue] as const;
44
+ return [value, setValue];
45
45
  };
@@ -24,7 +24,10 @@ export function parsePluginConfiguration(plugin, manifest) {
24
24
  return populateFields(plugin, manifest.custom_configuration_fields);
25
25
  }
26
26
 
27
- export function usePluginConfiguration<T, S>(identifier, manifest) {
27
+ export function usePluginConfiguration<T = any, S = Record<string, any>>(
28
+ identifier: string,
29
+ manifest?: any
30
+ ) {
28
31
  const plugins = usePlugins();
29
32
 
30
33
  const plugin = useMemo(
@@ -1,5 +1,5 @@
1
- import { usePrevious, useIsInitialRender } from "../";
2
- import { renderHook, cleanup } from "@testing-library/react-native";
1
+ import { usePrevious, useIsInitialRender, useForceUpdate } from "../";
2
+ import { renderHook, cleanup, act } from "@testing-library/react-native";
3
3
 
4
4
  describe("usePrevious", () => {
5
5
  it("renders", () => {
@@ -49,3 +49,23 @@ describe("useIsInitialRender", () => {
49
49
  expect(result.current).toBe(false);
50
50
  });
51
51
  });
52
+
53
+ describe("useForceUpdate", () => {
54
+ it("forces component to re-render when called", () => {
55
+ let renderCount = 0;
56
+
57
+ const { result } = renderHook(() => {
58
+ renderCount++;
59
+
60
+ return useForceUpdate();
61
+ });
62
+
63
+ expect(renderCount).toBe(1);
64
+
65
+ act(() => {
66
+ result.current();
67
+ });
68
+
69
+ expect(renderCount).toBe(2);
70
+ });
71
+ });
@@ -1,4 +1,4 @@
1
- import { useEffect, useRef } from "react";
1
+ import { useEffect, useReducer, useRef } from "react";
2
2
 
3
3
  /**
4
4
  * This hook returns a previous value that was passed to it.
@@ -31,6 +31,16 @@ export const useIsInitialRender = (): boolean => {
31
31
  return isInitialRenderRef.current;
32
32
  };
33
33
 
34
+ /**
35
+ * Returns a function that forces a re-render of the component when invoked.
36
+ * @return {() => void}
37
+ */
38
+ export const useForceUpdate = (): (() => void) => {
39
+ const [, forceUpdate] = useReducer((n: number) => n + 1, 0);
40
+
41
+ return forceUpdate;
42
+ };
43
+
34
44
  export const checkIsLocalFeed = (feedUrl) => feedUrl?.startsWith("pipesv2://");
35
45
 
36
46
  export const shouldDispatchData = (
@@ -122,6 +122,48 @@ describe("inflate string", () => {
122
122
  "this is a string with custom separators"
123
123
  );
124
124
  });
125
+
126
+ it("does not HTML-escape search variables containing single quotes or apostrophes", () => {
127
+ const string = "https://api.example.com/search?q={{search.query}}";
128
+ const data = { search: { query: "L'aventure" } };
129
+
130
+ expect(inflateString({ string, data })).toBe(
131
+ "https://api.example.com/search?q=L'aventure"
132
+ );
133
+ });
134
+
135
+ it("search context with straight apostrophe", () => {
136
+ const string =
137
+ "https://api.pc-cms.tele.quebec/api/applicaster/v1/tv/search?q={{search.q}}";
138
+
139
+ const data = { search: { q: "l'a" } };
140
+
141
+ expect(inflateString({ string, data })).toBe(
142
+ "https://api.pc-cms.tele.quebec/api/applicaster/v1/tv/search?q=l'a"
143
+ );
144
+ });
145
+
146
+ it("search context with backtick apostrophe", () => {
147
+ const string =
148
+ "https://api.pc-cms.tele.quebec/api/applicaster/v1/tv/search?q={{search.q}}";
149
+
150
+ const data = { search: { q: "l`a" } };
151
+
152
+ expect(inflateString({ string, data })).toBe(
153
+ "https://api.pc-cms.tele.quebec/api/applicaster/v1/tv/search?q=l`a"
154
+ );
155
+ });
156
+
157
+ it("search context with right single quotation mark", () => {
158
+ const string =
159
+ "https://api.pc-cms.tele.quebec/api/applicaster/v1/tv/search?q={{search.q}}";
160
+
161
+ const data = { search: { q: "l’a" } };
162
+
163
+ expect(inflateString({ string, data })).toBe(
164
+ "https://api.pc-cms.tele.quebec/api/applicaster/v1/tv/search?q=l’a"
165
+ );
166
+ });
125
167
  });
126
168
 
127
169
  describe("objectToReadableString", () => {
@@ -72,8 +72,8 @@ const valueIsNull = (value) => () => value === null;
72
72
  const encodeHelper = "encodeURL";
73
73
 
74
74
  const encodeHandlebarsExpressions = R.compose(
75
- R.replace(/{{([^}]+)}}/g, (match, p1) =>
76
- p1.includes("search") ? match : `{{{${encodeHelper} ${p1}}}}`
75
+ R.replace(/{{([^}]+)}}/g, (_, p1) =>
76
+ p1.includes("search") ? `{{{${p1}}}}` : `{{{${encodeHelper} ${p1}}}}`
77
77
  )
78
78
  );
79
79
 
@@ -0,0 +1,93 @@
1
+ import {
2
+ parseActionIdentifiers,
3
+ resolveActionIdentifiers,
4
+ } from "../resolveActionIdentifiers";
5
+ import { uiActionsRegistry } from "../registry";
6
+
7
+ const action = (identifier: string) =>
8
+ ({ identifier, action: { invokeAction: jest.fn() } }) as any;
9
+
10
+ describe("parseActionIdentifiers", () => {
11
+ it("parses comma-separated identifiers", () => {
12
+ expect(parseActionIdentifiers(" a, b , ,c ")).toEqual(["a", "b", "c"]);
13
+ });
14
+
15
+ it("parses identifier arrays", () => {
16
+ expect(parseActionIdentifiers([" a ", "", "b", " ", "c"])).toEqual([
17
+ "a",
18
+ "b",
19
+ "c",
20
+ ]);
21
+ });
22
+
23
+ it("returns empty array for nil config", () => {
24
+ expect(parseActionIdentifiers(null)).toEqual([]);
25
+ expect(parseActionIdentifiers(undefined)).toEqual([]);
26
+ });
27
+ });
28
+
29
+ describe("resolveActionIdentifiers", () => {
30
+ const entry = { id: "entry-1" } as any;
31
+
32
+ beforeEach(() => {
33
+ jest
34
+ .spyOn(uiActionsRegistry, "getActions")
35
+ .mockImplementation((identifier) => [action(identifier)] as any);
36
+ });
37
+
38
+ afterEach(() => {
39
+ jest.restoreAllMocks();
40
+ });
41
+
42
+ it("resolves through registry by default", () => {
43
+ const result = resolveActionIdentifiers({
44
+ identifiers: "favorites,share",
45
+ entry,
46
+ });
47
+
48
+ expect(result.map((item) => item.identifier)).toEqual([
49
+ "favorites",
50
+ "share",
51
+ ]);
52
+
53
+ expect(uiActionsRegistry.getActions).toHaveBeenCalledWith(
54
+ "favorites",
55
+ entry
56
+ );
57
+
58
+ expect(uiActionsRegistry.getActions).toHaveBeenCalledWith("share", entry);
59
+ });
60
+
61
+ it("expands entry_actions through the caller, not the registry", () => {
62
+ const expanded = [action("entry_action_0"), action("entry_action_1")];
63
+ const expandEntryActions = jest.fn(() => expanded);
64
+
65
+ const unregister = uiActionsRegistry.registerAction("share", {
66
+ invokeAction: jest.fn(),
67
+ });
68
+
69
+ try {
70
+ const result = resolveActionIdentifiers({
71
+ identifiers: "entry_actions,share",
72
+ entry,
73
+ expandEntryActions,
74
+ });
75
+
76
+ expect(expandEntryActions).toHaveBeenCalledWith(entry);
77
+
78
+ expect(result.map((item) => item.identifier)).toEqual([
79
+ "entry_action_0",
80
+ "entry_action_1",
81
+ "share",
82
+ ]);
83
+ } finally {
84
+ unregister();
85
+ }
86
+ });
87
+
88
+ it("resolves nothing for entry_actions when the caller cannot expand it", () => {
89
+ expect(
90
+ resolveActionIdentifiers({ identifiers: "entry_actions", entry })
91
+ ).toEqual([]);
92
+ });
93
+ });