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

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 (51) hide show
  1. package/README.md +0 -10
  2. package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
  3. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
  4. package/analyticsUtils/currentScreenProperities.ts +6 -4
  5. package/analyticsUtils/index.tsx +3 -4
  6. package/analyticsUtils/manager.ts +1 -1
  7. package/appUtils/HooksManager/index.ts +1 -1
  8. package/appUtils/contextKeysManager/index.ts +2 -2
  9. package/appUtils/contextKeysManager/utils/index.ts +2 -1
  10. package/appUtils/focusManager/index.ts +1 -10
  11. package/appUtils/keyCodes/index.ts +11 -7
  12. package/appUtils/orientationHelper.ts +0 -1
  13. package/appUtils/platform/platformUtils.ts +6 -0
  14. package/appUtils/playerManager/index.ts +1 -1
  15. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  16. package/equalUtils/index.ts +49 -30
  17. package/focusManager/FocusManager.ts +14 -28
  18. package/focusManager/index.ts +41 -4
  19. package/functionUtils/index.ts +21 -8
  20. package/manifestUtils/fonts/index.js +5 -6
  21. package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
  22. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +875 -0
  23. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
  24. package/numberUtils/index.ts +7 -5
  25. package/package.json +4 -9
  26. package/reactHooks/app/useAppState.ts +2 -2
  27. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +5 -7
  28. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  29. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +39 -88
  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 +12 -24
  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/testUtils/index.tsx +7 -18
  50. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
  51. /package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +0 -0
@@ -1,5 +1,5 @@
1
- import React, { useEffect, useMemo } from "react";
2
- import { BackHandler, InteractionManager, NativeModules } from "react-native";
1
+ import { useContext, useEffect, useMemo, useRef } from "react";
2
+ import { BackHandler } from "react-native";
3
3
 
