@applicaster/zapp-react-native-ui-components 14.0.0-alpha.4552519200 → 14.0.0-alpha.4596155133

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 (84) hide show
  1. package/Components/AudioPlayer/mobile/Layout.tsx +1 -1
  2. package/Components/AudioPlayer/tv/Artwork.tsx +3 -2
  3. package/Components/AudioPlayer/tv/Channel.tsx +7 -7
  4. package/Components/AudioPlayer/tv/Layout.tsx +100 -93
  5. package/Components/AudioPlayer/tv/Runtime.tsx +7 -1
  6. package/Components/AudioPlayer/tv/Summary.tsx +6 -2
  7. package/Components/AudioPlayer/tv/Title.tsx +6 -2
  8. package/Components/AudioPlayer/tv/__tests__/__snapshots__/Runtime.test.js.snap +2 -2
  9. package/Components/AudioPlayer/tv/__tests__/__snapshots__/audioPlayer.test.js.snap +20 -26
  10. package/Components/AudioPlayer/tv/__tests__/__snapshots__/channel.test.js.snap +8 -17
  11. package/Components/AudioPlayer/tv/__tests__/__snapshots__/summary.test.js.snap +1 -2
  12. package/Components/AudioPlayer/tv/__tests__/__snapshots__/title.test.js.snap +1 -2
  13. package/Components/AudioPlayer/tv/helpers.tsx +10 -3
  14. package/Components/AudioPlayer/tv/index.tsx +6 -0
  15. package/Components/Cell/index.js +7 -3
  16. package/Components/ComponentResolver/index.ts +1 -1
  17. package/Components/FeedLoader/index.js +1 -1
  18. package/Components/Focusable/Focusable.tsx +5 -3
  19. package/Components/Focusable/FocusableiOS.tsx +2 -2
  20. package/Components/Focusable/__tests__/index.android.test.tsx +3 -0
  21. package/Components/Focusable/index.android.tsx +12 -8
  22. package/Components/Focusable/index.tsx +1 -1
  23. package/Components/FocusableList/index.tsx +4 -0
  24. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +42 -59
  25. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +12 -8
  26. package/Components/HandlePlayable/HandlePlayable.tsx +11 -1
  27. package/Components/Layout/TV/LayoutBackground.tsx +1 -1
  28. package/Components/MasterCell/DefaultComponents/Button.tsx +1 -1
  29. package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -27
  30. package/Components/MasterCell/DefaultComponents/Image/hoc/withDimensions.tsx +1 -1
  31. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +1 -1
  32. package/Components/MasterCell/index.tsx +1 -1
  33. package/Components/MasterCell/utils/behaviorProvider.ts +82 -14
  34. package/Components/MasterCell/utils/index.ts +27 -3
  35. package/Components/OfflineHandler/__tests__/index.test.tsx +20 -22
  36. package/Components/PlayerContainer/ErrorDisplay/index.ts +1 -1
  37. package/Components/PlayerContainer/PlayerContainer.tsx +15 -8
  38. package/Components/PlayerContainer/ProgramInfo/index.tsx +1 -1
  39. package/Components/PlayerContainer/index.ts +1 -1
  40. package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +379 -0
  41. package/Components/River/ComponentsMap/hooks/useLoadingState.ts +2 -2
  42. package/Components/River/RefreshControl.tsx +6 -4
  43. package/Components/River/TV/River.tsx +2 -17
  44. package/Components/River/TV/index.tsx +3 -1
  45. package/Components/River/TV/withPipesV1DataLoader.tsx +43 -0
  46. package/Components/River/TV/withRiverDataLoader.tsx +17 -0
  47. package/Components/River/index.tsx +1 -1
  48. package/Components/Screen/__tests__/Screen.test.tsx +23 -12
  49. package/Components/ScreenRevealManager/ScreenRevealManager.ts +76 -0
  50. package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +107 -0
  51. package/Components/ScreenRevealManager/__tests__/withScreenRevealManager.test.tsx +96 -0
  52. package/Components/ScreenRevealManager/index.ts +1 -0
  53. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +79 -0
  54. package/Components/Tabs/TV/Tabs.android.tsx +0 -2
  55. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +32 -8
  56. package/Components/VideoModal/PlayerDetails.tsx +24 -2
  57. package/Components/VideoModal/PlayerWrapper.tsx +26 -142
  58. package/Components/VideoModal/VideoModal.tsx +3 -17
  59. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +1 -7
  60. package/Components/VideoModal/__tests__/__snapshots__/PlayerWrapper.test.tsx.snap +44 -240
  61. package/Components/VideoModal/hooks/index.ts +0 -2
  62. package/Components/VideoModal/hooks/useModalSize.ts +18 -2
  63. package/Components/VideoModal/utils.ts +6 -0
  64. package/Components/Viewport/VisibilitySensor/VisibilitySensor.tsx +3 -3
  65. package/Components/default-cell-renderer/viewTrees/tv/DefaultCell/index.ts +3 -3
  66. package/Contexts/ScreenContext/index.tsx +44 -0
  67. package/Decorators/RiverFeedLoader/index.tsx +12 -2
  68. package/Decorators/RiverFeedLoader/utils/index.ts +19 -2
  69. package/Decorators/RiverResolver/__tests__/riverResolver.test.tsx +3 -6
  70. package/Decorators/ZappPipesDataConnector/ResolverSelector.tsx +25 -0
  71. package/Decorators/ZappPipesDataConnector/__tests__/NullFeedResolver.test.tsx +78 -0
  72. package/Decorators/ZappPipesDataConnector/__tests__/ResolverSelector.test.tsx +205 -0
  73. package/Decorators/ZappPipesDataConnector/__tests__/StaticFeedResolver.test.tsx +251 -0
  74. package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +368 -0
  75. package/Decorators/ZappPipesDataConnector/__tests__/utils.test.ts +39 -0
  76. package/Decorators/ZappPipesDataConnector/index.tsx +26 -293
  77. package/Decorators/ZappPipesDataConnector/resolvers/NullFeedResolver.tsx +25 -0
  78. package/Decorators/ZappPipesDataConnector/resolvers/StaticFeedResolver.tsx +87 -0
  79. package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +268 -0
  80. package/Decorators/ZappPipesDataConnector/types.ts +29 -0
  81. package/Decorators/ZappPipesDataConnector/utils/mongoFilter.ts +738 -0
  82. package/Decorators/ZappPipesDataConnector/utils/useFilter.tsx +162 -0
  83. package/package.json +5 -9
  84. package/Components/VideoModal/hooks/useBackgroundColor.ts +0 -10
