@applicaster/zapp-react-native-ui-components 14.0.0-alpha.5219335081 → 14.0.0-alpha.5234792518

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 (49) hide show
  1. package/Components/Cell/__tests__/CellWIthFocusable.test.js +3 -2
  2. package/Components/FeedLoader/FeedLoader.tsx +7 -16
  3. package/Components/FeedLoader/FeedLoaderHOC.tsx +21 -0
  4. package/Components/FeedLoader/index.js +2 -8
  5. package/Components/Focusable/Focusable.tsx +1 -1
  6. package/Components/Focusable/FocusableTvOS.tsx +2 -2
  7. package/Components/FocusableGroup/FocusableTvOS.tsx +1 -1
  8. package/Components/FocusableList/index.tsx +2 -2
  9. package/Components/FreezeWithCallback/__tests__/index.test.tsx +67 -43
  10. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +5 -6
  11. package/Components/Layout/TV/__tests__/index.test.tsx +0 -1
  12. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +6 -2
  13. package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +10 -10
  14. package/Components/MasterCell/DefaultComponents/__tests__/text.test.tsx +18 -18
  15. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/index.test.tsx +10 -10
  16. package/Components/MasterCell/utils/behaviorProvider.ts +82 -14
  17. package/Components/MasterCell/utils/index.ts +11 -5
  18. package/Components/OfflineHandler/__tests__/index.test.tsx +6 -13
  19. package/Components/PlayerContainer/PlayerContainer.tsx +4 -1
  20. package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +378 -0
  21. package/Components/River/ComponentsMap/hooks/useLoadingState.ts +2 -2
  22. package/Components/River/RefreshControl.tsx +11 -19
  23. package/Components/River/RiverItem.tsx +5 -0
  24. package/Components/River/__tests__/river.test.js +12 -26
  25. package/Components/Screen/__tests__/Screen.test.tsx +5 -17
  26. package/Components/Screen/__tests__/navigationHandler.test.ts +133 -22
  27. package/Components/Screen/navigationHandler.ts +20 -2
  28. package/Components/Tabs/TV/Tabs.android.tsx +1 -1
  29. package/Components/Tabs/Tabs.tsx +2 -3
  30. package/Components/Touchable/__tests__/touchable.test.tsx +12 -17
  31. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +3 -9
  32. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.web.tsx +294 -0
  33. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.web.tsx +93 -0
  34. package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +5 -5
  35. package/Contexts/ConfigutaionContext/__tests__/ConfigurationProvider.test.tsx +3 -3
  36. package/Contexts/ScreenContext/index.tsx +46 -6
  37. package/Decorators/ConfigurationWrapper/__tests__/withConfigurationProvider.test.tsx +3 -3
  38. package/Decorators/RiverFeedLoader/__tests__/__snapshots__/riverFeedLoader.test.tsx.snap +221 -209
  39. package/Decorators/RiverFeedLoader/__tests__/riverFeedLoader.test.tsx +14 -16
  40. package/Decorators/RiverFeedLoader/__tests__/utils.test.ts +0 -20
  41. package/Decorators/RiverFeedLoader/index.tsx +22 -4
  42. package/Decorators/RiverFeedLoader/utils/index.ts +0 -18
  43. package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +27 -27
  44. package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +35 -10
  45. package/Decorators/ZappPipesDataConnector/utils/mongoFilter.ts +738 -0
  46. package/Decorators/ZappPipesDataConnector/utils/useFilter.tsx +157 -0
  47. package/events/index.ts +1 -0
  48. package/package.json +5 -5
  49. package/Components/River/__tests__/__snapshots__/river.test.js.snap +0 -27
@@ -1,28 +1,58 @@
1
1
  import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils";
