@applicaster/zapp-react-native-utils 13.0.19 → 13.0.21-rc.0

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.
@@ -336,7 +336,9 @@ class FocusManager {
336
336
 
337
337
  resetFocus() {
338
338
  if (FocusManager.instance.focused?.onBlur) {
339
- FocusManager.instance.focused.onBlur(FocusManager.instance.focused, {});
339
+ FocusManager.instance.focused.onBlur(FocusManager.instance.focused, {
340
+ forceResetFocus: true,
341
+ });
340
342
  }
341
343
 
342
344
  FocusManager.instance.setFocusLocal({ current: null });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "13.0.19",
3
+ "version": "13.0.21-rc.0",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "13.0.19",
30
+ "@applicaster/applicaster-types": "13.0.21-rc.0",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -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-hooks");
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,4 +1,4 @@
1
- import { useMemo } from "react";
1
+ import { useCallback, useMemo } from "react";
2
2
  import * as R from "ramda";
3
3
 
4
4
  import {
@@ -178,22 +178,19 @@ export function getSearchContext(
178
178
  return { [property]: encodeIfNeeded(searchContext) };
179
179
  }
180
180
 
181
- export function useInflatedUrl({
182
- feedUrl,
183
- mapping,
184
- }: {
185
- feedUrl?: string;
186
- mapping?: ZappTypeMapping;
187
- }) {
181
+ export const useGetUrlInflater = () => {
188
182
  const { pathname } = useRoute();
189
183
 
190
184
  const [entryContext] = ZappPipesEntryContext.useZappPipesContext(pathname);
191
185
  const [searchContext] = ZappPipesSearchContext.useZappPipesContext();
192
186
  const [screenContext] = ZappPipesScreenContext.useZappPipesContext();
193
187
 
194
- const url = useMemo(
195
- () =>
196
- mapping
188
+ return useCallback(
189
+ (
190
+ feedUrl: Nullable<string>,
191
+ mapping?: ZappTypeMapping
192
+ ): Nullable<string> => {
193
+ return mapping
197
194
  ? getInflatedDataSourceUrl({
198
195
  source: feedUrl,
199
196
  contexts: {
@@ -203,8 +200,24 @@ export function useInflatedUrl({
203
200
  },
204
201
  mapping,
205
202
  })
206
- : feedUrl,
207
- [feedUrl, mapping]
203
+ : feedUrl;
204
+ },
205
+ [entryContext, screenContext, searchContext]
206
+ );
207
+ };
208
+
209
+ export function useInflatedUrl({
210
+ feedUrl,
211
+ mapping,
212
+ }: {
213
+ feedUrl?: string;
214
+ mapping?: ZappTypeMapping;
215
+ }) {
216
+ const urlInflater = useGetUrlInflater();
217
+
218
+ const url = useMemo(
219
+ () => urlInflater(feedUrl, mapping),
220
+ [urlInflater, feedUrl, mapping]
208
221
  );
209
222
 
210
223
  if (!feedUrl) {