@@ -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,8 +192,18 @@ export const getFocusedButtonId = (focusable) => {
190
192
  });
191
193
  };
192
194
 
193
- export const isSelected = (item: ZappEntry, behavior?: Behavior) => {
194
- return isCellSelected(item, behavior);
195
+ export const isSelected = ({
196
+ item,
197
+ screenRoute,
198
+ screenStateStore,
199
+ behavior,
200
+ }: {
201
+ item: ZappEntry;
202
+ screenRoute: string;
203
+ screenStateStore: ScreenStateStore;
204
+ behavior?: Behavior;
205
+ }) => {
206
+ return isCellSelected({ item, screenRoute, screenStateStore, behavior });
195
207
  };
196
208
 
197
209
  export const useCellState = ({
@@ -204,9 +216,21 @@ export const useCellState = ({
204
216
  focused: boolean;
205
217
  }): CellState => {
206
218
  const lastUpdate = useBehaviorUpdate(behavior);
219
+ const router = useRoute();
220
+ /** Could be replaced with existing store from useScreenContextV2
221
+ * const screenContextV2 = useScreenContextV2();
222
+ const screenStateStore = screenContextV2._stateStore();
223
+ */
224
+ const screenStateStore = useScreenStateStore();
207
225
 
208
226
  const _isSelected = useMemo(
209
- () => isSelected(item, behavior),
227
+ () =>
228
+ isSelected({
229
+ item,
230
+ screenRoute: router?.pathname,
231
+ screenStateStore,
232
+ behavior,
233
+ }),
210
234
  [behavior, item, lastUpdate]
211
235
  );
212
236
 
@@ -19,29 +19,27 @@ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/utils", () => {
19
19
  };
20
20
  });
21
21
 
22
- jest.mock(
23
- "@applicaster/zapp-react-native-redux/hooks/usePickFromState",
24
- () => ({
25
- usePickFromState: () => ({
26
- plugins: [
27
- {
28
- name: "offline experience",
29
- identifier: "offline-experience",
30
- type: "general",
31
- module: {
32
- useOfflineExperienceConfiguration: () => ({
33
- configurationFields: {},
34
- localizations: {
35
- offline_toast_message: "No internet connection",
36
- online_toast_message: "You are back online",
37
- },
38
- }),
39
- },
22
+ jest.mock("@applicaster/zapp-react-native-redux/hooks", () => ({
23
+ ...jest.requireActual("@applicaster/zapp-react-native-redux/hooks"),
24
+ usePickFromState: () => ({
25
+ plugins: [
26
+ {
27
+ name: "offline experience",
28
+ identifier: "offline-experience",
29
+ type: "general",
30
+ module: {
31
+ useOfflineExperienceConfiguration: () => ({
32
+ configurationFields: {},
33
+ localizations: {
34
+ offline_toast_message: "No internet connection",
35
+ online_toast_message: "You are back online",
36
+ },
37
+ }),
40
38
  },
41
- ],
42
- }),
43
- })
44
- );
39
+ },
40
+ ],
41
+ }),
42
+ }));
45
43
 
46
44
  jest.mock("react-native-safe-area-context", () => ({
47
45
  useSafeAreaInsets: () => ({ top: 44 }),
@@ -1,6 +1,6 @@
1
1
  import * as R from "ramda";
2
2
 
3
- import { connectToStore } from "@applicaster/zapp-react-native-redux";
3
+ import { connectToStore } from "@applicaster/zapp-react-native-redux/utils/connectToStore";
4
4
 
5
5
  import { ErrorDisplayComponent } from "./ErrorDisplay";
6
6
 
@@ -92,7 +92,7 @@ export const VideoModalMode = {
92
92
  MAXIMIZED: "MAXIMIZED",
93
93
  MINIMIZED: "MINIMIZED",
94
94
  FULLSCREEN: "FULLSCREEN",
95
- };
95
+ } as const;
96
96
 
97
97
  export type PlayNextData = {
98
98
  state: PlayNextState;
@@ -131,7 +131,7 @@ const webStyles = {
131
131
  playerScreen: {
132
132
  flex: 1,
133
133
  height: "100vh",
134
- background: "black",
134
+ backgroundColor: "black",
135
135
  },
136
136
  playerWrapper: {
137
137
  height: "100%",
@@ -149,7 +149,6 @@ const nativeStyles = {
149
149
  },
150
150
  playerScreen: {
151
151
  flex: 1,
152
- backgroundColor: "black",
153
152
  overflow: "hidden",
154
153
  },
155
154
  playerWrapper: {
@@ -405,8 +404,6 @@ const PlayerContainerComponent = (props: Props) => {
405
404
  (event) => {
406
405
  const { eventType } = event;
407
406
 
408
- console.log("PlayerContainer: playerRemoteHandler", eventType);
409
-
410
407
  if (!isLanguageOverlayVisible && eventType === "menu") {
411
408
  close();
412
409
  }
@@ -571,8 +568,9 @@ const PlayerContainerComponent = (props: Props) => {
571
568
  const isInlineTV = isInlineTVUtil(screenData);
572
569
 
573
570
  const inline =
574
- [VideoModalMode.MAXIMIZED, VideoModalMode.MINIMIZED].includes(mode) ||
575
- isInlineTV;
571
+ [VideoModalMode.MAXIMIZED, VideoModalMode.MINIMIZED].includes(
572
+ mode as any
573
+ ) || isInlineTV;
576
574
 
577
575
  const value = React.useMemo(
578
576
  () => ({ playerId: state.playerId }),
@@ -593,7 +591,11 @@ const PlayerContainerComponent = (props: Props) => {
593
591
  );
594
592
  }
595
593
 
596
- if (screen_background_color && mode !== VideoModalMode.FULLSCREEN) {
594
+ if (
595
+ screen_background_color &&
596
+ mode !== VideoModalMode.FULLSCREEN &&
597
+ isTV()
598
+ ) {
597
599
  updatedStyles.playerScreen.backgroundColor = screen_background_color;
598
600
  }
599
601
 
@@ -623,6 +625,8 @@ const PlayerContainerComponent = (props: Props) => {
623
625
  playNextData,
624
626
  };
625
627
 
628
+ const pointerEventsProp = mode === "MINIMIZED" ? "box-none" : "auto";
629
+
626
630
  return (
627
631
  <PlayerStateContext.Provider value={value}>
628
632
  <PlayerContainerContextProvider
@@ -643,14 +647,17 @@ const PlayerContainerComponent = (props: Props) => {
643
647
  preferredFocus
644
648
  shouldUsePreferredFocus
645
649
  groupId={groupId}
650
+ pointerEvents={pointerEventsProp}
646
651
  >
647
652
  {/* Video player and components */}
648
653
  <View
649
654
  style={styles.playerScreen}
650
655
  testID={"player-screen-container"}
656
+ pointerEvents={pointerEventsProp}
651
657
  >
652
658
  {/* Player container */}
653
659
  <View
660
+ pointerEvents={pointerEventsProp}
654
661
  style={[
655
662
  styles.playerWrapper,
656
663
  // eslint-disable-next-line react-native/no-inline-styles, react-native/no-color-literals
@@ -1,4 +1,4 @@
1
- import { connectToStore } from "@applicaster/zapp-react-native-redux";
1
+ import { connectToStore } from "@applicaster/zapp-react-native-redux/utils/connectToStore";
2
2
  import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
3
3
  import { styleKeys } from "@applicaster/zapp-react-native-utils/styleKeysUtils";
4
4
  import { transformColorCode as fixColorHexCode } from "@applicaster/zapp-react-native-utils/transform";
@@ -1,6 +1,6 @@
1
1
  import * as R from "ramda";
2
2
 
3
- import { connectToStore } from "@applicaster/zapp-react-native-redux";
3
+ import { connectToStore } from "@applicaster/zapp-react-native-redux/utils/connectToStore";
4
4
  import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
5
5
 
6
6
  import { PlayerContainer as PlayerContainerComponent } from "./PlayerContainer";
@@ -0,0 +1,379 @@
1
+ import { renderHook, act } from "@testing-library/react-hooks";
2
+ import { BehaviorSubject } from "rxjs";
3
+ import { useLoadingState } from "../useLoadingState";
4
+
5
+ // Mock the useRefWithInitialValue hook
6
+ jest.mock(
7
+ "@applicaster/zapp-react-native-utils/reactHooks/state/useRefWithInitialValue",
8
+ () => ({
9
+ useRefWithInitialValue: jest.fn((initializer) => ({
10
+ current: initializer(),
11
+ })),
12
+ })
13
+ );
14
+
15
+ describe("useLoadingState", () => {
16
+ let onLoadDone: jest.Mock;
17
+
18
+ beforeEach(() => {
19
+ onLoadDone = jest.fn();
20
+ jest.clearAllMocks();
21
+ });
22
+
23
+ describe("initialization", () => {
24
+ it("should initialize with correct default state for zero components", () => {
25
+ const { result } = renderHook(() => useLoadingState(0, onLoadDone));
26
+
27
+ const initialState = result.current.loadingState.getValue();
28
+
29
+ expect(initialState).toEqual({
30
+ index: -1,
31
+ done: true,
32
+ waitForAllComponents: false,
33
+ });
34
+
35
+ expect(result.current.shouldShowLoadingError).toBe(false);
36
+ });
37
+
38
+ it("should initialize with correct default state for multiple components", () => {
39
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
40
+
41
+ const initialState = result.current.loadingState.getValue();
42
+
43
+ expect(initialState).toEqual({
44
+ index: -1,
45
+ done: false,
46
+ waitForAllComponents: false,
47
+ });
48
+
49
+ expect(result.current.shouldShowLoadingError).toBe(false);
50
+ });
51
+
52
+ it("should return a BehaviorSubject for loadingState", () => {
53
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
54
+
55
+ expect(result.current.loadingState).toBeInstanceOf(BehaviorSubject);
56
+ });
57
+ });
58
+
59
+ describe("arePreviousComponentsLoaded", () => {
60
+ it("should return true for index 0 (first component)", () => {
61
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
62
+
63
+ expect(result.current.arePreviousComponentsLoaded(0)).toBe(true);
64
+ });
65
+
66
+ it("should return false when previous components are not loaded", () => {
67
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
68
+
69
+ expect(result.current.arePreviousComponentsLoaded(1)).toBe(false);
70
+ expect(result.current.arePreviousComponentsLoaded(2)).toBe(false);
71
+ });
72
+
73
+ it("should return true when all previous components are loaded", () => {
74
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
75
+
76
+ act(() => {
77
+ result.current.onLoadFinished(0);
78
+ });
79
+
80
+ expect(result.current.arePreviousComponentsLoaded(1)).toBe(true);
81
+ expect(result.current.arePreviousComponentsLoaded(2)).toBe(false);
82
+
83
+ act(() => {
84
+ result.current.onLoadFinished(1);
85
+ });
86
+
87
+ expect(result.current.arePreviousComponentsLoaded(2)).toBe(true);
88
+ });
89
+ });
90
+
91
+ describe("onLoadFinished", () => {
92
+ it("should update component state and loading state when component finishes loading", () => {
93
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
94
+
95
+ act(() => {
96
+ result.current.onLoadFinished(0);
97
+ });
98
+
99
+ const state = result.current.loadingState.getValue();
100
+ expect(state.index).toBe(0);
101
+ expect(state.done).toBe(false);
102
+ });
103
+
104
+ it("should update index to highest loaded component", () => {
105
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
106
+
107
+ act(() => {
108
+ result.current.onLoadFinished(2);
109
+ });
110
+
111
+ let state = result.current.loadingState.getValue();
112
+ expect(state.index).toBe(2);
113
+
114
+ act(() => {
115
+ result.current.onLoadFinished(1);
116
+ });
117
+
118
+ state = result.current.loadingState.getValue();
119
+ expect(state.index).toBe(2); // Should remain 2, not decrease to 1
120
+ });
121
+
122
+ it("should mark as done when all components are loaded", () => {
123
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
124
+
125
+ act(() => {
126
+ result.current.onLoadFinished(0);
127
+ });
128
+
129
+ let state = result.current.loadingState.getValue();
130
+ expect(state.done).toBe(true); // True because arePreviousComponentsLoaded(1) returns true when component 0 is loaded
131
+ expect(onLoadDone).toHaveBeenCalledTimes(1);
132
+
133
+ act(() => {
134
+ result.current.onLoadFinished(1);
135
+ });
136
+
137
+ state = result.current.loadingState.getValue();
138
+ expect(state.done).toBe(true);
139
+ expect(onLoadDone).toHaveBeenCalledTimes(2); // Called again
140
+ });
141
+
142
+ it("should call onLoadDone when count is 0", () => {
143
+ const { result } = renderHook(() => useLoadingState(0, onLoadDone));
144
+
145
+ const state = result.current.loadingState.getValue();
146
+ expect(state.done).toBe(true);
147
+ // onLoadDone is not called on initialization for count 0, only when all components are loaded via dispatch
148
+ });
149
+
150
+ it("should handle loading components out of order", () => {
151
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
152
+
153
+ // Load component 2 first
154
+ act(() => {
155
+ result.current.onLoadFinished(2);
156
+ });
157
+
158
+ let state = result.current.loadingState.getValue();
159
+ expect(state.done).toBe(false);
160
+
161
+ // Load component 0
162
+ act(() => {
163
+ result.current.onLoadFinished(0);
164
+ });
165
+
166
+ state = result.current.loadingState.getValue();
167
+ expect(state.done).toBe(false);
168
+
169
+ // Load component 1 - should complete loading
170
+ act(() => {
171
+ result.current.onLoadFinished(1);
172
+ });
173
+
174
+ state = result.current.loadingState.getValue();
175
+ expect(state.done).toBe(true);
176
+ expect(onLoadDone).toHaveBeenCalledTimes(1);
177
+ });
178
+
179
+ it("should call onLoadDone again on subsequent dispatches", () => {
180
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
181
+
182
+ act(() => {
183
+ result.current.onLoadFinished(0);
184
+ result.current.onLoadFinished(1);
185
+ });
186
+
187
+ expect(onLoadDone).toHaveBeenCalledTimes(2); // Called for each dispatch when done is true
188
+
189
+ // Try loading again - onLoadDone will be called again because dispatch runs again
190
+ act(() => {
191
+ result.current.onLoadFinished(0);
192
+ });
193
+
194
+ expect(onLoadDone).toHaveBeenCalledTimes(3); // Will be called again
195
+ });
196
+ });
197
+
198
+ describe("onLoadFailed", () => {
199
+ it("should treat failed components as loaded when SHOULD_FAIL_ON_COMPONENT_LOADING is false", () => {
200
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
201
+
202
+ const error = new Error("Load failed");
203
+
204
+ act(() => {
205
+ result.current.onLoadFailed({ error, index: 0 });
206
+ });
207
+
208
+ const state = result.current.loadingState.getValue();
209
+ expect(state.index).toBe(0);
210
+ expect(result.current.shouldShowLoadingError).toBe(false);
211
+ });
212
+
213
+ it("should complete loading when all components fail", () => {
214
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
215
+
216
+ const error = new Error("Load failed");
217
+
218
+ act(() => {
219
+ result.current.onLoadFailed({ error, index: 0 });
220
+ result.current.onLoadFailed({ error, index: 1 });
221
+ });
222
+
223
+ const state = result.current.loadingState.getValue();
224
+ expect(state.done).toBe(true);
225
+ expect(onLoadDone).toHaveBeenCalledTimes(2); // Called for each failed component
226
+ });
227
+
228
+ it("should handle mixed success and failure", () => {
229
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone));
230
+
231
+ const error = new Error("Load failed");
232
+
233
+ act(() => {
234
+ result.current.onLoadFinished(0);
235
+ result.current.onLoadFailed({ error, index: 1 });
236
+ result.current.onLoadFinished(2);
237
+ });
238
+
239
+ const state = result.current.loadingState.getValue();
240
+ expect(state.done).toBe(true);
241
+ expect(onLoadDone).toHaveBeenCalledTimes(2); // Called when all components 0,1,2 are handled
242
+ });
243
+ });
244
+
245
+ describe("loading state observable", () => {
246
+ it("should emit state changes through BehaviorSubject", () => {
247
+ const { result } = renderHook(() => useLoadingState(3, onLoadDone)); // Use 3 components so loading component 0 doesn't complete everything
248
+ const mockSubscriber = jest.fn();
249
+
250
+ result.current.loadingState.subscribe(mockSubscriber);
251
+
252
+ act(() => {
253
+ result.current.onLoadFinished(0);
254
+ });
255
+
256
+ // Should have been called twice: initial state + update
257
+ expect(mockSubscriber).toHaveBeenCalledTimes(2);
258
+
259
+ expect(mockSubscriber).toHaveBeenLastCalledWith({
260
+ index: 0,
261
+ done: false, // Will be false because we need components 1 and 2 as well
262
+ waitForAllComponents: false,
263
+ });
264
+ });
265
+
266
+ it("should preserve waitForAllComponents flag in state updates", () => {
267
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
268
+
269
+ act(() => {
270
+ result.current.onLoadFinished(0);
271
+ });
272
+
273
+ const state = result.current.loadingState.getValue();
274
+ expect(state.waitForAllComponents).toBe(false);
275
+ });
276
+ });
277
+
278
+ describe("memoization", () => {
279
+ it("should return stable references for functions", () => {
280
+ const { result, rerender } = renderHook(() =>
281
+ useLoadingState(2, onLoadDone)
282
+ );
283
+
284
+ const firstRender = {
285
+ onLoadFinished: result.current.onLoadFinished,
286
+ onLoadFailed: result.current.onLoadFailed,
287
+ arePreviousComponentsLoaded: result.current.arePreviousComponentsLoaded,
288
+ };
289
+
290
+ rerender();
291
+
292
+ expect(result.current.onLoadFinished).toBe(firstRender.onLoadFinished);
293
+ expect(result.current.onLoadFailed).toBe(firstRender.onLoadFailed);
294
+
295
+ expect(result.current.arePreviousComponentsLoaded).toBe(
296
+ firstRender.arePreviousComponentsLoaded
297
+ );
298
+ });
299
+
300
+ it("should return stable function references (current behavior)", () => {
301
+ const { result, rerender } = renderHook(
302
+ ({ onLoadDone }) => useLoadingState(2, onLoadDone),
303
+ { initialProps: { onLoadDone } }
304
+ );
305
+
306
+ const firstResult = result.current;
307
+
308
+ const newOnLoadDone = jest.fn();
309
+ rerender({ onLoadDone: newOnLoadDone });
310
+
311
+ // Functions should remain the same due to empty dependency arrays (this is the current behavior)
312
+ expect(result.current.onLoadFinished).toBe(firstResult.onLoadFinished);
313
+ expect(result.current.onLoadFailed).toBe(firstResult.onLoadFailed);
314
+ });
315
+ });
316
+
317
+ describe("edge cases", () => {
318
+ it("should handle duplicate load finished calls gracefully", () => {
319
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
320
+
321
+ act(() => {
322
+ result.current.onLoadFinished(0);
323
+ result.current.onLoadFinished(0); // Duplicate call
324
+ });
325
+
326
+ const state = result.current.loadingState.getValue();
327
+ expect(state.index).toBe(0);
328
+ expect(state.done).toBe(true); // True because loading component 0 makes it done in a 2-component setup
329
+ });
330
+
331
+ it("should handle loading index greater than component count", () => {
332
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
333
+
334
+ act(() => {
335
+ result.current.onLoadFinished(5); // Index out of bounds
336
+ });
337
+
338
+ const state = result.current.loadingState.getValue();
339
+ expect(state.index).toBe(5);
340
+ expect(state.done).toBe(false); // Should not be done as not all components loaded
341
+ });
342
+
343
+ it("should handle negative indices", () => {
344
+ const { result } = renderHook(() => useLoadingState(2, onLoadDone));
345
+
346
+ act(() => {
347
+ result.current.onLoadFinished(-1);
348
+ });
349
+
350
+ const state = result.current.loadingState.getValue();
351
+ expect(state.index).toBe(-1); // Should remain -1
352
+ });
353
+ });
354
+
355
+ describe("component count changes", () => {
356
+ it("should handle changing component count", () => {
357
+ const { result, rerender } = renderHook(
358
+ ({ count }) => useLoadingState(count, onLoadDone),
359
+ { initialProps: { count: 2 } }
360
+ );
361
+
362
+ act(() => {
363
+ result.current.onLoadFinished(0);
364
+ });
365
+
366
+ // Change count
367
+ rerender({ count: 3 });
368
+
369
+ // The hook should work with the new count
370
+ act(() => {
371
+ result.current.onLoadFinished(1);
372
+ result.current.onLoadFinished(2);
373
+ });
374
+
375
+ const state = result.current.loadingState.getValue();
376
+ expect(state.done).toBe(true);
377
+ });
378
+ });
379
+ });
@@ -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 }) => {
@@ -10,11 +10,13 @@ import { useLocalizedStrings } from "@applicaster/zapp-react-native-utils/locali
10
10
  import { useAnalytics } from "@applicaster/zapp-react-native-utils/analyticsUtils";
11
11
  import { useSendAnalyticsEventWithFunction } from "@applicaster/zapp-react-native-utils/analyticsUtils/helpers/hooks";
12
12
  import { useCurrentScreenData } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useCurrentScreenData";
13
- import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
14
- import { useDispatch } from "react-redux";
15
13
  import { useShallow } from "zustand/react/shallow";
16
14
  import { useScreenContextV2 } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
17
15
  import { useSafeAreaInsets } from "react-native-safe-area-context";
16
+ import {
17
+ ZappPipes,
18
+ useAppDispatch,
19
+ } from "@applicaster/zapp-react-native-redux";
18
20
 
19
21
  const BRIGHTNESS_THRESHOLD = 160;
20
22
  const ABOVE_DEFAULT_COLOR = "gray";
@@ -61,7 +63,7 @@ export const usePullToRefresh = (
61
63
  ) => {
62
64
  const isPipesV1 = !!pullToRefreshPipesV1RefreshingStateUpdater;
63
65
 
64
- const dispatch = useDispatch();
66
+ const dispatch = useAppDispatch();
65
67
 
66
68
  const [refreshing, setRefreshing] = React.useState(false);
67
69
 
@@ -81,7 +83,7 @@ export const usePullToRefresh = (
81
83
  if (refreshing && !isPipesV1) {
82
84
  feeds.forEach((feed) => {
83
85
  dispatch(
84
- loadPipesData(feed, {
86
+ ZappPipes.loadPipesData(feed, {
85
87
  silentRefresh: true,
86
88
  clearCache: true,
87
89
  callback: () => {