2
- import { StorageSingleValueProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageSingleSelectProvider";
2
+ import { StorageSingleValueProvider } from "@applicaster/zapp-react-native-utils/storage/StorageSingleSelectProvider";
3
3
  import { PushTopicManager } from "@applicaster/zapp-react-native-bridge/PushNotifications/PushTopicManager";
4
- import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
4
+ import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-utils/storage/StorageMultiSelectProvider";
5
5
  import React, { useEffect } from "react";
6
6
  import { usePlayer } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer";
7
7
  import { BehaviorSubject } from "rxjs";
8
8
  import { masterCellLogger } from "../logger";
9
9
  import get from "lodash/get";
10
-
11
- const parseContextKey = (key: string): string | null => {
12
- if (!key?.startsWith("@{ctx/")) return null;
13
-
14
- return key.substring("@{ctx/".length, key.length - 1);
10
+ import { ScreenMultiSelectProvider } from "@applicaster/zapp-react-native-utils/storage/ScreenStateMultiSelectProvider";
11
+ import { ScreenSingleValueProvider } from "@applicaster/zapp-react-native-utils/storage/ScreenSingleValueProvider";
12
+ import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks";
13
+ import { useScreenStateStore } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useScreenStateStore";
14
+
15
+ const parseContextKey = (
16
+ key: string,
17
+ context: string = "ctx"
18
+ ): string | null => {
19
+ if (!key?.startsWith(`@{${context}/`)) return null;
20
+
21
+ return key.substring(`@{${context}/`.length, key.length - 1);
15
22
  };
16
23
 
17
24
  const getDataSourceProvider = (
18
- behavior: Behavior
25
+ behavior: Behavior,
26
+ screenRoute: string,
27
+ screenStateStore: ReturnType<typeof useScreenStateStore>
19
28
  ): BehaviorSubject<string[] | string> | null => {
20
29
  if (!behavior) return null;
21
30
 
22
31
  const selection = String(behavior.current_selection);
32
+ const screenKey = parseContextKey(selection, "screen");
33
+
34
+ if (screenKey) {
35
+ if (behavior.select_mode === "multi") {
36
+ return ScreenMultiSelectProvider.getProvider(
37
+ screenKey,
38
+ screenRoute,
39
+ screenStateStore
40
+ ).getObservable();
41
+ }
42
+
43
+ if (behavior.select_mode === "single") {
44
+ return ScreenSingleValueProvider.getProvider(
45
+ screenKey,
46
+ screenRoute,
47
+ screenStateStore
48
+ ).getObservable();
49
+ }
50
+ }
51
+
23
52
  const contextKey = parseContextKey(selection);
24
53
 
25
54
  if (contextKey) {
55
+ // TODO: Add storage scope to behavior
26
56
  if (behavior.select_mode === "multi") {
27
57
  return StorageMultiSelectProvider.getProvider(contextKey).getObservable();
28
58
  }
@@ -41,6 +71,8 @@ const getDataSourceProvider = (
41
71
 
42
72
  export const useBehaviorUpdate = (behavior: Behavior) => {
43
73
  const [lastUpdate, setLastUpdate] = React.useState<number | null>(null);
74
+ const screenRoute = useRoute()?.pathname || "";
75
+ const screenStateStore = useScreenStateStore();
44
76
  const player = usePlayer();
45
77
 
46
78
  const triggerUpdate = () => setLastUpdate(Date.now());
@@ -48,7 +80,11 @@ export const useBehaviorUpdate = (behavior: Behavior) => {
48
80
  useEffect(() => {
49
81
  if (!behavior) return;
50
82
 
51
- const dataSource = getDataSourceProvider(behavior);
83
+ const dataSource = getDataSourceProvider(
84
+ behavior,
85
+ screenRoute,
86
+ screenStateStore
87
+ );
52
88
 
53
89
  if (dataSource) {
54
90
  const subscription = dataSource.subscribe(triggerUpdate);
@@ -72,10 +108,17 @@ export const useBehaviorUpdate = (behavior: Behavior) => {
72
108
 
73
109
  // We cant use async in this function (its inside render),
74
110
  // so we rely on useBehaviorUpdate to update current value and trigger re-render
75
- export const isCellSelected = (
76
- item: ZappEntry,
77
- behavior?: Behavior
78
- ): boolean => {
111
+ export const isCellSelected = ({
112
+ item,
113
+ screenRoute,
114
+ screenStateStore,
115
+ behavior,
116
+ }: {
117
+ item: ZappEntry;
118
+ screenRoute: string;
119
+ screenStateStore: ReturnType<typeof useScreenStateStore>;
120
+ behavior?: Behavior;
121
+ }): boolean => {
79
122
  if (!behavior) return false;
80
123
 
81
124
  const id = behavior.selector ? get(item, behavior.selector) : item.id;
@@ -99,7 +142,32 @@ export const isCellSelected = (
99
142
  }
100
143
 
101
144
  const selection = String(behavior.current_selection);
102
- const contextKey = parseContextKey(selection);
145
+
146
+ const screenKey = parseContextKey(selection, "screen");
147
+
148
+ if (screenKey) {
149
+ if (behavior.select_mode === "single") {
150
+ const selectedItem = ScreenSingleValueProvider.getProvider(
151
+ screenKey,
152
+ screenRoute,
153
+ screenStateStore
154
+ ).getValue();
155
+
156
+ return selectedItem === String(id);
157
+ }
158
+
159
+ if (behavior.select_mode === "multi") {
160
+ const selectedItems = ScreenMultiSelectProvider.getProvider(
161
+ screenKey,
162
+ screenRoute,
163
+ screenStateStore
164
+ ).getSelectedItems();
165
+
166
+ return selectedItems?.includes(String(id));
167
+ }
168
+ }
169
+
170
+ const contextKey = parseContextKey(selection, "ctx");
103
171
 
104
172
  if (contextKey) {
105
173
  if (behavior.select_mode === "single") {
@@ -8,6 +8,8 @@ import { masterCellLogger } from "../logger";
8
8
  import { getCellState } from "../../Cell/utils";
9
9
  import { getColorFromData } from "@applicaster/zapp-react-native-utils/cellUtils";
10
10
  import { isCellSelected, useBehaviorUpdate } from "./behaviorProvider";
11
+ import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks";
12
+ import { useScreenStateStore } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useScreenStateStore";
11
13
 
12
14
  const hasElementSpecificViewType = (viewType) => (element) => {
13
15
  if (R.isNil(element)) {
@@ -190,10 +192,6 @@ export const getFocusedButtonId = (focusable) => {
190
192
  });
191
193
  };
192
194
 
193
- export const isSelected = (item: ZappEntry, behavior?: Behavior) => {
194
- return isCellSelected(item, behavior);
195
- };
196
-
197
195
  export const useCellState = ({
198
196
  item,
199
197
  behavior,
@@ -204,9 +202,17 @@ export const useCellState = ({
204
202
  focused: boolean;
205
203
  }): CellState => {
206
204
  const lastUpdate = useBehaviorUpdate(behavior);
205
+ const router = useRoute();
206
+ const screenStateStore = useScreenStateStore();
207
207
 
208
208
  const _isSelected = useMemo(
209
- () => isSelected(item, behavior),
209
+ () =>
210
+ isCellSelected({
211
+ item,
212
+ screenRoute: router?.pathname,
213
+ screenStateStore,
214
+ behavior,
215
+ }),
210
216
  [behavior, item, lastUpdate]
211
217
  );
212
218
 
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
-
3
- import renderer, { act } from "react-test-renderer";
2
+ import { render } from "@testing-library/react-native";
4
3
 
5
4
  jest.useFakeTimers({ legacyFakeTimers: true });
6
5
 
@@ -49,24 +48,18 @@ describe("OfflineHandler", () => {
49
48
  const { OfflineHandler, NotificationView } = require("../");
50
49
 
51
50
  it("renders", () => {
52
- const instance = renderer.create(<OfflineHandler />);
53
- expect(instance.toJSON()).toMatchSnapshot();
51
+ const { toJSON } = render(<OfflineHandler />);
52
+ expect(toJSON()).toMatchSnapshot();
54
53
  });
55
54
 
56
55
  it("renders Notification mode if component was rendered while online", () => {
57
56
  mockConnectionStatus = true;
58
57
 
59
- let instance;
60
-
61
- act(() => {
62
- instance = renderer.create(<OfflineHandler />);
63
- });
58
+ const { rerender, UNSAFE_getByType } = render(<OfflineHandler />);
64
59
 
65
- act(() => {
66
- instance.update(<OfflineHandler />);
67
- });
60
+ rerender(<OfflineHandler />);
68
61
 
69
- const notificationsView = instance.root.findByType(NotificationView);
62
+ const notificationsView = UNSAFE_getByType(NotificationView);
70
63
  expect(notificationsView).toBeDefined();
71
64
  });
72
65
  });
@@ -423,7 +423,10 @@ const PlayerContainerComponent = (props: Props) => {
423
423
  id: playerContainerId,
424
424
  listener: {
425
425
  onVideoEnd,
426
- onError,
426
+ onError: (err: Error) => {
427
+ // Adapt Error to the expected shape for onError
428
+ onError({ error: err });
429
+ },
427
430
  onLoad,
428
431
  onPlayerClose: close,
429
432
  onPlayerDetached: close,
@@ -0,0 +1,378 @@
1
+ import { renderHook, act } from "@testing-library/react-hooks";
2
+ import { BehaviorSubject } from "rxjs";
3
+ import { useLoadingState } from "../useLoadingState";
4
+
5
+ jest.mock(
6
+ "@applicaster/zapp-react-native-utils/reactHooks/state/useRefWithInitialValue",
7
+ () => ({
8
+ useRefWithInitialValue: jest.fn((initializer) => ({
9
+ current: initializer(),
10
+ })),
11
+ })
12
+ );
13
+
14
+ describe("useLoadingState", () => {
15
+ let onLoadDone: jest.Mock;
16
+
17
+ beforeEach(() => {
18
+ onLoadDone = jest.fn();
19
+ jest.clearAllMocks();
20
+ });
21
+
22
+ describe("initialization", () => {
23
+ it("should initialize with correct default state for zero components", () => {
24
+ const { result } = renderHook(() => useLoadingState(0, onLoadDone));
25
+
26
+ const initialState = result.current.loadingState.getValue();
27
+
28
+ expect(initialState).toEqual({
29
+ index: -1,
30
+ done: true,
31
+ waitForAllComponents: false,
32
+ });
33
+
34
+ expect(result.current.shouldShowLoadingError).toBe(false);
35
+ });
36
+
37
+ it("should initialize with correct default state for multiple components", () => {
38
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
39
+
40
+ const initialState = result.current.loadingState.getValue();
41
+
42
+ expect(initialState).toEqual({
43
+ index: -1,
44
+ done: false,
45
+ waitForAllComponents: false,
46
+ });
47
+
48
+ expect(result.current.shouldShowLoadingError).toBe(false);
49
+ });
50
+
51
+ it("should return a BehaviorSubject for loadingState", () => {
52
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
53
+
54
+ expect(result.current.loadingState).toBeInstanceOf(BehaviorSubject);
55
+ });
56
+ });
57
+
58
+ describe("arePreviousComponentsLoaded", () => {
59
+ it("should return true for index 0 (first component)", () => {
60
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
61
+
62
+ expect(result.current.arePreviousComponentsLoaded(0)).toBe(true);
63
+ });
64
+
65
+ it("should return false when previous components are not loaded", () => {
66
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
67
+
68
+ expect(result.current.arePreviousComponentsLoaded(1)).toBe(false);
69
+ expect(result.current.arePreviousComponentsLoaded(2)).toBe(false);
70
+ });
71
+
72
+ it("should return true when all previous components are loaded", () => {
73
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
74
+
75
+ act(() => {
76
+ result.current.onLoadFinished(0);
77
+ });
78
+
79
+ expect(result.current.arePreviousComponentsLoaded(1)).toBe(true);
80
+ expect(result.current.arePreviousComponentsLoaded(2)).toBe(false);
81
+
82
+ act(() => {
83
+ result.current.onLoadFinished(1);
84
+ });
85
+
86
+ expect(result.current.arePreviousComponentsLoaded(2)).toBe(true);
87
+ });
88
+ });
89
+
90
+ describe("onLoadFinished", () => {
91
+ it("should update component state and loading state when component finishes loading", () => {
92
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
93
+
94
+ act(() => {
95
+ result.current.onLoadFinished(0);
96
+ });
97
+
98
+ const state = result.current.loadingState.getValue();
99
+ expect(state.index).toBe(0);
100
+ expect(state.done).toBe(false);
101
+ });
102
+
103
+ it("should update index to highest loaded component", () => {
104
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
105
+
106
+ act(() => {
107
+ result.current.onLoadFinished(2);
108
+ });
109
+
110
+ let state = result.current.loadingState.getValue();
111
+ expect(state.index).toBe(2);
112
+
113
+ act(() => {
114
+ result.current.onLoadFinished(1);
115
+ });
116
+
117
+ state = result.current.loadingState.getValue();
118
+ expect(state.index).toBe(2); // Should remain 2, not decrease to 1
119
+ });
120
+
121
+ it("should mark as done when all components are loaded", () => {
122
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
123
+
124
+ act(() => {
125
+ result.current.onLoadFinished(0);
126
+ });
127
+
128
+ let state = result.current.loadingState.getValue();
129
+ expect(state.done).toBe(true); // True because arePreviousComponentsLoaded(1) returns true when component 0 is loaded
130
+ expect(onLoadDone).toHaveBeenCalledTimes(1);
131
+
132
+ act(() => {
133
+ result.current.onLoadFinished(1);
134
+ });
135
+
136
+ state = result.current.loadingState.getValue();
137
+ expect(state.done).toBe(true);
138
+ expect(onLoadDone).toHaveBeenCalledTimes(2); // Called again
139
+ });
140
+
141
+ it("should call onLoadDone when count is 0", () => {
142
+ const { result } = renderHook(() => useLoadingState(0, onLoadDone));
143
+
144
+ const state = result.current.loadingState.getValue();
145
+ expect(state.done).toBe(true);
146
+ // onLoadDone is not called on initialization for count 0, only when all components are loaded via dispatch
147
+ });
148
+
149
+ it("should handle loading components out of order", () => {
150
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
151
+
152
+ // Load component 2 first
153
+ act(() => {
154
+ result.current.onLoadFinished(2);
155
+ });
156
+
157
+ let state = result.current.loadingState.getValue();
158
+ expect(state.done).toBe(false);
159
+
160
+ // Load component 0
161
+ act(() => {
162
+ result.current.onLoadFinished(0);
163
+ });
164
+
165
+ state = result.current.loadingState.getValue();
166
+ expect(state.done).toBe(false);
167
+
168
+ // Load component 1 - should complete loading
169
+ act(() => {
170
+ result.current.onLoadFinished(1);
171
+ });
172
+
173
+ state = result.current.loadingState.getValue();
174
+ expect(state.done).toBe(true);
175
+ expect(onLoadDone).toHaveBeenCalledTimes(1);
176
+ });
177
+
178
+ it("should call onLoadDone again on subsequent dispatches", () => {
179
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
180
+
181
+ act(() => {
182
+ result.current.onLoadFinished(0);
183
+ result.current.onLoadFinished(1);
184
+ });
185
+
186
+ expect(onLoadDone).toHaveBeenCalledTimes(2); // Called for each dispatch when done is true
187
+
188
+ // Try loading again - onLoadDone will be called again because dispatch runs again
189
+ act(() => {
190
+ result.current.onLoadFinished(0);
191
+ });
192
+
193
+ expect(onLoadDone).toHaveBeenCalledTimes(3); // Will be called again
194
+ });
195
+ });
196
+
197
+ describe("onLoadFailed", () => {
198
+ it("should treat failed components as loaded when SHOULD_FAIL_ON_COMPONENT_LOADING is false", () => {
199
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
200
+
201
+ const error = new Error("Load failed");
202
+
203
+ act(() => {
204
+ result.current.onLoadFailed({ error, index: 0 });
205
+ });
206
+
207
+ const state = result.current.loadingState.getValue();
208
+ expect(state.index).toBe(0);
209
+ expect(result.current.shouldShowLoadingError).toBe(false);
210
+ });
211
+
212
+ it("should complete loading when all components fail", () => {
213
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
214
+
215
+ const error = new Error("Load failed");
216
+
217
+ act(() => {
218
+ result.current.onLoadFailed({ error, index: 0 });
219
+ result.current.onLoadFailed({ error, index: 1 });
220
+ });
221
+
222
+ const state = result.current.loadingState.getValue();
223
+ expect(state.done).toBe(true);
224
+ expect(onLoadDone).toHaveBeenCalledTimes(2); // Called for each failed component
225
+ });
226
+
227
+ it("should handle mixed success and failure", () => {
228
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
229
+
230
+ const error = new Error("Load failed");
231
+
232
+ act(() => {
233
+ result.current.onLoadFinished(0);
234
+ result.current.onLoadFailed({ error, index: 1 });
235
+ result.current.onLoadFinished(2);
236
+ });
237
+
238
+ const state = result.current.loadingState.getValue();
239
+ expect(state.done).toBe(true);
240
+ expect(onLoadDone).toHaveBeenCalledTimes(2); // Called when all components 0,1,2 are handled
241
+ });
242
+ });
243
+
244
+ describe("loading state observable", () => {
245
+ it("should emit state changes through BehaviorSubject", () => {
246
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone)); // Use 3 components so loading component 0 doesn't complete everything
247
+ const mockSubscriber = jest.fn();
248
+
249
+ result.current.loadingState.subscribe(mockSubscriber);
250
+
251
+ act(() => {
252
+ result.current.onLoadFinished(0);
253
+ });
254
+
255
+ // Should have been called twice: initial state + update
256
+ expect(mockSubscriber).toHaveBeenCalledTimes(2);
257
+
258
+ expect(mockSubscriber).toHaveBeenLastCalledWith({
259
+ index: 0,
260
+ done: false, // Will be false because we need components 1 and 2 as well
261
+ waitForAllComponents: false,
262
+ });
263
+ });
264
+
265
+ it("should preserve waitForAllComponents flag in state updates", () => {
266
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
267
+
268
+ act(() => {
269
+ result.current.onLoadFinished(0);
270
+ });
271
+
272
+ const state = result.current.loadingState.getValue();
273
+ expect(state.waitForAllComponents).toBe(false);
274
+ });
275
+ });
276
+
277
+ describe("memoization", () => {
278
+ it("should return stable references for functions", () => {
279
+ const { result, rerender } = renderHook(() =>
280
+ useLoadingState(2, onLoadDone)
281
+ );
282
+
283
+ const firstRender = {
284
+ onLoadFinished: result.current.onLoadFinished,
285
+ onLoadFailed: result.current.onLoadFailed,
286
+ arePreviousComponentsLoaded: result.current.arePreviousComponentsLoaded,
287
+ };
288
+
289
+ rerender();
290
+
291
+ expect(result.current.onLoadFinished).toBe(firstRender.onLoadFinished);
292
+ expect(result.current.onLoadFailed).toBe(firstRender.onLoadFailed);
293
+
294
+ expect(result.current.arePreviousComponentsLoaded).toBe(
295
+ firstRender.arePreviousComponentsLoaded
296
+ );
297
+ });
298
+
299
+ it("should return stable function references (current behavior)", () => {
300
+ const { result, rerender } = renderHook(
301
+ ({ onLoadDone }) => useLoadingState(2, onLoadDone),
302
+ { initialProps: { onLoadDone } }
303
+ );
304
+
305
+ const firstResult = result.current;
306
+
307
+ const newOnLoadDone = jest.fn();
308
+ rerender({ onLoadDone: newOnLoadDone });
309
+
310
+ // Functions should remain the same due to empty dependency arrays (this is the current behavior)
311
+ expect(result.current.onLoadFinished).toBe(firstResult.onLoadFinished);
312
+ expect(result.current.onLoadFailed).toBe(firstResult.onLoadFailed);
313
+ });
314
+ });
315
+
316
+ describe("edge cases", () => {
317
+ it("should handle duplicate load finished calls gracefully", () => {
318
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
319
+
320
+ act(() => {
321
+ result.current.onLoadFinished(0);
322
+ result.current.onLoadFinished(0); // Duplicate call
323
+ });
324
+
325
+ const state = result.current.loadingState.getValue();
326
+ expect(state.index).toBe(0);
327
+ expect(state.done).toBe(true); // True because loading component 0 makes it done in a 2-component setup
328
+ });
329
+
330
+ it("should handle loading index greater than component count", () => {
331
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
332
+
333
+ act(() => {
334
+ result.current.onLoadFinished(5); // Index out of bounds
335
+ });
336
+
337
+ const state = result.current.loadingState.getValue();
338
+ expect(state.index).toBe(5);
339
+ expect(state.done).toBe(false); // Should not be done as not all components loaded
340
+ });
341
+
342
+ it("should handle negative indices", () => {
343
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
344
+
345
+ act(() => {
346
+ result.current.onLoadFinished(-1);
347
+ });
348
+
349
+ const state = result.current.loadingState.getValue();
350
+ expect(state.index).toBe(-1); // Should remain -1
351
+ });
352
+ });
353
+
354
+ describe("component count changes", () => {
355
+ it("should handle changing component count", () => {
356
+ const { result, rerender } = renderHook(
357
+ ({ count }) => useLoadingState(count, onLoadDone),
358
+ { initialProps: { count: 2 } }
359
+ );
360
+
361
+ act(() => {
362
+ result.current.onLoadFinished(0);
363
+ });
364
+
365
+ // Change count
366
+ rerender({ count: 3 });
367
+
368
+ // The hook should work with the new count
369
+ act(() => {
370
+ result.current.onLoadFinished(1);
371
+ result.current.onLoadFinished(2);
372
+ });
373
+
374
+ const state = result.current.loadingState.getValue();
375
+ expect(state.done).toBe(true);
376
+ });
377
+ });
378
+ });
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { isNil, set, lensIndex, T, slice } from "ramda";
2
+ import { isNil, set, lensIndex, slice } from "ramda";
3
3
  import { BehaviorSubject } from "rxjs";
4
4
  import { useRefWithInitialValue } from "@applicaster/zapp-react-native-utils/reactHooks/state/useRefWithInitialValue";
5
5
 
@@ -53,7 +53,7 @@ export const useLoadingState = (
53
53
 
54
54
  const componentsBefore = slice(0, index, componentStateRef.current);
55
55
 
56
- return componentsBefore.every(T);
56
+ return componentsBefore.every(Boolean);
57
57
  }, []);
58
58
 
59
59
  const dispatch = React.useCallback(({ payload }) => {
@@ -13,10 +13,7 @@ import { useCurrentScreenData } from "@applicaster/zapp-react-native-utils/react
13
13
  import { useShallow } from "zustand/react/shallow";
14
14
  import { useScreenContextV2 } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
15
15
  import { useSafeAreaInsets } from "react-native-safe-area-context";
16
- import {
17
- ZappPipes,
18
- useAppDispatch,
19
- } from "@applicaster/zapp-react-native-redux";
16
+ import { useLoadPipesDataDispatch } from "@applicaster/zapp-react-native-utils/reactHooks";
20
17
 
21
18
  const BRIGHTNESS_THRESHOLD = 160;
22
19
  const ABOVE_DEFAULT_COLOR = "gray";
@@ -63,38 +60,33 @@ export const usePullToRefresh = (
63
60
  ) => {
64
61
  const isPipesV1 = !!pullToRefreshPipesV1RefreshingStateUpdater;
65
62
 
66
- const dispatch = useAppDispatch();
67
-
68
63
  const [refreshing, setRefreshing] = React.useState(false);
69
64
 
70
65
  const feeds: string[] =
71
66
  riverComponents?.map(R.path(["data", "source"])).filter((feed) => !!feed) ??
72
67
  [];
73
68
 
74
- const screenData = useCurrentScreenData();
75
-
76
69
  const feedsLength = feeds.length;
77
70
 
78
71
  const [requestsCompletedCounter, setRequestsCompletedCounter] =
79
72
  React.useState(0);
80
73
 
74
+ const loadPipesDataDispatcher = useLoadPipesDataDispatch();
75
+
81
76
  React.useEffect(() => {
82
77
  // will not work for pipes v1 on 1st level screens
83
78
  if (refreshing && !isPipesV1) {
84
79
  feeds.forEach((feed) => {
85
- dispatch(
86
- ZappPipes.loadPipesData(feed, {
87
- silentRefresh: true,
88
- clearCache: true,
89
- callback: () => {
90
- setRequestsCompletedCounter(R.inc);
91
- },
92
- riverId: screenData.id,
93
- })
94
- );
80
+ loadPipesDataDispatcher(feed, {
81
+ silentRefresh: true,
82
+ clearCache: true,
83
+ callback: () => {
84
+ setRequestsCompletedCounter(R.inc);
85
+ },
86
+ });
95
87
  });
96
88
  }
97
- }, [refreshing, isPipesV1]);
89
+ }, [refreshing, isPipesV1, feeds, loadPipesDataDispatcher]);
98
90
 
99
91
  React.useEffect(() => {
100
92
  if (requestsCompletedCounter === feedsLength) {