@applicaster/zapp-react-native-utils 14.0.0-alpha.5333112458 → 14.0.0-alpha.5351122050

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 (58) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +0 -1
  2. package/actionsExecutor/ScreenActions.ts +20 -19
  3. package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
  4. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
  5. package/analyticsUtils/__tests__/analyticsUtils.test.js +0 -11
  6. package/analyticsUtils/index.tsx +3 -4
  7. package/analyticsUtils/manager.ts +1 -1
  8. package/appUtils/HooksManager/Hook.ts +4 -4
  9. package/appUtils/HooksManager/index.ts +11 -1
  10. package/appUtils/accessibilityManager/index.ts +3 -12
  11. package/appUtils/contextKeysManager/contextResolver.ts +29 -1
  12. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +5 -0
  13. package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
  14. package/appUtils/focusManager/index.ios.ts +10 -0
  15. package/appUtils/focusManager/index.ts +82 -11
  16. package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
  17. package/appUtils/focusManagerAux/utils/index.ts +106 -3
  18. package/arrayUtils/index.ts +1 -1
  19. package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
  20. package/componentsUtils/index.ts +4 -1
  21. package/configurationUtils/__tests__/manifestKeyParser.test.ts +0 -1
  22. package/index.d.ts +0 -12
  23. package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
  24. package/navigationUtils/index.ts +7 -5
  25. package/package.json +2 -3
  26. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
  27. package/reactHooks/cell-click/__tests__/index.test.js +3 -0
  28. package/reactHooks/debugging/__tests__/index.test.js +0 -1
  29. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +47 -90
  30. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +57 -37
  31. package/reactHooks/feed/index.ts +2 -0
  32. package/reactHooks/feed/useBatchLoading.ts +15 -8
  33. package/reactHooks/feed/useFeedLoader.tsx +39 -44
  34. package/reactHooks/feed/useLoadPipesDataDispatch.ts +57 -0
  35. package/reactHooks/feed/usePipesCacheReset.ts +2 -2
  36. package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
  37. package/reactHooks/layout/__tests__/index.test.tsx +3 -1
  38. package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
  39. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
  40. package/reactHooks/layout/useLayoutVersion.ts +5 -5
  41. package/reactHooks/navigation/index.ts +5 -7
  42. package/reactHooks/navigation/useScreenStateStore.ts +3 -3
  43. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
  44. package/reactHooks/state/index.ts +1 -1
  45. package/reactHooks/state/useHomeRiver.ts +4 -2
  46. package/reactHooks/state/useRivers.ts +7 -8
  47. package/screenPickerUtils/index.ts +7 -0
  48. package/storage/ScreenSingleValueProvider.ts +25 -22
  49. package/storage/ScreenStateMultiSelectProvider.ts +26 -23
  50. package/testUtils/index.tsx +7 -8
  51. package/time/BackgroundTimer.ts +1 -1
  52. package/utils/__tests__/find.test.ts +36 -0
  53. package/utils/__tests__/pathOr.test.ts +37 -0
  54. package/utils/__tests__/startsWith.test.ts +30 -0
  55. package/utils/find.ts +3 -0
  56. package/utils/index.ts +8 -0
  57. package/utils/pathOr.ts +5 -0
  58. package/utils/startsWith.ts +9 -0
@@ -2,6 +2,7 @@ import { MultiSelectProvider } from "./StorageMultiSelectProvider";
2
2
  import { BehaviorSubject } from "rxjs";
3
3
  import { createLogger } from "../logger";
4
4
  import { bridgeLogger } from "../../zapp-react-native-bridge/logger";
5
+ import { useScreenStateStore } from "../reactHooks/navigation/useScreenStateStore";
5
6
 
