@applicaster/zapp-react-native-utils 15.0.0-alpha.1201747215 → 15.0.0-alpha.1257410812
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/actionsExecutor/ActionExecutorContext.tsx +3 -6
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/adsUtils/index.ts +2 -2
- package/analyticsUtils/README.md +1 -1
- package/analyticsUtils/analyticsMapper.ts +10 -2
- package/appUtils/HooksManager/index.ts +10 -10
- package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
- package/appUtils/accessibilityManager/__tests__/utils.test.ts +360 -0
- package/appUtils/accessibilityManager/const.ts +4 -0
- package/appUtils/accessibilityManager/hooks.ts +20 -13
- package/appUtils/accessibilityManager/index.ts +28 -1
- package/appUtils/accessibilityManager/utils.ts +59 -8
- package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
- package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
- package/appUtils/contextKeysManager/contextResolver.ts +51 -22
- package/appUtils/contextKeysManager/index.ts +65 -10
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +3 -0
- package/appUtils/focusManager/index.ios.ts +43 -4
- package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
- package/appUtils/focusManagerAux/utils/index.ts +1 -1
- package/appUtils/focusManagerAux/utils/utils.ios.ts +199 -3
- package/appUtils/keyCodes/keys/keys.web.ts +1 -4
- package/appUtils/orientationHelper.ts +2 -4
- package/appUtils/platform/platformUtils.ts +115 -16
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +94 -4
- package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
- package/appUtils/playerManager/player.ts +4 -0
- package/appUtils/playerManager/playerNative.ts +29 -16
- package/appUtils/playerManager/usePlayerState.tsx +14 -2
- package/cellUtils/index.ts +32 -0
- package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
- package/configurationUtils/index.ts +17 -11
- package/focusManager/aux/index.ts +1 -1
- package/manifestUtils/defaultManifestConfigurations/player.js +125 -11
- package/manifestUtils/tvAction/container/index.js +1 -1
- package/navigationUtils/index.ts +15 -5
- package/package.json +4 -4
- package/playerUtils/usePlayerTTS.ts +8 -3
- package/pluginUtils/index.ts +4 -0
- package/reactHooks/advertising/index.ts +2 -2
- package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
- package/reactHooks/cell-click/__tests__/index.test.js +1 -3
- package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
- package/reactHooks/connection/__tests__/index.test.js +1 -1
- package/reactHooks/debugging/__tests__/index.test.js +4 -4
- package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
- package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +4 -1
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
- package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +1 -1
- package/reactHooks/feed/__tests__/{useInflatedUrl.test.ts → useInflatedUrl.test.tsx} +62 -7
- package/reactHooks/feed/useEntryScreenId.ts +2 -2
- package/reactHooks/feed/useInflatedUrl.ts +43 -17
- package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
- package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
- package/reactHooks/layout/__tests__/index.test.tsx +1 -1
- package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
- package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
- package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
- package/reactHooks/navigation/index.ts +27 -11
- package/reactHooks/navigation/useRoute.ts +11 -7
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
- package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
- package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
- package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
- package/reactHooks/resolvers/useCellResolver.ts +6 -2
- package/reactHooks/resolvers/useComponentResolver.ts +8 -2
- package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
- package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
- package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
- package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +12 -4
- package/reactHooks/screen/useTargetScreenData.ts +4 -2
- package/reactHooks/state/useRefWithInitialValue.ts +10 -0
- package/reactHooks/state/useRivers.ts +1 -1
- package/reactHooks/usePluginConfiguration.ts +2 -2
- package/reactHooks/utils/__tests__/index.test.js +1 -1
- package/screenState/__tests__/index.test.ts +1 -1
- package/searchUtils/const.ts +7 -0
- package/searchUtils/index.ts +3 -0
- package/services/storageServiceSync.web.ts +1 -1
- package/stringUtils/index.ts +1 -1
- package/testUtils/index.tsx +30 -21
- package/utils/__tests__/mergeRight.test.ts +48 -0
- package/utils/__tests__/selectors.test.ts +124 -0
- package/utils/index.ts +13 -0
- package/utils/mergeRight.ts +5 -0
- package/utils/path.ts +6 -3
- package/utils/pathOr.ts +5 -1
- package/utils/selectors.ts +46 -0
- package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +34 -11
- package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { renderHook } from "@testing-library/react-
|
|
1
|
+
import { renderHook, waitFor } from "@testing-library/react-native";
|
|
2
2
|
import { encodeParams } from "@applicaster/zapp-pipes-v2-client/src/utils";
|
|
3
3
|
|
|
4
4
|
const appData = {
|
|
@@ -42,26 +42,26 @@ describe("useBuildPipesUrl", () => {
|
|
|
42
42
|
build: jest.fn(() => Promise.resolve(buildResult)),
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
const { result
|
|
45
|
+
const { result } = renderHook(() =>
|
|
46
46
|
useBuildPipesUrl({ url, mapping, requestBuilder: mockedRequestBuilder })
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
expect(result.current.url).toBe("http://foo.com/show/show-1");
|
|
50
50
|
expect(result.current.requestParams).toBeNull();
|
|
51
51
|
|
|
52
|
-
await
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
);
|
|
52
|
+
await waitFor(() => {
|
|
53
|
+
expect(result.current.requestParams).toEqual(
|
|
54
|
+
expect.objectContaining({
|
|
55
|
+
params: {
|
|
56
|
+
version: appData.version_name,
|
|
57
|
+
ctx: encodeParams({ platform: appData.platform }),
|
|
58
|
+
},
|
|
59
|
+
headers: {
|
|
60
|
+
SDK: appData.sdk_version,
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it("returns empty object if url is not in endpoints", async () => {
|
|
@@ -81,15 +81,15 @@ describe("useBuildPipesUrl", () => {
|
|
|
81
81
|
build: jest.fn(() => Promise.resolve(buildResult)),
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
const { result
|
|
84
|
+
const { result } = renderHook(() =>
|
|
85
85
|
useBuildPipesUrl({ url, mapping, requestBuilder: mockedRequestBuilder })
|
|
86
86
|
);
|
|
87
87
|
|
|
88
88
|
expect(result.current.url).toBe("http://foobar.com/show-1");
|
|
89
89
|
expect(result.current.requestParams).toBeNull();
|
|
90
90
|
|
|
91
|
-
await
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
await waitFor(() => {
|
|
92
|
+
expect(result.current.requestParams).toEqual({});
|
|
93
|
+
});
|
|
94
94
|
});
|
|
95
95
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { renderHook } from "@testing-library/react-
|
|
3
|
+
import { renderHook } from "@testing-library/react-native";
|
|
4
4
|
import { Provider } from "react-redux";
|
|
5
5
|
import { createStore } from "redux";
|
|
6
6
|
|
|
@@ -10,6 +10,9 @@ describe("useEntryScreenId", () => {
|
|
|
10
10
|
const mappedScreenId = "mapped-id";
|
|
11
11
|
|
|
12
12
|
const initialState = {
|
|
13
|
+
rivers: {
|
|
14
|
+
[mappedScreenId]: { id: mappedScreenId, type: "any" },
|
|
15
|
+
},
|
|
13
16
|
contentTypes: { mappedEntry: { screen_id: mappedScreenId } },
|
|
14
17
|
};
|
|
15
18
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { renderHook } from "@testing-library/react-
|
|
1
|
+
import { renderHook } from "@testing-library/react-native";
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
import * as zappPipesModule from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
4
4
|
import * as reactReduxModules from "react-redux";
|
|
@@ -50,6 +50,16 @@ const mockZappPipesData = {
|
|
|
50
50
|
url: "test://testfakeurl",
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
const createWrapper = (
|
|
54
|
+
getStore: () => any
|
|
55
|
+
): React.FC<{ children: React.ReactNode }> => {
|
|
56
|
+
const Wrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
57
|
+
<WrappedWithProviders store={getStore()}>{children}</WrappedWithProviders>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return Wrapper;
|
|
61
|
+
};
|
|
62
|
+
|
|
53
63
|
describe("useFeedLoader", () => {
|
|
54
64
|
describe("with cached feed url", () => {
|
|
55
65
|
const store = {
|
|
@@ -57,11 +67,7 @@ describe("useFeedLoader", () => {
|
|
|
57
67
|
zappPipes: { "test://testfakeurl": mockZappPipesData },
|
|
58
68
|
};
|
|
59
69
|
|
|
60
|
-
const wrapper
|
|
61
|
-
<WrappedWithProviders store={props.store || store}>
|
|
62
|
-
{children}
|
|
63
|
-
</WrappedWithProviders>
|
|
64
|
-
);
|
|
70
|
+
const wrapper = createWrapper(() => store);
|
|
65
71
|
|
|
66
72
|
it("returns cached feed", () => {
|
|
67
73
|
const { result } = renderHook(
|
|
@@ -109,12 +115,6 @@ describe("useFeedLoader", () => {
|
|
|
109
115
|
describe("without cached feeds", () => {
|
|
110
116
|
const feedUrl = "test://testfakeurl2";
|
|
111
117
|
|
|
112
|
-
const wrapper: React.FC<any> = ({ children, ...props }) => (
|
|
113
|
-
<WrappedWithProviders store={props.store}>
|
|
114
|
-
{children}
|
|
115
|
-
</WrappedWithProviders>
|
|
116
|
-
);
|
|
117
|
-
|
|
118
118
|
it("It loads data for new url and returns it", () => {
|
|
119
119
|
const useDispatchSpy = jest
|
|
120
120
|
.spyOn(reactReduxModules, "useDispatch")
|
|
@@ -129,9 +129,12 @@ describe("useFeedLoader", () => {
|
|
|
129
129
|
zappPipes: { "test://testfakeurl": "foobar" },
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
+
let store = initialStore;
|
|
133
|
+
const wrapper = createWrapper(() => store);
|
|
134
|
+
|
|
132
135
|
const { result, rerender } = renderHook(
|
|
133
|
-
() => useFeedLoader({ feedUrl:
|
|
134
|
-
{ wrapper, initialProps: {
|
|
136
|
+
({ feedUrl: url }) => useFeedLoader({ feedUrl: url }),
|
|
137
|
+
{ wrapper, initialProps: { feedUrl } }
|
|
135
138
|
);
|
|
136
139
|
|
|
137
140
|
expect(result.current.data).toBeNull();
|
|
@@ -150,7 +153,8 @@ describe("useFeedLoader", () => {
|
|
|
150
153
|
zappPipes: { "test://testfakeurl2": mockZappPipesData },
|
|
151
154
|
};
|
|
152
155
|
|
|
153
|
-
|
|
156
|
+
store = store2;
|
|
157
|
+
rerender({ feedUrl });
|
|
154
158
|
|
|
155
159
|
expect(R.omit(["reloadData", "loadNext"], result.current)).toEqual(
|
|
156
160
|
mockZappPipesData
|
|
@@ -174,9 +178,12 @@ describe("useFeedLoader", () => {
|
|
|
174
178
|
zappPipes: { "test://testfakeurl": "foobar" },
|
|
175
179
|
};
|
|
176
180
|
|
|
181
|
+
let store = initialStore;
|
|
182
|
+
const wrapper = createWrapper(() => store);
|
|
183
|
+
|
|
177
184
|
const { result, rerender } = renderHook(
|
|
178
|
-
() => useFeedLoader({ feedUrl:
|
|
179
|
-
{ wrapper, initialProps: {
|
|
185
|
+
({ feedUrl: url }) => useFeedLoader({ feedUrl: url }),
|
|
186
|
+
{ wrapper, initialProps: { feedUrl } }
|
|
180
187
|
);
|
|
181
188
|
|
|
182
189
|
expect(result.current.data).toBeNull();
|
|
@@ -198,7 +205,8 @@ describe("useFeedLoader", () => {
|
|
|
198
205
|
zappPipes: { "test://testfakeurl2": mockZappPipesData },
|
|
199
206
|
};
|
|
200
207
|
|
|
201
|
-
|
|
208
|
+
store = store2;
|
|
209
|
+
rerender({ feedUrl });
|
|
202
210
|
|
|
203
211
|
loadPipesDataSpy.mockRestore();
|
|
204
212
|
useDispatchSpy.mockRestore();
|
|
@@ -209,12 +217,6 @@ describe("useFeedLoader", () => {
|
|
|
209
217
|
const feedUrl = "test://testfakeurl";
|
|
210
218
|
const feedUrlWithNext = "test://withnexttestfakeurl";
|
|
211
219
|
|
|
212
|
-
const wrapper: React.FC<any> = ({ children, ...props }) => (
|
|
213
|
-
<WrappedWithProviders store={props.store || {}}>
|
|
214
|
-
{children}
|
|
215
|
-
</WrappedWithProviders>
|
|
216
|
-
);
|
|
217
|
-
|
|
218
220
|
describe("reloadData", () => {
|
|
219
221
|
it("Tries to reload data in the redux store", () => {
|
|
220
222
|
const loadPipesDataSpy = jest
|
|
@@ -230,10 +232,17 @@ describe("useFeedLoader", () => {
|
|
|
230
232
|
zappPipes: { [feedUrl]: "foobar" },
|
|
231
233
|
};
|
|
232
234
|
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
const store = initialStore;
|
|
236
|
+
|
|
237
|
+
const wrapper = createWrapper(() => store);
|
|
238
|
+
|
|
239
|
+
const { result } = renderHook(
|
|
240
|
+
({ feedUrl: url }) => useFeedLoader({ feedUrl: url }),
|
|
241
|
+
{
|
|
242
|
+
wrapper,
|
|
243
|
+
initialProps: { feedUrl },
|
|
244
|
+
}
|
|
245
|
+
);
|
|
237
246
|
|
|
238
247
|
const { reloadData } = result.current;
|
|
239
248
|
|
|
@@ -279,11 +288,14 @@ describe("useFeedLoader", () => {
|
|
|
279
288
|
zappPipes: { [feedUrlWithNext]: { data: { next: nextUrl } } },
|
|
280
289
|
};
|
|
281
290
|
|
|
291
|
+
const store = initialStore;
|
|
292
|
+
const wrapper = createWrapper(() => store);
|
|
293
|
+
|
|
282
294
|
const { result } = renderHook(
|
|
283
|
-
() => useFeedLoader({ feedUrl:
|
|
295
|
+
({ feedUrl: url }) => useFeedLoader({ feedUrl: url }),
|
|
284
296
|
{
|
|
285
297
|
wrapper,
|
|
286
|
-
initialProps: {
|
|
298
|
+
initialProps: { feedUrl: feedUrlWithNext },
|
|
287
299
|
}
|
|
288
300
|
);
|
|
289
301
|
|
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { WrappedWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
getInflatedDataSourceUrl,
|
|
7
|
+
getSearchContext,
|
|
8
|
+
useGetUrlInflater,
|
|
9
|
+
} from "../useInflatedUrl";
|
|
10
|
+
|
|
11
|
+
import { reactHooksLogger } from "../../logger";
|
|
12
|
+
|
|
13
|
+
jest.mock("../../navigation", () => ({
|
|
14
|
+
useRoute: () => ({ pathname: "/mock/path" }),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
// mock contexts hooks
|
|
18
|
+
jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
|
|
19
|
+
ZappPipesEntryContext: {
|
|
20
|
+
useZappPipesContext: () => [
|
|
21
|
+
{ id: "entry-1", extensions: { showId: "A123" } },
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
ZappPipesSearchContext: {
|
|
25
|
+
useZappPipesContext: () => ["user%20query"],
|
|
26
|
+
},
|
|
27
|
+
ZappPipesScreenContext: {
|
|
28
|
+
useZappPipesContext: () => [{ id: "screen-1" }],
|
|
29
|
+
},
|
|
30
|
+
}));
|
|
31
|
+
|
|
1
32
|
jest.mock("../../logger", () => ({
|
|
2
33
|
reactHooksLogger: {
|
|
3
34
|
warning: jest.fn(),
|
|
@@ -5,13 +36,6 @@ jest.mock("../../logger", () => ({
|
|
|
5
36
|
},
|
|
6
37
|
}));
|
|
7
38
|
|
|
8
|
-
const {
|
|
9
|
-
getInflatedDataSourceUrl,
|
|
10
|
-
getSearchContext,
|
|
11
|
-
} = require("../useInflatedUrl");
|
|
12
|
-
|
|
13
|
-
const { reactHooksLogger } = require("../../logger");
|
|
14
|
-
|
|
15
39
|
let mockStore;
|
|
16
40
|
|
|
17
41
|
describe("getInflatedDataSourceUrl", () => {
|
|
@@ -188,3 +212,34 @@ describe("getSearchContext", () => {
|
|
|
188
212
|
expect(result).toHaveProperty(mapping.queryParam.property, searchContext);
|
|
189
213
|
});
|
|
190
214
|
});
|
|
215
|
+
|
|
216
|
+
describe("useGetUrlInflater", () => {
|
|
217
|
+
const { renderHook } = require("@testing-library/react-native");
|
|
218
|
+
|
|
219
|
+
it("returns original url when mapping is not provided", () => {
|
|
220
|
+
const { result } = renderHook(() => useGetUrlInflater(), {
|
|
221
|
+
wrapper: WrappedWithProviders,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
const src = "https://foo.com/feed";
|
|
225
|
+
expect(result.current(src)).toBe(src);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("inflates url using entry/search/screen contexts when mapping provided", () => {
|
|
229
|
+
const { result } = renderHook(() => useGetUrlInflater(), {
|
|
230
|
+
wrapper: ({ children }) => (
|
|
231
|
+
<WrappedWithProviders>{children}</WrappedWithProviders>
|
|
232
|
+
),
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const source = "https://foo.com/shows/{{showId}}?q={{q}}";
|
|
236
|
+
|
|
237
|
+
const mapping = {
|
|
238
|
+
showId: { source: "entry", property: "extensions.showId" },
|
|
239
|
+
q: { source: "search", property: "q" },
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const url = result.current(source, mapping);
|
|
243
|
+
expect(url).toBe("https://foo.com/shows/A123?q=user%20query");
|
|
244
|
+
});
|
|
245
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useContentTypes } from "@applicaster/zapp-react-native-redux";
|
|
2
2
|
|
|
3
3
|
export const useEntryScreenId = (entry?: ZappEntry): string | undefined => {
|
|
4
|
-
const
|
|
4
|
+
const contentTypes = useContentTypes();
|
|
5
5
|
|
|
6
6
|
if (!entry) {
|
|
7
7
|
return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
1
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
|
|
4
4
|
import {
|
|
@@ -169,7 +169,7 @@ const encodeIfNeeded: (string) => string = R.tryCatch(
|
|
|
169
169
|
|
|
170
170
|
export function getSearchContext(
|
|
171
171
|
searchContext: string,
|
|
172
|
-
mapping: ZappTypeMapping
|
|
172
|
+
mapping: Nullable<ZappTypeMapping>
|
|
173
173
|
) {
|
|
174
174
|
if (!mapping) {
|
|
175
175
|
return {};
|
|
@@ -183,31 +183,57 @@ export function getSearchContext(
|
|
|
183
183
|
return { [property]: encodeIfNeeded(searchContext) };
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
mapping?: ZappTypeMapping;
|
|
192
|
-
}) {
|
|
186
|
+
/**
|
|
187
|
+
* Hook returns a function that replace placeholders with context values
|
|
188
|
+
* @returns function that inflates urls based on contexts
|
|
189
|
+
*/
|
|
190
|
+
export const useGetUrlInflater = () => {
|
|
193
191
|
const { pathname } = useRoute();
|
|
194
192
|
|
|
195
193
|
const [entryContext] = ZappPipesEntryContext.useZappPipesContext(pathname);
|
|
196
194
|
const [searchContext] = ZappPipesSearchContext.useZappPipesContext();
|
|
197
195
|
const [screenContext] = ZappPipesScreenContext.useZappPipesContext();
|
|
198
196
|
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
197
|
+
const entryContextRef = useRef(entryContext);
|
|
198
|
+
entryContextRef.current = entryContext;
|
|
199
|
+
|
|
200
|
+
const screenContextRef = useRef(screenContext);
|
|
201
|
+
screenContextRef.current = screenContext;
|
|
202
|
+
|
|
203
|
+
const searchContextRef = useRef(searchContext);
|
|
204
|
+
searchContextRef.current = searchContext;
|
|
205
|
+
|
|
206
|
+
return useCallback(
|
|
207
|
+
(
|
|
208
|
+
feedUrl: Nullable<string>,
|
|
209
|
+
mapping?: Nullable<ZappTypeMapping>
|
|
210
|
+
): Nullable<string> => {
|
|
211
|
+
return getInflatedDataSourceUrl({
|
|
202
212
|
source: feedUrl,
|
|
203
213
|
contexts: {
|
|
204
|
-
entry:
|
|
205
|
-
screen:
|
|
206
|
-
search: getSearchContext(
|
|
214
|
+
entry: entryContextRef.current,
|
|
215
|
+
screen: screenContextRef.current,
|
|
216
|
+
search: getSearchContext(searchContextRef.current, mapping),
|
|
207
217
|
},
|
|
208
218
|
mapping,
|
|
209
|
-
})
|
|
210
|
-
|
|
219
|
+
});
|
|
220
|
+
},
|
|
221
|
+
[]
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export function useInflatedUrl({
|
|
226
|
+
feedUrl,
|
|
227
|
+
mapping,
|
|
228
|
+
}: {
|
|
229
|
+
feedUrl?: string;
|
|
230
|
+
mapping?: ZappTypeMapping;
|
|
231
|
+
}) {
|
|
232
|
+
const urlInflater = useGetUrlInflater();
|
|
233
|
+
|
|
234
|
+
const url = useMemo(
|
|
235
|
+
() => urlInflater(feedUrl, mapping),
|
|
236
|
+
[urlInflater, feedUrl, mapping]
|
|
211
237
|
);
|
|
212
238
|
|
|
213
239
|
return url;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
-
type Return = (index: number) => void;
|
|
5
|
-
|
|
6
4
|
type Predicate = (
|
|
7
|
-
|
|
5
|
+
entryLength: number,
|
|
8
6
|
index: number,
|
|
9
7
|
numberOfColumns: number
|
|
10
8
|
) => boolean;
|
|
@@ -12,19 +10,15 @@ type Predicate = (
|
|
|
12
10
|
type Props = {
|
|
13
11
|
ifNeeded: Predicate;
|
|
14
12
|
loadNextData: () => void;
|
|
15
|
-
|
|
13
|
+
entryLength: number;
|
|
16
14
|
numberOfColumns?: number;
|
|
17
15
|
};
|
|
18
16
|
|
|
19
17
|
const handleLoadNextPage =
|
|
20
18
|
(
|
|
21
|
-
ifNeeded:
|
|
22
|
-
entry: ZappEntry[],
|
|
23
|
-
index: number,
|
|
24
|
-
numberOfColumns?: number
|
|
25
|
-
) => boolean,
|
|
19
|
+
ifNeeded: Predicate,
|
|
26
20
|
loadNextData: () => void,
|
|
27
|
-
|
|
21
|
+
entryLength: number,
|
|
28
22
|
numberOfColumns
|
|
29
23
|
) =>
|
|
30
24
|
(index: number) => {
|
|
@@ -32,7 +26,7 @@ const handleLoadNextPage =
|
|
|
32
26
|
* Lazy-Loading, invoke nextLoadData if we reach the end of the List
|
|
33
27
|
*/
|
|
34
28
|
|
|
35
|
-
if (ifNeeded(
|
|
29
|
+
if (ifNeeded(entryLength, index, numberOfColumns)) {
|
|
36
30
|
loadNextData();
|
|
37
31
|
}
|
|
38
32
|
};
|
|
@@ -40,11 +34,14 @@ const handleLoadNextPage =
|
|
|
40
34
|
export const useLoadNextPageIfNeeded = ({
|
|
41
35
|
ifNeeded,
|
|
42
36
|
loadNextData = noop,
|
|
43
|
-
|
|
37
|
+
entryLength,
|
|
44
38
|
numberOfColumns = 0,
|
|
45
|
-
}: Props)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
}: Props) => {
|
|
40
|
+
const memoFn = React.useMemo(
|
|
41
|
+
() =>
|
|
42
|
+
handleLoadNextPage(ifNeeded, loadNextData, entryLength, numberOfColumns),
|
|
43
|
+
[ifNeeded, loadNextData, entryLength, numberOfColumns]
|
|
49
44
|
);
|
|
45
|
+
|
|
46
|
+
return memoFn;
|
|
50
47
|
};
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { reactHooksLogger } from "../../logger";
|
|
2
|
-
import {
|
|
2
|
+
import { useZappHookModalStore } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
|
|
3
3
|
|
|
4
4
|
const logger = reactHooksLogger.addSubsystem("useHookModalScreenData");
|
|
5
5
|
|
|
6
6
|
type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
|
|
7
7
|
|
|
8
|
-
export const useHookModalScreenData = (
|
|
9
|
-
|
|
8
|
+
export const useHookModalScreenData = (
|
|
9
|
+
skipSubscription: boolean
|
|
10
|
+
): VariousScreenData | undefined => {
|
|
11
|
+
const hookModalState = useZappHookModalStore((state) =>
|
|
12
|
+
skipSubscription ? undefined : state.state
|
|
13
|
+
);
|
|
10
14
|
|
|
11
|
-
if (!hookModalState
|
|
15
|
+
if (!hookModalState?.screenData) {
|
|
12
16
|
return;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
try {
|
|
16
|
-
const screenData = hookModalState.
|
|
17
|
-
const hookPlugin = hookModalState.
|
|
20
|
+
const screenData = hookModalState.screenData?.payload;
|
|
21
|
+
const hookPlugin = hookModalState.screenData.hookPlugin;
|
|
18
22
|
|
|
19
23
|
if (hookPlugin?.screen_id) {
|
|
20
24
|
return {
|
|
@@ -23,7 +27,7 @@ export const useHookModalScreenData = (): VariousScreenData | undefined => {
|
|
|
23
27
|
};
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
return hookModalState.
|
|
30
|
+
return hookModalState.screenData?.payload;
|
|
27
31
|
} catch (error) {
|
|
28
32
|
logger.error({
|
|
29
33
|
message: "Hook modal screen data creation failed",
|
|
@@ -34,6 +38,6 @@ export const useHookModalScreenData = (): VariousScreenData | undefined => {
|
|
|
34
38
|
jsOnly: true,
|
|
35
39
|
});
|
|
36
40
|
|
|
37
|
-
return hookModalState.
|
|
41
|
+
return hookModalState.screenData?.payload;
|
|
38
42
|
}
|
|
39
43
|
};
|