@applicaster/zapp-react-native-utils 13.0.0-alpha.1700735421 → 13.0.0-alpha.1711912250

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 (74) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +126 -6
  2. package/actionsExecutor/consts.ts +4 -0
  3. package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
  4. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +1 -2
  5. package/analyticsUtils/index.tsx +4 -3
  6. package/analyticsUtils/manager.ts +1 -1
  7. package/appUtils/HooksManager/Hook.ts +4 -0
  8. package/appUtils/HooksManager/index.ts +2 -0
  9. package/appUtils/__tests__/__snapshots__/localizationsHelper.test.ts.snap +151 -0
  10. package/appUtils/__tests__/allZappLocales.ts +79 -0
  11. package/appUtils/__tests__/{localizationsHelper.test.js → localizationsHelper.test.ts} +11 -0
  12. package/appUtils/contextKeysManager/contextResolver.ts +1 -12
  13. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -0
  14. package/appUtils/focusManager/index.ios.ts +14 -4
  15. package/appUtils/focusManager/index.ts +13 -0
  16. package/appUtils/focusManager/utils/__tests__/findChild.test.ts +35 -0
  17. package/appUtils/focusManager/utils/index.ts +5 -0
  18. package/appUtils/localizationsHelper.ts +31 -0
  19. package/appUtils/orientationHelper.ts +11 -12
  20. package/appUtils/playerManager/player.ts +24 -12
  21. package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +11 -7
  22. package/appUtils/playerManager/playerNative.ts +18 -3
  23. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +7 -1
  24. package/cellUtils/index.ts +9 -5
  25. package/componentsUtils/__tests__/isFirstComponentGallery.test.ts +33 -0
  26. package/componentsUtils/__tests__/isFirstComponentScreenPicker.test.ts +33 -0
  27. package/componentsUtils/__tests__/isGallery.test.ts +33 -0
  28. package/componentsUtils/__tests__/isScreenPicker.test.ts +33 -0
  29. package/componentsUtils/index.ts +39 -0
  30. package/dateUtils/index.ts +19 -0
  31. package/focusManager/FocusManager.ts +3 -1
  32. package/focusManager/index.ts +3 -21
  33. package/functionUtils/index.ts +25 -0
  34. package/index.d.ts +0 -12
  35. package/localizationUtils/index.ts +8 -13
  36. package/manifestUtils/defaultManifestConfigurations/generalContent.js +13 -0
  37. package/manifestUtils/defaultManifestConfigurations/player.js +10 -4
  38. package/manifestUtils/index.js +2 -0
  39. package/manifestUtils/keys.js +27 -2
  40. package/modalState/__tests__/index.test.ts +51 -0
  41. package/modalState/index.ts +32 -2
  42. package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +1 -0
  43. package/navigationUtils/index.ts +3 -1
  44. package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +23 -3
  45. package/numberUtils/index.ts +4 -0
  46. package/package.json +2 -3
  47. package/playerUtils/configurationGenerator.ts +9 -11
  48. package/reactHooks/advertising/index.ts +5 -5
  49. package/reactHooks/app/useAppState.ts +2 -2
  50. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +88 -39
  51. package/reactHooks/feed/useBatchLoading.ts +10 -12
  52. package/reactHooks/feed/useFeedLoader.tsx +17 -8
  53. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +39 -0
  54. package/reactHooks/navigation/{useGetTabBarHeight.ts → getTabBarHeight.ts} +1 -1
  55. package/reactHooks/navigation/index.ts +7 -5
  56. package/reactHooks/navigation/useGetBottomTabBarHeight.ts +10 -3
  57. package/reactHooks/navigation/useNavigationPluginData.ts +8 -4
  58. package/reactHooks/navigation/useNavigationType.ts +4 -2
  59. package/reactHooks/navigation/useRoute.ts +4 -6
  60. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +69 -0
  61. package/reactHooks/screen/useScreenBackgroundColor.ts +3 -15
  62. package/reactHooks/useListenEventBusEvent.ts +1 -1
  63. package/reactUtils/index.ts +9 -0
  64. package/services/js2native.ts +673 -0
  65. package/testUtils/index.tsx +8 -7
  66. package/time/BackgroundTimer.ts +55 -0
  67. package/time/Timer.ts +6 -6
  68. package/utils/README.md +30 -0
  69. package/utils/chunk.ts +5 -0
  70. package/utils/index.ts +5 -0
  71. package/utils/times.ts +5 -0
  72. package/zappFrameworkUtils/localStorageHelper.ts +6 -0
  73. package/zappFrameworkUtils/loginPluginUtils.ts +6 -2
  74. package/zappFrameworkUtils/types.ts +11 -0