4
4
  import {
5
5
  useContentTypes,
@@ -31,6 +31,8 @@ export { useGetBottomTabBarHeight } from "./useGetBottomTabBarHeight";
31
31
 
32
32
  export { useIsScreenActive } from "./useIsScreenActive";
33
33
 
34
+ export { useProfilerLogging } from "./useProfilerLogging";
35
+
34
36
  export {
35
37
  useUniqueRouteSuffix,
36
38
  useNavbarId,
@@ -106,11 +108,11 @@ export function isNavBarVisible(
106
108
  return false;
107
109
  }
108
110
 
109
- const hideSecondaryLevel = screenData?.navigations?.some(
110
- (navigation) => navigation.styles?.hide_secondary_level_menu
111
+ const showSecondaryLevel = screenData?.navigations?.some(
112
+ (navigation) => navigation.styles?.show_secondary_level_menu
111
113
  );
112
114
 
113
- if (canGoBack && hideSecondaryLevel) {
115
+ if (canGoBack && !showSecondaryLevel) {
114
116
  return false;
115
117
  }
116
118
 
@@ -121,14 +123,12 @@ export function isNavBarVisible(
121
123
  return true;
122
124
  }
123
125
 
124
- const { ProfilerBridge } = NativeModules;
125
-
126
126
  export const useBackHandler = (cb: () => boolean) => {
127
- React.useEffect(() => {
128
- BackHandler.addEventListener("hardwareBackPress", cb);
127
+ useEffect(() => {
128
+ const unsubscribe = BackHandler.addEventListener("hardwareBackPress", cb);
129
129
 
130
130
  return () => {
131
- BackHandler.removeEventListener("hardwareBackPress", cb);
131
+ unsubscribe.remove();
132
132
  };
133
133
  }, [cb]);
134
134
  };
@@ -158,7 +158,7 @@ export const useZappHooksForEntry = (
158
158
  setIsHooksExecutionInProgress,
159
159
  setIsPresentingFullScreen,
160
160
  setIsRunningInBackground,
161
- }: HookModalContextT = React.useContext(ZappHookModalContext.ReactContext);
161
+ }: HookModalContextT = useContext(ZappHookModalContext.ReactContext);
162
162
 
163
163
  const {
164
164
  appData: { layoutVersion },
@@ -256,22 +256,10 @@ export const useZappHooksForEntry = (
256
256
  }, [entry.id]);
257
257
  };
258
258
 
259
- export const useProfilerLogging = () => {
260
- const logTimestamp = (data: string) =>
261
- InteractionManager.runAfterInteractions(() => {
262
- if (ProfilerBridge && data) {
263
- ProfilerBridge.updateTimer("navigation", data, Date.now());
264
- }
265
- });
266
-
267
- return logTimestamp;
268
- };
269
-
270
259
  export const useRunIfLongPress = (
271
260
  options = { timeout: LONG_KEY_PRESS_TIMEOUT }
272
261
  ) => {
273
- const pressTimeout =
274
- React.useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
262
+ const pressTimeout = useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
275
263
 
276
264
  const resetTimeout = () => {
277
265
  clearTimeout(pressTimeout.current as ReturnType<typeof setTimeout>);
@@ -0,0 +1,15 @@
1
+ import { useCallback } from "react";
2
+ import { InteractionManager, NativeModules } from "react-native";
3
+
4
+ const { ProfilerBridge } = NativeModules;
5
+
6
+ export const useProfilerLogging = () =>
7
+ useCallback(
8
+ (data: string) =>
9
+ InteractionManager.runAfterInteractions(() => {
10
+ if (ProfilerBridge && data) {
11
+ ProfilerBridge.updateTimer("navigation", data, Date.now());
12
+ }
13
+ }),
14
+ []
15
+ );
@@ -1,6 +1,6 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`addLifeCycleMethods attaches the lifecycle method to the component 1`] = `
3
+ exports[`reactUtils helpers addLifeCycleMethods attaches the lifecycle method to the component 1`] = `
4
4
  <View>
5
5
  <Text>
6
6
  I'm a class component
@@ -8,7 +8,7 @@ exports[`addLifeCycleMethods attaches the lifecycle method to the component 1`]
8
8
  </View>
9
9
  `;
10
10
 
11
- exports[`attachMethodToPrototype attaches a lifecycle method to the component's prototype 1`] = `
11
+ exports[`reactUtils helpers attachMethodToPrototype attaches a lifecycle method to the component's prototype 1`] = `
12
12
  <View>
13
13
  <Text>
14
14
  I'm a class component
@@ -16,6 +16,18 @@ exports[`attachMethodToPrototype attaches a lifecycle method to the component's
16
16
  </View>
17
17
  `;
18
18
 
19
- exports[`attachMethodToPrototype preserves any existing lifecycle method 1`] = `<StatelessComponent />`;
19
+ exports[`reactUtils helpers attachMethodToPrototype preserves any existing lifecycle method 1`] = `
20
+ <View>
21
+ <Text>
22
+ I'm a stateless component
23
+ </Text>
24
+ </View>
25
+ `;
20
26
 
21
- exports[`wrapInClass wraps the stateless component in a class 1`] = `<StatelessComponent />`;
27
+ exports[`reactUtils helpers wrapInClass wraps the stateless component in a class 1`] = `
28
+ <View>
29
+ <Text>
30
+ I'm a stateless component
31
+ </Text>
32
+ </View>
33
+ `;
@@ -7,7 +7,7 @@ import {
7
7
  componentDidMount,
8
8
  } from "./fixtures";
9
9
 
10
- import { attachLifeCycleMethods, createReactRef, mergeChildrenProps } from "..";
10
+ import { attachLifeCycleMethods, mergeChildrenProps } from "..";
11
11
 
12
12
  describe("attachLifeCycleMethods", () => {
13
13
  let addLifeCycleMethodsSpy;
@@ -41,24 +41,6 @@ describe("attachLifeCycleMethods", () => {
41
41
  });
42
42
  });
43
43
 
44
- describe("createReactRef", () => {
45
- it("calls the React.createRef function if it exists", () => {
46
- jest.clearAllMocks();
47
-
48
- const ref = createReactRef();
49
- expect(ref).toHaveProperty("current");
50
- });
51
-
52
- it("calls the polyfill if React.createRef doesn't exist", () => {
53
- jest.clearAllMocks();
54
- const originalCreateRef = React.createRef;
55
- React.createRef = undefined;
56
- const ref = createReactRef();
57
- expect(ref).toHaveProperty("current");
58
- React.createRef = originalCreateRef;
59
- });
60
- });
61
-
62
44
  describe("mergeChildrenProps", () => {
63
45
  it("returns the cloned children with the merged props", () => {
64
46
  const Egg = () => React.createElement("Egg");
@@ -1,6 +1,5 @@
1
1
  import * as React from "react";
2
- import { shallow } from "enzyme";
3
- import { shallowToJson } from "enzyme-to-json";
2
+ import { render } from "@testing-library/react-native";
4
3
 
5
4
  import {
6
5
  isClassComponent,
@@ -20,98 +19,100 @@ import {
20
19
  } from "./fixtures";
21
20
 
22
21
  describe("reactUtils helpers", () => {
23
- it("should have isNilOrEmpty", () => {
24
- expect(isNilOrEmpty).toBeDefined();
25
- expect(isNilOrEmpty(null)).toBeTruthy();
26
- expect(isNilOrEmpty(undefined)).toBeTruthy();
27
- expect(isNilOrEmpty("")).toBeTruthy();
28
- expect(isNilOrEmpty([])).toBeTruthy();
22
+ describe("isNilOrEmpty", () => {
23
+ it("should return correct output", () => {
24
+ expect(isNilOrEmpty).toBeDefined();
25
+ expect(isNilOrEmpty(null)).toBeTruthy();
26
+ expect(isNilOrEmpty(undefined)).toBeTruthy();
27
+ expect(isNilOrEmpty("")).toBeTruthy();
28
+ expect(isNilOrEmpty([])).toBeTruthy();
29
+ });
29
30
  });
30
- });
31
31
 
32
- describe("isClassComponent", () => {
33
- it("returns true if the component is a class component", () => {
34
- expect(isClassComponent(ClassComponent)).toBe(true);
35
- });
32
+ describe("isClassComponent", () => {
33
+ it("returns true if the component is a class component", () => {
34
+ expect(isClassComponent(ClassComponent)).toBe(true);
35
+ });
36
36
 
37
- it("returns false otherwise", () => {
38
- expect(isClassComponent(StatelessComponent)).toBe(false);
37
+ it("returns false otherwise", () => {
38
+ expect(isClassComponent(StatelessComponent)).toBe(false);
39
+ });
39
40
  });
40
- });
41
41
 
42
- describe("attachMethodToPrototype", () => {
43
- const initialWrapper = shallow(<ClassComponent />);
42
+ describe("attachMethodToPrototype", () => {
43
+ const initialWrapper = render(<ClassComponent />);
44
44
 
45
- expect(initialWrapper.instance()).not.toHaveProperty(
46
- COMPONENT_DID_MOUNT_METHOD
47
- );
48
-
49
- afterEach(() => {
50
- componentDidMount.mockClear();
51
- });
52
-
53
- it("attaches a lifecycle method to the component's prototype", () => {
54
- const NewComponent = attachMethodToPrototype(ClassComponent)(
55
- componentDidMount,
45
+ expect(initialWrapper.toJSON()).not.toHaveProperty(
56
46
  COMPONENT_DID_MOUNT_METHOD
57
47
  );
58
48
 
59
- const wrapper = shallow(<NewComponent />);
49
+ afterEach(() => {
50
+ componentDidMount.mockClear();
51
+ });
60
52
 
61
- expect(shallowToJson(wrapper)).toMatchSnapshot();
62
- expect(wrapper.instance()).toHaveProperty(COMPONENT_DID_MOUNT_METHOD);
63
- expect(componentDidMount).toHaveBeenCalled();
64
- });
53
+ it("attaches a lifecycle method to the component's prototype", () => {
54
+ const NewComponent = attachMethodToPrototype(ClassComponent)(
55
+ componentDidMount,
56
+ COMPONENT_DID_MOUNT_METHOD
57
+ );
65
58
 
66
- it("preserves any existing lifecycle method", () => {
67
- const NewComponent = attachMethodToPrototype(ComponentWithLifeCycle)(
68
- componentDidMount,
69
- COMPONENT_DID_MOUNT_METHOD
70
- );
59
+ const wrapper = render(<NewComponent />);
71
60
 
72
- expect(componentDidMount).not.toHaveBeenCalled();
61
+ expect(wrapper.toJSON(wrapper)).toMatchSnapshot();
62
+ expect(new NewComponent()).toHaveProperty(COMPONENT_DID_MOUNT_METHOD);
63
+ expect(componentDidMount).toHaveBeenCalled();
64
+ });
73
65
 
74
- const wrapper = shallow(<NewComponent />);
66
+ it("preserves any existing lifecycle method", () => {
67
+ const NewComponent = attachMethodToPrototype(ComponentWithLifeCycle)(
68
+ componentDidMount,
69
+ COMPONENT_DID_MOUNT_METHOD
70
+ );
75
71
 
76
- expect(shallowToJson(wrapper)).toMatchSnapshot();
77
- expect(componentDidMount).toHaveBeenCalled();
78
- expect(existingMethod).toHaveBeenCalled();
79
- });
80
- });
72
+ expect(componentDidMount).not.toHaveBeenCalled();
81
73
 
82
- describe("wrapInClass", () => {
83
- let NewComponent;
84
- let wrapper;
74
+ const wrapper = render(<NewComponent />);
85
75
 
86
- beforeEach(() => {
87
- NewComponent = wrapInClass(StatelessComponent);
88
- wrapper = shallow(<NewComponent />);
76
+ expect(wrapper.toJSON()).toMatchSnapshot();
77
+ expect(componentDidMount).toHaveBeenCalled();
78
+ expect(existingMethod).toHaveBeenCalled();
79
+ });
89
80
  });
90
81
 
91
- it("wraps the stateless component in a class", () => {
92
- expect(isClassComponent(NewComponent)).toBe(true);
93
- expect(shallowToJson(wrapper)).toMatchSnapshot();
94
- });
95
- });
82
+ describe("wrapInClass", () => {
83
+ let NewComponent;
84
+ let wrapper;
96
85
 
97
- describe("addLifeCycleMethods", () => {
98
- let NewComponent;
99
- let wrapper;
86
+ beforeEach(() => {
87
+ NewComponent = wrapInClass(StatelessComponent);
88
+ wrapper = render(<NewComponent />);
89
+ });
100
90
 
101
- beforeEach(() => {
102
- NewComponent = addLifeCycleMethods({ componentDidMount })(ClassComponent);
103
- wrapper = shallow(<NewComponent />);
91
+ it("wraps the stateless component in a class", () => {
92
+ expect(isClassComponent(NewComponent)).toBe(true);
93
+ expect(wrapper.toJSON()).toMatchSnapshot();
94
+ });
104
95
  });
105
96
 
106
- afterEach(() => {
107
- componentDidMount.mockClear();
108
- });
97
+ describe("addLifeCycleMethods", () => {
98
+ let NewComponent;
99
+ let wrapper;
109
100
 
110
- it("attaches the lifecycle method to the component", () => {
111
- expect(shallowToJson(wrapper)).toMatchSnapshot();
112
- });
101
+ beforeEach(() => {
102
+ NewComponent = addLifeCycleMethods({ componentDidMount })(ClassComponent);
103
+ wrapper = render(<NewComponent />);
104
+ });
105
+
106
+ afterEach(() => {
107
+ componentDidMount.mockClear();
108
+ });
109
+
110
+ it("attaches the lifecycle method to the component", () => {
111
+ expect(wrapper.toJSON()).toMatchSnapshot();
112
+ });
113
113
 
114
- it("adds the lifecycle method to the component", () => {
115
- expect(componentDidMount).toHaveBeenCalled();
114
+ it("adds the lifecycle method to the component", () => {
115
+ expect(componentDidMount).toHaveBeenCalled();
116
+ });
116
117
  });
117
118
  });
@@ -1,59 +1,27 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 1`] = `
3
+ exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 1`] = `
4
4
  {
5
5
  "bar": "bar",
6
6
  "foo": "foo",
7
7
  }
8
8
  `;
9
9
 
10
- exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 2`] = `
11
- {
12
- "bar": "bar",
13
- "foo": "invalid foo",
14
- }
15
- `;
16
-
17
- exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 3`] = `
18
- {
19
- "bar": "invalid bar",
20
- "foo": "invalid foo",
21
- }
22
- `;
23
-
24
- exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 4`] = `
25
- [
26
- [
27
- [Function],
28
- ],
29
- [
30
- [Function],
31
- ],
32
- ]
33
- `;
34
-
35
- exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 1`] = `
10
+ exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 2`] = `
36
11
  {
37
12
  "bar": "bar",
38
13
  "foo": "foo",
39
14
  }
40
15
  `;