6
7
  export const { log_debug, log_error } = createLogger({
7
8
  category: "ScreenMultiSelectProvider",
@@ -22,7 +23,7 @@ export class ScreenMultiSelectProvider implements MultiSelectProvider {
22
23
  public static getProvider(
23
24
  key: string,
24
25
  screenRoute: string,
25
- screenStateStore: ScreenStateStore
26
+ screenStateStore: ReturnType<typeof useScreenStateStore>
26
27
  ): MultiSelectProvider {
27
28
  if (!key) {
28
29
  throw new Error("ScreenMultiSelectProvider: Key is required");
@@ -66,7 +67,7 @@ export class ScreenMultiSelectProvider implements MultiSelectProvider {
66
67
  private constructor(
67
68
  private key: string,
68
69
  route: string,
69
- private screenStateStore: ScreenStateStore
70
+ private screenStateStore: ReturnType<typeof useScreenStateStore>
70
71
  ) {
71
72
  if (!key) {
72
73
  throw new Error("ScreenMultiSelectProvider: Key is required");
@@ -88,7 +89,9 @@ export class ScreenMultiSelectProvider implements MultiSelectProvider {
88
89
  log_debug("ScreenMultiSelectProvider: Initializing", { key, route });
89
90
  }
90
91
 
91
- private updateStore(screenStateStore: ScreenStateStore): void {
92
+ private updateStore(
93
+ screenStateStore: ReturnType<typeof useScreenStateStore>
94
+ ): void {
92
95
  if (screenStateStore === this.screenStateStore) {
93
96
  return;
94
97
  }
@@ -104,26 +107,26 @@ export class ScreenMultiSelectProvider implements MultiSelectProvider {
104
107
  (state) => ({
105
108
  value: state.data[this.key],
106
109
  exists: this.key in state.data,
107
- }),
108
- (current, previous) => {
109
- if (!current.exists && previous.exists) {
110
- log_debug(
111
- `ScreenMultiSelectProvider: Key deleted from store: ${this.key}`
112
- );
113
-
114
- // TODO: If we need to handle deletion, we can do it here
115
- }
116
-
117
- if (current.value !== previous.value) {
118
- const items = this.parseStoredValue(current.value);
119
- this.itemSubject.next(items);
120
-
121
- log_debug(`ScreenMultiSelectProvider: Key updated: ${this.key}`, {
122
- previous: this.parseStoredValue(previous.value),
123
- current: items,
124
- });
125
- }
126
- }
110
+ })
111
+ // (current, previous) => {
112
+ // if (!current.exists && previous.exists) {
113
+ // log_debug(
114
+ // `ScreenMultiSelectProvider: Key deleted from store: ${this.key}`
115
+ // );
116
+
117
+ // // TODO: If we need to handle deletion, we can do it here
118
+ // }
119
+
120
+ // if (current.value !== previous.value) {
121
+ // const items = this.parseStoredValue(current.value);
122
+ // this.itemSubject.next(items);
123
+
124
+ // log_debug(`ScreenMultiSelectProvider: Key updated: ${this.key}`, {
125
+ // previous: this.parseStoredValue(previous.value),
126
+ // current: items,
127
+ // });
128
+ // }
129
+ // }
127
130
  );
128
131
 
129
132
  log_debug(
@@ -1,17 +1,16 @@
1
- import * as R from "ramda";
2
-
1
+ import { SafeAreaProvider } from "react-native-safe-area-context";
2
+ import { render } from "@testing-library/react-native";
3
3
  import React, { PropsWithChildren } from "react";
4
- import { View } from "react-native";
5
-
4
+ import configureStore from "redux-mock-store";
6
5
  import { Provider } from "react-redux";
6
+ import { View } from "react-native";
7
7
  import thunk from "redux-thunk";
8
- import configureStore from "redux-mock-store";
9
- import { SafeAreaProvider } from "react-native-safe-area-context";
8
+ import * as R from "ramda";
9
+
10
10
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
11
11
 
12
- import { render } from "@testing-library/react-native";
13
- import { AnalyticsProvider } from "../analyticsUtils";
14
12
  import { ThemeContext } from "../theme";
13
+ import { AnalyticsProvider } from "../analyticsUtils";
15
14
 
16
15
  export { getByTestId } from "./getByTestId";
17
16
 
@@ -11,7 +11,7 @@ class BackgroundTimer {
11
11
  this.uniqueId = 0;
12
12
  this.callbacks = {};
13
13
 
14
- const EventEmitter = platformSelect({
14
+ const EventEmitter: typeof DeviceEventEmitter | undefined = platformSelect({
15
15
  android: DeviceEventEmitter,
16
16
  android_tv: DeviceEventEmitter,
17
17
  amazon: DeviceEventEmitter, // probably does not exist and uses android_tv
@@ -0,0 +1,36 @@
1
+ import { find } from "../find";
2
+
3
+ test("example 1", () => {
4
+ const predicate = <T>(_: T, index: number): boolean => index === 0;
5
+ const xs = ["1", "2", "2", "3", "4"];
6
+
7
+ expect(find(predicate, xs)).toBe("1");
8
+ });
9
+
10
+ test("example 2", () => {
11
+ const predicate = <T>(_: T, index: number): boolean => index === 0;
12
+ const xs: string[] = [];
13
+
14
+ expect(find(predicate, xs)).toBe(undefined);
15
+ });
16
+
17
+ test("example 3", () => {
18
+ const predicate = () => false;
19
+ const xs = ["1", "2", "2", "3"];
20
+
21
+ expect(find(predicate, xs)).toBe(undefined);
22
+ });
23
+
24
+ test("example 4", () => {
25
+ const predicate = <T>(_: T, index: number): boolean => index === 1;
26
+ const xs = ["1", "2", "2", "3"];
27
+
28
+ expect(find(predicate, xs)).toBe("2");
29
+ });
30
+
31
+ test("example 5", () => {
32
+ const predicate = <T>(_: T, index: number): boolean => index === 2;
33
+ const xs = ["1", "2.1", "2", "3", "2", "4"];
34
+
35
+ expect(find(predicate, xs)).toBe("2");
36
+ });
@@ -0,0 +1,37 @@
1
+ import { pathOr } from "../pathOr";
2
+
3
+ test("example 1", () => {
4
+ const defaultValue = "defaultValue";
5
+ const path = ["a", "b", "c"];
6
+ const xs = { a: { b: { c: 1 } } };
7
+
8
+ const output = 1;
9
+
10
+ expect(pathOr(defaultValue, path, xs)).toEqual(output);
11
+ });
12
+
13
+ test("example 2", () => {
14
+ const defaultValue = "defaultValue";
15
+ const path = ["a", "b"];
16
+ const xs = { a: { b: { c: 1 } } };
17
+
18
+ const output = { c: 1 };
19
+
20
+ expect(pathOr(defaultValue, path, xs)).toEqual(output);
21
+ });
22
+
23
+ test("example 3", () => {
24
+ const defaultValue = "defaultValue";
25
+ const path = ["a", "b", "x"];
26
+ const xs = { a: { b: { c: 1 } } };
27
+
28
+ expect(pathOr(defaultValue, path, xs)).toBe(defaultValue);
29
+ });
30
+
31
+ test("example 4", () => {
32
+ const defaultValue = "defaultValue";
33
+ const path = ["a", "b", "c"];
34
+ const xs = undefined;
35
+
36
+ expect(pathOr(defaultValue, path, xs)).toBe(defaultValue);
37
+ });
@@ -0,0 +1,30 @@
1
+ import { startsWith } from "../startsWith";
2
+
3
+ describe("startsWith", () => {
4
+ it("returns false when str is null", () => {
5
+ expect(startsWith("a", null)).toBe(false);
6
+ });
7
+
8
+ it("returns false when str is undefined", () => {
9
+ expect(startsWith("a", undefined)).toBe(false);
10
+ });
11
+
12
+ it("returns true when string starts with target", () => {
13
+ expect(startsWith("he", "hello")).toBe(true);
14
+ expect(startsWith("", "hello")).toBe(true); // empty target always matches
15
+ });
16
+
17
+ it("returns false when string does not start with target", () => {
18
+ expect(startsWith("yo", "hello")).toBe(false);
19
+ });
20
+
21
+ it("works with single character target", () => {
22
+ expect(startsWith("h", "hello")).toBe(true);
23
+ expect(startsWith("x", "hello")).toBe(false);
24
+ });
25
+
26
+ it("is case-sensitive", () => {
27
+ expect(startsWith("He", "hello")).toBe(false);
28
+ expect(startsWith("he", "hello")).toBe(true);
29
+ });
30
+ });
package/utils/find.ts ADDED
@@ -0,0 +1,3 @@
1
+ export const find = (predicate, xs) => {
2
+ return (xs || []).find((x, index) => predicate(x, index));
3
+ };
package/utils/index.ts CHANGED
@@ -2,6 +2,12 @@ export { chunk } from "./chunk";
2
2
 
3
3
  export { times } from "./times";
4
4
 
5
+ export { startsWith } from "./startsWith";
6
+
7
+ export { find } from "./find";
8
+
9
+ export { pathOr } from "./pathOr";
10
+
5
11
  export {
6
12
  cloneDeep as clone,
7
13
  flatten,
@@ -14,7 +20,9 @@ export {
14
20
  flatMap,
15
21
  difference,
16
22
  take,
23
+ pick,
17
24
  map,
18
25
  trim,
19
26
  toString,
27
+ last,
20
28
  } from "lodash";
@@ -0,0 +1,5 @@
1
+ import { get } from "lodash";
2
+
3
+ export const pathOr = (defaultValue, path, record) => {
4
+ return get(record, path, defaultValue);
5
+ };
@@ -0,0 +1,9 @@
1
+ import { isNil } from "lodash";
2
+
3
+ export const startsWith = (target, str) => {
4
+ if (isNil(str)) {
5
+ return false;
6
+ }
7
+
8
+ return str.startsWith(target);
9
+ };