@applicaster/zapp-react-native-utils 13.0.0-alpha.2569962250 → 13.0.0-alpha.2685746452

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 (60) hide show
  1. package/README.md +0 -10
  2. package/analyticsUtils/currentScreenProperities.ts +6 -4
  3. package/appUtils/HooksManager/index.ts +1 -1
  4. package/appUtils/contextKeysManager/index.ts +2 -2
  5. package/appUtils/contextKeysManager/utils/index.ts +2 -1
  6. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +1 -0
  7. package/appUtils/focusManager/index.ts +9 -9
  8. package/appUtils/keyCodes/index.ts +11 -7
  9. package/appUtils/orientationHelper.ts +11 -13
  10. package/appUtils/platform/platformUtils.ts +6 -0
  11. package/appUtils/playerManager/index.ts +1 -1
  12. package/appUtils/playerManager/player.ts +24 -12
  13. package/appUtils/playerManager/playerNative.ts +18 -3
  14. package/dateUtils/index.ts +2 -0
  15. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  16. package/equalUtils/index.ts +49 -30
  17. package/focusManager/FocusManager.ts +11 -1
  18. package/focusManager/index.ts +49 -4
  19. package/functionUtils/index.ts +21 -8
  20. package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
  21. package/manifestUtils/fonts/index.js +5 -6
  22. package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
  23. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +875 -0
  24. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
  25. package/numberUtils/index.ts +7 -5
  26. package/package.json +4 -10
  27. package/playerUtils/configurationGenerator.ts +8 -0
  28. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +5 -7
  29. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  30. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  31. package/reactHooks/navigation/__tests__/index.test.tsx +6 -17
  32. package/reactHooks/navigation/index.ts +13 -23
  33. package/reactHooks/navigation/useProfilerLogging.ts +15 -0
  34. package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
  35. package/reactUtils/__tests__/reactUtils.test.js +1 -19
  36. package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
  37. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +6 -72
  38. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
  39. package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
  40. package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
  41. package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
  42. package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
  43. package/reactUtils/createContext/__tests__/provider.test.js +4 -6
  44. package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
  45. package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
  46. package/reactUtils/createContext/helpers.ts +6 -1
  47. package/reactUtils/createContext/index.ts +11 -25
  48. package/reactUtils/index.ts +0 -11
  49. package/services/js2native.ts +673 -0
  50. package/testUtils/index.tsx +0 -10
  51. package/time/BackgroundTimer.ts +55 -0
  52. package/time/Timer.ts +6 -6
  53. package/utils/README.md +34 -0
  54. package/utils/clone.ts +56 -0
  55. package/utils/flatten.ts +3 -0
  56. package/utils/index.ts +7 -0
  57. package/utils/splitEvery.ts +27 -0
  58. package/utils/times.ts +2 -0
  59. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
  60. /package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +0 -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,34 @@