41
16
 
42
- exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 2`] = `
17
+ exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 3`] = `
43
18
  {
44
19
  "bar": "bar",
45
- "foo": "new foo",
46
- }
47
- `;
48
-
49
- exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 3`] = `
50
- {
51
- "bar": "new bar",
52
- "foo": "new foo",
20
+ "foo": "foo",
53
21
  }
54
22
  `;
55
23
 
56
- exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 4`] = `
24
+ exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 4`] = `
57
25
  [
58
26
  [
59
27
  [Function],
@@ -64,43 +32,9 @@ exports[`createContextSetters when state validator is provided calls setState wh
64
32
  ]
65
33
  `;
66
34
 
67
- exports[`createContextSetters when state validator is provided skips the update if the new value is the same as the previous one 1`] = `
35
+ exports[`helpers createContextSetters when state validator is provided skips the update if the new value is the same as the previous one 1`] = `
68
36
  {
69
37
  "bar": "bar",
70
38
  "foo": "new foo",
71
39
  }
72
40
  `;
73
-
74
- exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 1`] = `
75
- {
76
- "bar": "bar",
77
- "foo": "foo",
78
- }
79
- `;
80
-
81
- exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 2`] = `
82
- {
83
- "bar": "bar",
84
- "foo": "foo",
85
- }
86
- `;
87
-
88
- exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 3`] = `
89
- {
90
- "bar": "bar",
91
- "foo": "foo",
92
- }
93
- `;
94
-
95
- exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 4`] = `
96
- [
97
- [
98
- "trying to invoke setFoo with invalid foo - but it was rejected by the state validator
99
- skipping context update",
100
- ],
101
- [
102
- "trying to invoke setBar with invalid bar - but it was rejected by the state validator
103
- skipping context update",
104
- ],
105
- ]
106
- `;
@@ -1,32 +1,7 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`createProvider creates a context Provider component 1`] = `
4
- <mockConstructor
5
- value={
6
- {
7
- "context": "initialValue",
8
- "otherContext": "otherValue",
9
- "setContext": [Function],
10
- "setOtherContext": [Function],
11
- }
12
- }
13
- >
14
- <MockChild
15
- context="context"
16
- />
17
- </mockConstructor>
18
- `;
19
-
20
- exports[`createProvider creates a context Provider component 2`] = `
21
- {
22
- "children": <MockChild
23
- context="context"
24
- />,
25
- "value": {
26
- "context": "initialValue",
27
- "otherContext": "otherValue",
28
- "setContext": [Function],
29
- "setOtherContext": [Function],
30
- },
31
- }
4
+ <View>
5
+ context
6
+ </View>
32
7
  `;
@@ -1,8 +1,7 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`createConsumer creates a context consumer function 1`] = `
4
- <Child
5
- context="foo"
6
- setContext={[MockFunction]}
7
- />
4
+ <View>
5
+ foo
6
+ </View>
8
7
  `;
@@ -1,7 +1,11 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`withProvider decorates a component with the provider 1`] = `
4
- <Provider>
5
- <Component />
6
- </Provider>
4
+ <View>
5
+ <View>
6
+ <Text>
7
+ I am a Component
8
+ </Text>
9
+ </View>
10
+ </View>
7
11
  `;