@applicaster/zapp-react-native-ui-components 14.0.0-rc.9 → 15.0.0-alpha.1456157166
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.
- package/Components/AnimatedInOut/index.tsx +5 -3
- package/Components/AudioPlayer/index.tsx +15 -0
- package/Components/AudioPlayer/mobile/Layout.tsx +66 -0
- package/Components/AudioPlayer/{__tests__/__snapshots__/audioPlayer.test.js.snap → mobile/__tests__/__snapshots__/audioPlayerMobileLayout.test.js.snap} +2 -2
- package/Components/AudioPlayer/mobile/__tests__/audioPlayerMobileLayout.test.js +18 -0
- package/Components/AudioPlayer/mobile/index.tsx +18 -0
- package/Components/AudioPlayer/{Artwork.tsx → tv/Artwork.tsx} +3 -2
- package/Components/AudioPlayer/{Channel.tsx → tv/Channel.tsx} +7 -7
- package/Components/AudioPlayer/tv/Layout.tsx +168 -0
- package/Components/AudioPlayer/{Runtime.tsx → tv/Runtime.tsx} +7 -1
- package/Components/AudioPlayer/{Summary.tsx → tv/Summary.tsx} +6 -2
- package/Components/AudioPlayer/{Title.tsx → tv/Title.tsx} +6 -2
- package/Components/AudioPlayer/{__tests__ → tv/__tests__}/__snapshots__/Runtime.test.js.snap +2 -2
- package/Components/AudioPlayer/tv/__tests__/__snapshots__/audioPlayer.test.js.snap +164 -0
- package/Components/AudioPlayer/tv/__tests__/__snapshots__/channel.test.js.snap +19 -0
- package/Components/AudioPlayer/{__tests__ → tv/__tests__}/__snapshots__/summary.test.js.snap +1 -2
- package/Components/AudioPlayer/{__tests__ → tv/__tests__}/__snapshots__/title.test.js.snap +1 -2
- package/Components/AudioPlayer/{__tests__ → tv/__tests__}/audioPlayer.test.js +7 -3
- package/Components/AudioPlayer/{helpers.tsx → tv/helpers.tsx} +11 -5
- package/Components/AudioPlayer/{AudioPlayer.tsx → tv/index.tsx} +17 -58
- package/Components/AudioPlayer/types.ts +40 -0
- package/Components/BaseFocusable/index.tsx +23 -12
- package/Components/Cell/Cell.tsx +91 -64
- package/Components/Cell/CellWithFocusable.tsx +3 -0
- package/Components/Cell/__tests__/CellWIthFocusable.test.js +3 -2
- package/Components/Cell/index.js +7 -3
- package/Components/ComponentResolver/index.ts +1 -1
- package/Components/FeedLoader/FeedLoader.tsx +7 -16
- package/Components/FeedLoader/FeedLoaderHOC.tsx +21 -0
- package/Components/FeedLoader/index.js +2 -8
- package/Components/Focusable/Focusable.tsx +12 -3
- package/Components/Focusable/FocusableTvOS.tsx +5 -5
- package/Components/Focusable/FocusableiOS.tsx +2 -2
- package/Components/Focusable/Touchable.tsx +5 -3
- package/Components/Focusable/__tests__/index.android.test.tsx +3 -0
- package/Components/Focusable/index.android.tsx +19 -11
- package/Components/Focusable/index.tsx +1 -1
- package/Components/FocusableGroup/FocusableTvOS.tsx +1 -1
- package/Components/FocusableList/FocusableItem.tsx +4 -3
- package/Components/FocusableList/FocusableListItemWrapper.tsx +2 -1
- package/Components/FocusableList/hooks/useCellState.android.ts +13 -3
- package/Components/FocusableList/index.tsx +20 -9
- package/Components/FreezeWithCallback/__tests__/index.test.tsx +67 -43
- package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +42 -59
- package/Components/GeneralContentScreen/utils/useCurationAPI.ts +22 -21
- package/Components/HandlePlayable/HandlePlayable.tsx +25 -9
- package/Components/HookRenderer/HookRenderer.tsx +5 -1
- package/Components/Layout/TV/LayoutBackground.tsx +1 -1
- package/Components/Layout/TV/__tests__/index.test.tsx +0 -1
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +6 -2
- package/Components/MasterCell/DefaultComponents/Button.tsx +1 -1
- package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -39
- package/Components/MasterCell/DefaultComponents/Image/hoc/withDimensions.tsx +1 -1
- package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +1 -1
- package/Components/MasterCell/DefaultComponents/SecondaryImage/Image.tsx +65 -17
- package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/Image.test.tsx +21 -3
- package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/__snapshots__/Image.test.tsx.snap +6 -3
- package/Components/MasterCell/DefaultComponents/Text/index.tsx +26 -6
- package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +10 -10
- package/Components/MasterCell/DefaultComponents/__tests__/text.test.tsx +18 -18
- package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/index.test.tsx +10 -10
- package/Components/MasterCell/elementMapper.tsx +1 -2
- package/Components/MasterCell/index.tsx +1 -1
- package/Components/MasterCell/utils/behaviorProvider.ts +82 -14
- package/Components/MasterCell/utils/index.ts +11 -5
- package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +13 -18
- package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +9 -0
- package/Components/OfflineHandler/__tests__/index.test.tsx +26 -35
- package/Components/PlayerContainer/ErrorDisplay/index.ts +1 -1
- package/Components/PlayerContainer/PlayerContainer.tsx +46 -33
- package/Components/PlayerContainer/ProgramInfo/index.tsx +1 -1
- package/Components/PlayerContainer/index.ts +1 -1
- package/Components/PlayerImageBackground/index.tsx +1 -1
- package/Components/River/ComponentsMap/ComponentsMap.tsx +49 -43
- package/Components/River/ComponentsMap/ContextProviders/ComponentsMapHeightContext.ts +8 -0
- package/Components/River/ComponentsMap/ContextProviders/ComponentsMapRefContext.ts +8 -0
- package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +378 -0
- package/Components/River/ComponentsMap/hooks/useLoadingState.ts +2 -2
- package/Components/River/RefreshControl.tsx +11 -17
- package/Components/River/RiverItem.tsx +3 -0
- package/Components/River/TV/River.tsx +2 -17
- package/Components/River/TV/index.tsx +3 -1
- package/Components/River/TV/withPipesV1DataLoader.tsx +43 -0
- package/Components/River/TV/withRiverDataLoader.tsx +17 -0
- package/Components/River/TV/withTVEventHandler.tsx +1 -1
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +2 -0
- package/Components/River/__tests__/river.test.js +12 -26
- package/Components/River/index.tsx +1 -1
- package/Components/Screen/__tests__/Screen.test.tsx +28 -29
- package/Components/Screen/__tests__/navigationHandler.test.ts +133 -22
- package/Components/Screen/navigationHandler.ts +20 -2
- package/Components/ScreenResolver/index.tsx +15 -0
- package/Components/ScreenRevealManager/ScreenRevealManager.ts +76 -0
- package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +107 -0
- package/Components/ScreenRevealManager/__tests__/withScreenRevealManager.test.tsx +96 -0
- package/Components/ScreenRevealManager/index.ts +1 -0
- package/Components/ScreenRevealManager/withScreenRevealManager.tsx +79 -0
- package/Components/Tabs/TV/Tabs.android.tsx +1 -3
- package/Components/Tabs/Tabs.tsx +2 -3
- package/Components/TextInputTv/__tests__/__snapshots__/TextInputTv.test.js.snap +13 -0
- package/Components/TextInputTv/index.tsx +11 -0
- package/Components/Touchable/__tests__/__snapshots__/touchable.test.tsx.snap +34 -0
- package/Components/Touchable/__tests__/touchable.test.tsx +12 -17
- package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +15 -9
- package/Components/VideoLive/animationUtils.ts +3 -3
- package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +6 -10
- package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.web.tsx +294 -0
- package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.web.tsx +93 -0
- package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +73 -29
- package/Components/VideoModal/PlayerDetails.tsx +29 -7
- package/Components/VideoModal/PlayerWrapper.tsx +26 -142
- package/Components/VideoModal/VideoModal.tsx +3 -17
- package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +5 -5
- package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +1 -7
- package/Components/VideoModal/__tests__/__snapshots__/PlayerWrapper.test.tsx.snap +44 -240
- package/Components/VideoModal/hooks/__tests__/useDelayedPlayerDetails.test.ts +9 -1
- package/Components/VideoModal/hooks/index.ts +0 -2
- package/Components/VideoModal/hooks/useDelayedPlayerDetails.ts +40 -15
- package/Components/VideoModal/hooks/useModalSize.ts +18 -2
- package/Components/VideoModal/hooks/utils/__tests__/showDetails.test.ts +2 -2
- package/Components/VideoModal/hooks/utils/index.ts +4 -0
- package/Components/VideoModal/utils.ts +6 -0
- package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +12 -16
- package/Components/Viewport/ViewportTracker/__tests__/viewportTracker.test.js +84 -24
- package/Components/Viewport/VisibilitySensor/VisibilitySensor.tsx +3 -3
- package/Components/default-cell-renderer/viewTrees/tv/DefaultCell/index.ts +3 -3
- package/Contexts/CellFocusedStateContext/index.tsx +27 -0
- package/Contexts/ConfigutaionContext/__tests__/ConfigurationProvider.test.tsx +3 -3
- package/Contexts/ScreenContext/index.tsx +46 -6
- package/Decorators/ConfigurationWrapper/__tests__/withConfigurationProvider.test.tsx +3 -3
- package/Decorators/ConfigurationWrapper/withConfigurationProvider.tsx +2 -2
- package/Decorators/RiverFeedLoader/__tests__/__snapshots__/riverFeedLoader.test.tsx.snap +221 -209
- package/Decorators/RiverFeedLoader/__tests__/riverFeedLoader.test.tsx +14 -16
- package/Decorators/RiverFeedLoader/__tests__/utils.test.ts +0 -20
- package/Decorators/RiverFeedLoader/index.tsx +22 -4
- package/Decorators/RiverFeedLoader/utils/getDatasourceUrl.ts +6 -10
- package/Decorators/RiverFeedLoader/utils/index.ts +0 -18
- package/Decorators/RiverResolver/__tests__/riverResolver.test.tsx +3 -6
- package/Decorators/ZappPipesDataConnector/ResolverSelector.tsx +25 -0
- package/Decorators/ZappPipesDataConnector/__tests__/NullFeedResolver.test.tsx +78 -0
- package/Decorators/ZappPipesDataConnector/__tests__/ResolverSelector.test.tsx +205 -0
- package/Decorators/ZappPipesDataConnector/__tests__/StaticFeedResolver.test.tsx +251 -0
- package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +368 -0
- package/Decorators/ZappPipesDataConnector/__tests__/utils.test.ts +39 -0
- package/Decorators/ZappPipesDataConnector/index.tsx +26 -293
- package/Decorators/ZappPipesDataConnector/resolvers/NullFeedResolver.tsx +25 -0
- package/Decorators/ZappPipesDataConnector/resolvers/StaticFeedResolver.tsx +87 -0
- package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +266 -0
- package/Decorators/ZappPipesDataConnector/types.ts +29 -0
- package/Decorators/ZappPipesDataConnector/utils/mongoFilter.ts +738 -0
- package/Decorators/ZappPipesDataConnector/utils/useFilter.tsx +157 -0
- package/events/index.ts +3 -0
- package/package.json +5 -10
- package/Components/AudioPlayer/AudioPlayerLayout.tsx +0 -202
- package/Components/AudioPlayer/__tests__/__snapshots__/audioPlayerLayout.test.js.snap +0 -66
- package/Components/AudioPlayer/__tests__/__snapshots__/channel.test.js.snap +0 -28
- package/Components/AudioPlayer/__tests__/audioPlayerLayout.test.js +0 -26
- package/Components/AudioPlayer/index.ts +0 -1
- package/Components/River/__tests__/__snapshots__/river.test.js.snap +0 -27
- package/Components/VideoModal/hooks/useBackgroundColor.ts +0 -10
- /package/Components/AudioPlayer/{__tests__ → tv/__tests__}/Runtime.test.js +0 -0
- /package/Components/AudioPlayer/{__tests__ → tv/__tests__}/__snapshots__/artWork.test.js.snap +0 -0
- /package/Components/AudioPlayer/{__tests__ → tv/__tests__}/artWork.test.js +0 -0
- /package/Components/AudioPlayer/{__tests__ → tv/__tests__}/channel.test.js +0 -0
- /package/Components/AudioPlayer/{__tests__ → tv/__tests__}/summary.test.js +0 -0
- /package/Components/AudioPlayer/{__tests__ → tv/__tests__}/title.test.js +0 -0
|
@@ -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,
|
|
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(
|
|
56
|
+
return componentsBefore.every(Boolean);
|
|
57
57
|
}, []);
|
|
58
58
|
|
|
59
59
|
const dispatch = React.useCallback(({ payload }) => {
|
|
@@ -10,11 +10,10 @@ 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 { useLoadPipesDataDispatch } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
18
17
|
|
|
19
18
|
const BRIGHTNESS_THRESHOLD = 160;
|
|
20
19
|
const ABOVE_DEFAULT_COLOR = "gray";
|
|
@@ -61,38 +60,33 @@ export const usePullToRefresh = (
|
|
|
61
60
|
) => {
|
|
62
61
|
const isPipesV1 = !!pullToRefreshPipesV1RefreshingStateUpdater;
|
|
63
62
|
|
|
64
|
-
const dispatch = useDispatch();
|
|
65
|
-
|
|
66
63
|
const [refreshing, setRefreshing] = React.useState(false);
|
|
67
64
|
|
|
68
65
|
const feeds: string[] =
|
|
69
66
|
riverComponents?.map(R.path(["data", "source"])).filter((feed) => !!feed) ??
|
|
70
67
|
[];
|
|
71
68
|
|
|
72
|
-
const screenData = useCurrentScreenData();
|
|
73
|
-
|
|
74
69
|
const feedsLength = feeds.length;
|
|
75
70
|
|
|
76
71
|
const [requestsCompletedCounter, setRequestsCompletedCounter] =
|
|
77
72
|
React.useState(0);
|
|
78
73
|
|
|
74
|
+
const loadPipesDataDispatcher = useLoadPipesDataDispatch();
|
|
75
|
+
|
|
79
76
|
React.useEffect(() => {
|
|
80
77
|
// will not work for pipes v1 on 1st level screens
|
|
81
78
|
if (refreshing && !isPipesV1) {
|
|
82
79
|
feeds.forEach((feed) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
riverId: screenData.id,
|
|
91
|
-
})
|
|
92
|
-
);
|
|
80
|
+
loadPipesDataDispatcher(feed, {
|
|
81
|
+
silentRefresh: true,
|
|
82
|
+
clearCache: true,
|
|
83
|
+
callback: () => {
|
|
84
|
+
setRequestsCompletedCounter(R.inc);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
93
87
|
});
|
|
94
88
|
}
|
|
95
|
-
}, [refreshing, isPipesV1]);
|
|
89
|
+
}, [refreshing, isPipesV1, feeds, loadPipesDataDispatcher]);
|
|
96
90
|
|
|
97
91
|
React.useEffect(() => {
|
|
98
92
|
if (requestsCompletedCounter === feedsLength) {
|
|
@@ -13,6 +13,7 @@ import { riverLogger } from "./logger";
|
|
|
13
13
|
import { tvPluginsWithCellRenderer } from "../../const";
|
|
14
14
|
import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
15
15
|
import type { BehaviorSubject } from "rxjs";
|
|
16
|
+
import { useCallbackActions } from "@applicaster/zapp-react-native-utils/zappFrameworkUtils/HookCallback/useCallbackActions";
|
|
16
17
|
|
|
17
18
|
export type RiverItemType = {
|
|
18
19
|
item: ZappUIComponent;
|
|
@@ -85,6 +86,7 @@ function RiverItemComponent(props: RiverItemType) {
|
|
|
85
86
|
loadingState,
|
|
86
87
|
} = props;
|
|
87
88
|
|
|
89
|
+
const callbackAction = useCallbackActions(item);
|
|
88
90
|
const readyToBeDisplayed = useLoadingState(index, loadingState);
|
|
89
91
|
|
|
90
92
|
const feedUrl = getFeedUrl(feed, index);
|
|
@@ -155,6 +157,7 @@ function RiverItemComponent(props: RiverItemType) {
|
|
|
155
157
|
groupId={groupId}
|
|
156
158
|
feedUrl={feedUrl}
|
|
157
159
|
isLast={isLast}
|
|
160
|
+
callback={callbackAction}
|
|
158
161
|
/>
|
|
159
162
|
);
|
|
160
163
|
}
|
|
@@ -4,10 +4,6 @@ import * as React from "react";
|
|
|
4
4
|
import { Text } from "react-native";
|
|
5
5
|
import * as R from "ramda";
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
useFeedLoader,
|
|
9
|
-
useLayoutVersion,
|
|
10
|
-
} from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
11
7
|
import { GeneralContentScreen } from "../../GeneralContentScreen";
|
|
12
8
|
import { ScreenResolver } from "@applicaster/zapp-react-native-ui-components/Components/ScreenResolver";
|
|
13
9
|
import { utilsLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
@@ -21,6 +17,7 @@ type Props = {
|
|
|
21
17
|
screenId: string;
|
|
22
18
|
screenData: ZappRiver | ZappEntry;
|
|
23
19
|
feedUrl?: string;
|
|
20
|
+
feedData?: PipesDataObject["data"];
|
|
24
21
|
extraProps?: any;
|
|
25
22
|
screenResolverExtraProps?: any;
|
|
26
23
|
componentsMapExtraProps?: any;
|
|
@@ -32,7 +29,7 @@ type Props = {
|
|
|
32
29
|
export const River = (props: Props) => {
|
|
33
30
|
const {
|
|
34
31
|
screenId,
|
|
35
|
-
|
|
32
|
+
feedData,
|
|
36
33
|
extraProps,
|
|
37
34
|
screenResolverExtraProps,
|
|
38
35
|
componentsMapExtraProps,
|
|
@@ -46,7 +43,6 @@ export const River = (props: Props) => {
|
|
|
46
43
|
useSetNavbarState();
|
|
47
44
|
|
|
48
45
|
const rivers = useRivers();
|
|
49
|
-
const isV2 = useLayoutVersion({ isV2: true });
|
|
50
46
|
|
|
51
47
|
const river = React.useMemo(() => rivers?.[screenId], [screenId]);
|
|
52
48
|
|
|
@@ -55,17 +51,6 @@ export const River = (props: Props) => {
|
|
|
55
51
|
[screenId]
|
|
56
52
|
);
|
|
57
53
|
|
|
58
|
-
const connectedScreenUrl = React.useMemo(() => {
|
|
59
|
-
// Avoid using feedUrl or content.src on layouts v2
|
|
60
|
-
if (isV2) return null;
|
|
61
|
-
|
|
62
|
-
return feedUrl || R.path(["content", "src"], screenData);
|
|
63
|
-
}, [feedUrl, screenData]);
|
|
64
|
-
|
|
65
|
-
const { data: feedData } = useFeedLoader({
|
|
66
|
-
feedUrl: connectedScreenUrl,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
54
|
const stringOrEmpty = (value: string | number | undefined): string =>
|
|
70
55
|
R.isNil(value) ? "" : String(value);
|
|
71
56
|
|
|
@@ -2,8 +2,10 @@ import { compose } from "ramda";
|
|
|
2
2
|
import { River as RiverComponent } from "./River";
|
|
3
3
|
import { withTvEventHandler } from "./withTVEventHandler";
|
|
4
4
|
import { withComponentsMapOffsetContext } from "../../../Contexts/ComponentsMapOffsetContext";
|
|
5
|
+
import { withRiverDataLoader } from "./withRiverDataLoader";
|
|
5
6
|
|
|
6
7
|
export const River = compose(
|
|
7
8
|
withTvEventHandler,
|
|
8
|
-
withComponentsMapOffsetContext
|
|
9
|
+
withComponentsMapOffsetContext,
|
|
10
|
+
withRiverDataLoader
|
|
9
11
|
)(RiverComponent);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
|
+
import { path } from "ramda";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
useFeedLoader,
|
|
6
|
+
useRivers,
|
|
7
|
+
} from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
8
|
+
|
|
9
|
+
type Props = {
|
|
10
|
+
screenId: string;
|
|
11
|
+
screenData: ZappRiver | ZappEntry;
|
|
12
|
+
feedUrl?: string;
|
|
13
|
+
river?: ZappRiver | ZappEntry;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const withPipesV1DataLoader = (
|
|
17
|
+
WrappedComponent: React.ComponentType<any>
|
|
18
|
+
) => {
|
|
19
|
+
return function WithPipesV1DataLoaderComponent(props: Props) {
|
|
20
|
+
const { screenId, feedUrl } = props;
|
|
21
|
+
|
|
22
|
+
const rivers = useRivers();
|
|
23
|
+
|
|
24
|
+
const river = React.useMemo(() => rivers?.[screenId], [screenId]);
|
|
25
|
+
|
|
26
|
+
const screenData = React.useMemo(
|
|
27
|
+
() => props.screenData || props.river || river,
|
|
28
|
+
[screenId]
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const connectedScreenUrl = useMemo(() => {
|
|
32
|
+
// Avoid using feedUrl or content.src on layouts v2
|
|
33
|
+
|
|
34
|
+
return feedUrl || path(["content", "src"], screenData);
|
|
35
|
+
}, [feedUrl, screenData]);
|
|
36
|
+
|
|
37
|
+
const { data: feedData } = useFeedLoader({
|
|
38
|
+
feedUrl: connectedScreenUrl,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return <WrappedComponent {...props} feedData={feedData} />;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useLayoutVersion } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { withPipesV1DataLoader } from "./withPipesV1DataLoader";
|
|
4
|
+
|
|
5
|
+
export const withRiverDataLoader = (
|
|
6
|
+
WrappedComponent: React.ComponentType<any>
|
|
7
|
+
) => {
|
|
8
|
+
return function WithRiverDataLoaderComponent(props) {
|
|
9
|
+
const isV2 = useLayoutVersion({ isV2: true });
|
|
10
|
+
|
|
11
|
+
if (isV2) {
|
|
12
|
+
return <WrappedComponent {...props} />;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return withPipesV1DataLoader(WrappedComponent)(props);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -8,7 +8,7 @@ export const withTvEventHandler = (Component) => {
|
|
|
8
8
|
return function WithTVEventHandler(props) {
|
|
9
9
|
const navigator = useNavigation();
|
|
10
10
|
|
|
11
|
-
const remoteHandler = (
|
|
11
|
+
const remoteHandler = (event) => {
|
|
12
12
|
const { eventType } = event;
|
|
13
13
|
|
|
14
14
|
const canGoBack = navigator.canGoBack();
|
|
@@ -159,6 +159,7 @@ exports[`componentsMap renders renders components map correctly 1`] = `
|
|
|
159
159
|
>
|
|
160
160
|
<View>
|
|
161
161
|
<View
|
|
162
|
+
onFocusCapture={[Function]}
|
|
162
163
|
onLayout={[Function]}
|
|
163
164
|
style={null}
|
|
164
165
|
>
|
|
@@ -174,6 +175,7 @@ exports[`componentsMap renders renders components map correctly 1`] = `
|
|
|
174
175
|
</View>
|
|
175
176
|
</View>
|
|
176
177
|
<View
|
|
178
|
+
onFocusCapture={[Function]}
|
|
177
179
|
onLayout={[Function]}
|
|
178
180
|
style={null}
|
|
179
181
|
>
|