1
+ ### ramda replacement utils
2
+
3
+ See contribution guide below
4
+
5
+ ## Reference
6
+
7
+
8
+ ### _.flatten
9
+ R.times => flatten.ts
10
+
11
+ ### _.times
12
+ R.times => times.ts
13
+
14
+ ### _.drop
15
+ R.drop(N,array) => array.slice(N)
16
+
17
+ ### _.clone
18
+ R.clone => clone.ts
19
+
20
+ ### _.splitEvery
21
+ R.splitEvery => splitEvery.ts
22
+
23
+ ### _.length
24
+ R.length(data) => data?.length ?? 0
25
+
26
+ ## Contribution
27
+
28
+ To add new helper function
29
+
30
+ 1. Search for replacement ( you can reuse lodash, preferable pure JS solution), arguments should match with Ramda definition
31
+ 2. Add new file, update exports in index file
32
+ 3. If replacement is simple enough that doesn't need a function - add snippet to this README
33
+ 4. Make sure README is updated and contains reference for newly added function
34
+ 5. Write unit test to test input/output. You can use AI's help.
package/utils/clone.ts ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Creates a deep copy of the value which may contain (nested) `Array`s and `Object`s,
3
+ * `Number`s, `String`s, `Boolean`s and `Date`s. `Function`s are assigned by reference
4
+ * rather than copied. Dispatches to a `clone` method if present.
5
+ *
6
+ * @param {*} value - The value to clone
7
+ * @return {*} A deep copy of the provided value
8
+ */
9
+ export const clone = (value) => {
10
+ // Handle null or undefined
11
+ if (value == null) {
12
+ return value;
13
+ }
14
+
15
+ // Check if value has a custom clone method
16
+ if (typeof value.clone === "function") {
17
+ return value.clone();
18
+ }
19
+
20
+ // Handle primitive types (they're immutable so no need to clone)
21
+ if (typeof value !== "object") {
22
+ return value;
23
+ }
24
+
25
+ // Handle Date objects
26
+ if (value instanceof Date) {
27
+ return new Date(value.getTime());
28
+ }
29
+
30
+ // Handle RegExp objects
31
+ if (value instanceof RegExp) {
32
+ return new RegExp(value.source, value.flags);
33
+ }
34
+
35
+ // Handle Array objects
36
+ if (Array.isArray(value)) {
37
+ return value.map((item) => clone(item));
38
+ }
39
+
40
+ // Handle Object literals
41
+ if (Object.prototype.toString.call(value) === "[object Object]") {
42
+ const result = {};
43
+ const keys = Object.keys(value);
44
+
45
+ for (let i = 0; i < keys.length; i++) {
46
+ const key = keys[i];
47
+ result[key] = clone(value[key]);
48
+ }
49
+
50
+ return result;
51
+ }
52
+
53
+ // For other types like Maps, Sets, etc., we would need additional handling
54
+ // For simplicity, we'll return the original value for unsupported types
55
+ return value;
56
+ };
@@ -0,0 +1,3 @@
1
+ export const flatten = <T>(array: (T & T[])[]) => {
2
+ return array.flat(Infinity);
3
+ };
package/utils/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { times } from "./times";
2
+
3
+ export { flatten } from "./flatten";
4
+
5
+ export { clone } from "./clone";
6
+
7
+ export { splitEvery } from "./splitEvery";
@@ -0,0 +1,27 @@
1
+ export function splitEvery(size, collection) {
2
+ if (size <= 0) {
3
+ throw new Error("First argument to splitEvery must be a positive integer");
4
+ }
5
+
6
+ const result = [];
7
+
8
+ // Handle string input
9
+ if (typeof collection === "string") {
10
+ for (let i = 0; i < collection.length; i += size) {
11
+ result.push(collection.slice(i, i + size));
12
+ }
13
+
14
+ return result;
15
+ }
16
+
17
+ // Handle array input
18
+ if (Array.isArray(collection)) {
19
+ for (let i = 0; i < collection.length; i += size) {
20
+ result.push(collection.slice(i, i + size));
21
+ }
22
+
23
+ return result;
24
+ }
25
+
26
+ return result;
27
+ }
package/utils/times.ts ADDED
@@ -0,0 +1,2 @@
1
+ export const times = (fn, n) =>
2
+ Array.from({ length: n }, (_, index) => fn(index));
@@ -1,27 +0,0 @@
1
- jest.mock("create-react-context", () =>
2
- jest.fn(() => ({
3
- Consumer: jest.fn(),
4
- Provider: jest.fn(),
5
- }))
6
- );
7
-
8
- jest.mock("react", () => ({
9
- ...jest.requireActual("react"),
10
- createContext: undefined,
11
- }));
12
-
13
- const { createContext } = require("../index");
14
- const createReactContext = require("create-react-context");
15
-
16
- describe("when react context api is not defined", () => {
17
- it("uses the polyfill", () => {
18
- createContext({ foo: "bar" });
19
-
20
- expect(createReactContext).toHaveBeenCalledWith(
21
- expect.objectContaining({
22
- foo: "bar",
23
- setFoo: expect.any(Function),
24
- })
25
- );
26
- });
27
- });