@@ -0,0 +1,55 @@
1
+ import { DeviceEventEmitter, NativeModules } from "react-native";
2
+ import { platformSelect } from "../reactUtils";
3
+
4
+ const { BackgroundTimer: RNBackgroundTimer } = NativeModules;
5
+
6
+ class BackgroundTimer {
7
+ private uniqueId: number;
8
+ private readonly callbacks: Record<number, () => void>;
9
+
10
+ constructor() {
11
+ this.uniqueId = 0;
12
+ this.callbacks = {};
13
+
14
+ const EventEmitter = platformSelect({
15
+ android: DeviceEventEmitter,
16
+ ios: undefined,
17
+ default: undefined,
18
+ });
19
+
20
+ EventEmitter?.addListener("BackgroundTimer.timer.fired", (id: number) => {
21
+ if (this.callbacks[id]) {
22
+ const callback = this.callbacks[id];
23
+ delete this.callbacks[id];
24
+ callback();
25
+ }
26
+ });
27
+ }
28
+
29
+ setTimeout(callback, timeout): number | NodeJS.Timeout {
30
+ if (!RNBackgroundTimer) {
31
+ return global.setTimeout(callback, timeout);
32
+ }
33
+
34
+ this.uniqueId += 1;
35
+ const timeoutId = this.uniqueId;
36
+
37
+ this.callbacks[timeoutId] = callback;
38
+ RNBackgroundTimer.setTimeout(timeoutId, timeout);
39
+
40
+ return timeoutId;
41
+ }
42
+
43
+ clearTimeout(timeoutId: number | NodeJS.Timeout): void {
44
+ if (!RNBackgroundTimer) {
45
+ return global.clearTimeout(timeoutId as NodeJS.Timeout);
46
+ }
47
+
48
+ if (this.callbacks[timeoutId as number]) {
49
+ delete this.callbacks[timeoutId as number];
50
+ RNBackgroundTimer.clearTimeout(timeoutId);
51
+ }
52
+ }
53
+ }
54
+
55
+ export default new BackgroundTimer();
package/time/Timer.ts CHANGED
@@ -1,19 +1,19 @@
1
+ import BackgroundTimer from "./BackgroundTimer";
2
+
1
3
  export class Timer {
2
4
  private startTime: number;
3
- private remaining: number;
4
- private timeoutId: NodeJS.Timeout | null;
5
+ private timeoutId: number | NodeJS.Timeout | null;
5
6
 
6
7
  constructor(
7
8
  private callback: () => void,
8
- private duration: number
9
+ private remaining: number = null
9
10
  ) {
10
- this.remaining = this.duration;
11
11
  this.timeoutId = null;
12
12
  }
13
13
 
14
14
  start(): void {
15
15
  this.startTime = Date.now();
16
- this.timeoutId = setTimeout(this.callback, this.remaining);
16
+ this.timeoutId = BackgroundTimer.setTimeout(this.callback, this.remaining);
17
17
 
18
18
  this.remaining = 0;
19
19
  }
@@ -29,6 +29,6 @@ export class Timer {
29
29
  }
30
30
 
31
31
  clear(): void {
32
- clearTimeout(this.timeoutId);
32
+ BackgroundTimer.clearTimeout(this.timeoutId);
33
33
  }
34
34
  }
@@ -0,0 +1,30 @@
1
+ ### ramda replacement utils
2
+
3
+ See contribution guide below
4
+
5
+ ## Reference
6
+
7
+ Prefer non-fp variant as it more performant - if refactoring assumes you need more efforts rewrite ramda sample to lodash and it can be easily replaced with lodash-fp - use lodash-fp.
8
+
9
+ ### Ramda alternatives:
10
+
11
+ Custom
12
+ - `splitEvery` => `chunk`
13
+ - `times` => `times`
14
+
15
+ From `lodash`
16
+ - `clone` => `clone`
17
+ - `flatten` => `flatten`
18
+ - `drop` => `drop`
19
+ - `length` => `size`
20
+
21
+
22
+ ## Contribution
23
+
24
+ To add new helper function as ramda replacement
25
+
26
+ 1. Search for replacement ( you can use lodash or pure JS solution), arguments should match with Ramda definition (for easier transition).
27
+ 2. Add new file if needed, add test, update exports in index file. 2.1. Make sure it's well-typed.
28
+ 3. If the function can-be reexported from other 3rd party lib - update index.ts to re-export it.
29
+ 4. Make sure README is updated and contains reference for newly added function.
30
+ 5. You can use AI's help. Use query like 'lodash & lodash/fp equivalent of Ramda's R.clone function' to get an options you can use.
package/utils/chunk.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { chunk as _chunk } from "lodash";
2
+
3
+ export const chunk = <T>(size: number, array: T[]): T[][] => {
4
+ return _chunk(array, size);
5
+ };
package/utils/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { chunk } from "./chunk";
2
+
3
+ export { times } from "./times";
4
+
5
+ export { cloneDeep as clone, flatten, drop, size, isNil } from "lodash";
package/utils/times.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { times as _times } from "lodash";
2
+
3
+ export const times = <T>(iteratee: (index: number) => T, n: number) => {
4
+ return _times(n, iteratee);
5
+ };
@@ -1,6 +1,12 @@
1
1
  import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
2
2
  import { isNilOrEmpty } from "../reactUtils/helpers";
3
3
  import { parseJsonIfNeeded } from "@applicaster/zapp-react-native-utils/functionUtils";
4
+ import {
5
+ StorageOwnedValues,
6
+ NamespaceValues,
7
+ StorageValuesToRemove,
8
+ StorageValuesToAdd,
9
+ } from "./types";
4
10
 
5
11
  const defaultOwnedKey = "owned_keys";
6
12
  const DEFAULT_NAMESPACE = "applicaster.v2";
@@ -89,11 +89,15 @@ const runInBackground = async ({
89
89
  const shouldPresent = await hookPresentPolicy.shouldPresentScreen();
90
90
 
91
91
  if (!shouldPresent) {
92
+ const isRefreshed = await checkUserAuthenticated();
93
+
92
94
  log_info(
93
- "runInBackground: Background mode finished, hook plugin will be skipped"
95
+ `runInBackground: Background mode finished, ${isRefreshed ? "finish hook with completion true" : "refresh failed will presentUI"}`
94
96
  );
95
97
 
96
- await checkUserAuthenticated();
98
+ isRefreshed
99
+ ? callback({ success: isRefreshed, payload: item })
100
+ : presentUI();
97
101
 
98
102
  return;
99
103
  }
@@ -0,0 +1,11 @@
1
+ export type StorageValuesToAdd = Record<string, NamespaceValues>;
2
+
3
+ export type StorageValuesToRemove = {
4
+ string?: string[];
5
+ };
6
+
7
+ export type StorageOwnedValues = {
8
+ string?: string[];
9
+ };
10
+
11
+ export type NamespaceValues = Record<string, string>;