@applicaster/zapp-react-native-utils 13.0.0-rc.14 → 13.0.0-rc.140

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 (185) hide show
  1. package/README.md +0 -10
  2. package/actionsExecutor/ActionExecutor.ts +16 -9
  3. package/actionsExecutor/ActionExecutorContext.tsx +214 -16
  4. package/actionsExecutor/consts.ts +4 -0
  5. package/alertUtils/alert.ts +148 -0
  6. package/alertUtils/index.ts +1 -148
  7. package/analyticsUtils/AnalyticPlayerListener.ts +18 -1
  8. package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
  9. package/analyticsUtils/currentScreenProperities.ts +6 -4
  10. package/analyticsUtils/helpers/hooks.ts +1 -1
  11. package/appUtils/HooksManager/Hook.ts +6 -2
  12. package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +7 -7
  13. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +186 -186
  14. package/appUtils/HooksManager/index.ts +3 -1
  15. package/appUtils/HooksManager/types.ts +5 -2
  16. package/appUtils/__tests__/__snapshots__/localizationsHelper.test.ts.snap +151 -0
  17. package/appUtils/__tests__/allZappLocales.ts +79 -0
  18. package/appUtils/__tests__/{localizationsHelper.test.js → localizationsHelper.test.ts} +11 -0
  19. package/appUtils/accessibilityManager/const.ts +18 -0
  20. package/appUtils/accessibilityManager/index.ts +46 -2
  21. package/appUtils/contextKeysManager/contextResolver.ts +66 -0
  22. package/appUtils/contextKeysManager/index.ts +2 -2
  23. package/appUtils/contextKeysManager/utils/index.ts +2 -1
  24. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +9 -6
  25. package/appUtils/focusManager/index.ios.ts +14 -4
  26. package/appUtils/focusManager/index.ts +108 -69
  27. package/appUtils/focusManager/treeDataStructure/Tree/index.js +23 -0
  28. package/appUtils/focusManager/utils/__tests__/findChild.test.ts +35 -0
  29. package/appUtils/focusManager/utils/enums.ts +4 -0
  30. package/appUtils/focusManager/utils/index.ts +5 -0
  31. package/appUtils/focusManagerAux/utils/index.ts +4 -3
  32. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
  33. package/appUtils/keyCodes/__tests__/keyCodes.test.js +1 -1
  34. package/appUtils/keyCodes/index.ts +11 -7
  35. package/appUtils/keyCodes/keys/keysByPlatform.ts +4 -0
  36. package/appUtils/keyInputHandler/KeyInputHandler.ts +68 -0
  37. package/appUtils/localizationsHelper.ts +31 -0
  38. package/appUtils/orientationHelper.ts +11 -13
  39. package/appUtils/platform/const.ts +14 -0
  40. package/appUtils/platform/platformUtils.ts +47 -4
  41. package/appUtils/playerManager/index.ts +1 -1
  42. package/appUtils/playerManager/player.ts +42 -18
  43. package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +11 -7
  44. package/appUtils/playerManager/playerNative.ts +18 -2
  45. package/appUtils/playerManager/usePlayerControllerSetup.tsx +3 -3
  46. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +7 -1
  47. package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
  48. package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
  49. package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
  50. package/arrayUtils/index.ts +7 -2
  51. package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +144 -0
  52. package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +72 -0
  53. package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +110 -0
  54. package/audioPlayerUtils/assets/index.ts +2 -0
  55. package/audioPlayerUtils/index.ts +138 -0
  56. package/cellUtils/index.ts +9 -5
  57. package/componentsUtils/__tests__/isFirstComponentGallery.test.ts +33 -0
  58. package/componentsUtils/__tests__/isFirstComponentScreenPicker.test.ts +33 -0
  59. package/componentsUtils/__tests__/isGallery.test.ts +33 -0
  60. package/componentsUtils/__tests__/isScreenPicker.test.ts +33 -0
  61. package/componentsUtils/index.ts +39 -0
  62. package/configurationUtils/__tests__/configurationUtils.test.js +0 -31
  63. package/configurationUtils/__tests__/getMediaItems.test.ts +65 -0
  64. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +34 -0
  65. package/configurationUtils/index.ts +63 -34
  66. package/dateUtils/index.ts +19 -0
  67. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  68. package/equalUtils/index.ts +49 -30
  69. package/focusManager/FocusManager.ts +14 -2
  70. package/focusManager/index.ts +23 -4
  71. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
  72. package/functionUtils/index.ts +46 -8
  73. package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
  74. package/idleUtils/index.ts +1 -1
  75. package/idleUtils/withTimeout.ts +15 -2
  76. package/index.d.ts +0 -12
  77. package/localizationUtils/index.ts +8 -13
  78. package/logger/const.ts +9 -67
  79. package/manifestUtils/__tests__/createConfig.test.js +16 -16
  80. package/manifestUtils/defaultManifestConfigurations/generalContent.js +13 -0
  81. package/manifestUtils/defaultManifestConfigurations/player.js +9 -3
  82. package/manifestUtils/fonts/index.js +5 -6
  83. package/manifestUtils/index.js +2 -0
  84. package/manifestUtils/keys.js +27 -2
  85. package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
  86. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +874 -0
  87. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
  88. package/modalState/__tests__/index.test.ts +51 -0
  89. package/modalState/index.ts +32 -2
  90. package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +7 -6
  91. package/navigationUtils/__tests__/itemTypes.test.js +2 -2
  92. package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
  93. package/navigationUtils/index.ts +6 -4
  94. package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +23 -3
  95. package/numberUtils/index.ts +11 -5
  96. package/package.json +5 -10
  97. package/playerUtils/configurationGenerator.ts +9 -11
  98. package/playerUtils/index.ts +23 -0
  99. package/reactHooks/advertising/index.ts +5 -5
  100. package/reactHooks/app/useAppState.ts +2 -2
  101. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  102. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +6 -8
  103. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  104. package/reactHooks/cell-click/__tests__/index.test.js +10 -2
  105. package/reactHooks/cell-click/index.ts +7 -1
  106. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
  107. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
  108. package/reactHooks/feed/useBatchLoading.ts +12 -14
  109. package/reactHooks/feed/useFeedLoader.tsx +18 -9
  110. package/reactHooks/feed/usePipesCacheReset.ts +5 -5
  111. package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
  112. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +39 -0
  113. package/reactHooks/layout/__tests__/index.test.tsx +10 -10
  114. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
  115. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
  116. package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
  117. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  118. package/reactHooks/navigation/__tests__/index.test.tsx +6 -21
  119. package/reactHooks/navigation/getTabBarHeight.ts +10 -0
  120. package/reactHooks/navigation/index.ts +34 -236
  121. package/reactHooks/navigation/useGetBottomTabBarHeight.ts +19 -0
  122. package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
  123. package/reactHooks/navigation/useIsScreenActive.ts +17 -0
  124. package/reactHooks/navigation/useNavigationPluginData.ts +19 -0
  125. package/reactHooks/navigation/useNavigationType.ts +17 -0
  126. package/reactHooks/navigation/usePathname.ts +4 -0
  127. package/reactHooks/navigation/useProfilerLogging.ts +15 -0
  128. package/reactHooks/navigation/useRoute.ts +98 -0
  129. package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
  130. package/reactHooks/player/TVSeekControlller/ISeekController.ts +32 -0
  131. package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +71 -0
  132. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +258 -0
  133. package/reactHooks/player/TVSeekControlller/TapSeekController.ts +53 -0
  134. package/reactHooks/player/__tests__/{useAutoSeek.test.tsx → useAutoSeek._test.tsx} +2 -3
  135. package/reactHooks/player/const.ts +0 -4
  136. package/reactHooks/player/index.ts +0 -6
  137. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +69 -0
  138. package/reactHooks/screen/useScreenBackgroundColor.ts +3 -15
  139. package/reactHooks/state/README.md +79 -0
  140. package/reactHooks/state/ZStoreProvider.tsx +71 -0
  141. package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +66 -0
  142. package/reactHooks/state/index.ts +2 -0
  143. package/reactHooks/state/useRefWithInitialValue.ts +14 -0
  144. package/reactHooks/state/useStateFromSubscribe.ts +23 -0
  145. package/reactHooks/useListenEventBusEvent.ts +1 -1
  146. package/reactHooks/usePluginConfiguration.ts +1 -1
  147. package/reactHooks/useSubscriberFor.ts +4 -3
  148. package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
  149. package/reactUtils/__tests__/reactUtils.test.js +1 -37
  150. package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
  151. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +13 -79
  152. package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +2 -2
  153. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
  154. package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
  155. package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
  156. package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
  157. package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
  158. package/reactUtils/createContext/__tests__/provider.test.js +4 -6
  159. package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
  160. package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
  161. package/reactUtils/createContext/helpers.ts +6 -1
  162. package/reactUtils/createContext/index.ts +11 -25
  163. package/reactUtils/index.ts +9 -11
  164. package/screenState/index.ts +24 -10
  165. package/services/js2native.ts +673 -0
  166. package/testUtils/index.tsx +0 -10
  167. package/theme/__mocks__/index.ts +4 -0
  168. package/theme/index.ts +1 -1
  169. package/time/BackgroundTimer.ts +55 -0
  170. package/time/Timer.ts +9 -6
  171. package/typeGuards/index.ts +3 -0
  172. package/types.ts +1 -0
  173. package/utils/README.md +30 -0
  174. package/utils/chunk.ts +5 -0
  175. package/utils/index.ts +12 -0
  176. package/utils/times.ts +5 -0
  177. package/zappFrameworkUtils/localStorageHelper.ts +38 -10
  178. package/zappFrameworkUtils/loginPluginUtils.ts +6 -2
  179. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
  180. package/zappFrameworkUtils/types.ts +11 -0
  181. package/reactHooks/player/useAutoSeek.tsx +0 -87
  182. package/reactHooks/player/useSeek.tsx +0 -66
  183. package/reactHooks/player/useTapSeek.tsx +0 -58
  184. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
  185. /package/reactHooks/player/__tests__/{useTapSeek.test.ts → useTapSeek._test.ts} +0 -0
@@ -1,7 +1,8 @@
1
1
  import * as React from "react";
2
- import { shallow } from "enzyme";
3
2
  import { View, Text } from "react-native";
4
3
 
4
+ import { NOOP, getSetterName, createContextSetters } from "../helpers";
5
+
5
6
  function stateValidator({ property, value }) {
6
7
  return (
7
8
  (property === "foo" && value === "new foo") ||
@@ -9,150 +10,135 @@ function stateValidator({ property, value }) {
9
10
  );
10
11
  }
11
12
 
12
- const logger = {
13
- warning: jest.fn(),
14
- };
15
-
16
- jest.mock("../../logger", () => ({
17
- reactUtilsLogger: {
18
- addSubsystem: jest.fn(() => logger),
19
- },
20
- }));
21
-
22
- const { NOOP, getSetterName, createContextSetters } = require("../helpers");
23
-
24
- describe("NOOP", () => {
25
- it("does nothing", () => {
26
- expect(NOOP()).toBeUndefined();
13
+ describe("helpers", () => {
14
+ describe("NOOP", () => {
15
+ it("does nothing", () => {
16
+ expect(NOOP()).toBeUndefined();
17
+ });
27
18
  });
28
- });
29
19
 
30
- describe("getSetterName", () => {
31
- it("returns a setter name for the given property name", () => {
32
- expect(getSetterName("fooBar")).toBe("setFooBar");
20
+ describe("getSetterName", () => {
21
+ it("returns a setter name for the given property name", () => {
22
+ expect(getSetterName("fooBar")).toBe("setFooBar");
23
+ });
33
24
  });
34
- });
35
-
36
- describe("createContextSetters", () => {
37
- describe("when state validator is provided", () => {
38
- class Component extends React.Component {
39
- constructor(props) {
40
- super(props);
41
- this.state = { foo: "foo", bar: "bar" };
42
- createContextSetters(["foo", "bar"], this, { stateValidator });
43
- }
44
-
45
- resetInitialState() {
46
- this.setState({ foo: "foo", bar: "bar" });
47
- }
48
25
 
49
- render() {
50
- return (
51
- <View>
52
- <Text>I am a component</Text>
53
- </View>
54
- );
26
+ describe("createContextSetters", () => {
27
+ describe("when state validator is provided", () => {
28
+ class ClassComponent {
29
+ constructor() {
30
+ this._state = { foo: "foo", bar: "bar" };
31
+ createContextSetters(["foo", "bar"], this, { stateValidator });
32
+ }
33
+
34
+ setState(newState) {
35
+ if (typeof newState === "function") {
36
+ this.state = newState(this.state);
37
+ } else {
38
+ this.state = { ...this.state, ...newState };
39
+ }
40
+ }
41
+
42
+ set state(val) {
43
+ this._state = val;
44
+ }
45
+
46
+ get state() {
47
+ return this._state;
48
+ }
49
+
50
+ getState() {
51
+ return this._state;
52
+ }
53
+
54
+ resetInitialState() {
55
+ this.setState({ foo: "foo", bar: "bar" });
56
+ }
57
+
58
+ render() {
59
+ return <View testID="test-view">{JSON.stringify(this.state)}</View>;
60
+ }
55
61
  }
56
- }
57
62
 
58
- const wrapper = shallow(<Component />);
59
- const instance = wrapper.instance();
60
- const setStateSpy = jest.spyOn(instance, "setState");
63
+ let instance;
61
64
 
62
- beforeEach(() => {
63
- instance.resetInitialState();
64
- setStateSpy.mockClear();
65
- logger.warning.mockClear();
66
- });
67
-
68
- it("adds all properties and setters to the component", () => {
69
- expect(instance).toHaveProperty("setFoo");
70
- expect(instance.setFoo).toBeFunction();
71
- expect(instance).toHaveProperty("setBar");
72
- expect(instance.setBar).toBeFunction();
73
- });
65
+ beforeEach(() => {
66
+ instance = new ClassComponent();
67
+ });
74
68
 
75
- it("calls setState when the setters are called & the validator passes", () => {
76
- expect(instance.state).toMatchSnapshot();
69
+ it("calls setState when the setters are called & the validator passes", () => {
70
+ expect(instance.state.foo).toEqual("foo");
71
+ expect(instance.state.bar).toEqual("bar");
77
72
 
78
- instance.setFoo("new foo");
79
- expect(instance.state).toMatchSnapshot();
80
-
81
- instance.setBar("new bar");
82
- expect(instance.state).toMatchSnapshot();
83
-
84
- expect(setStateSpy).toHaveBeenCalledTimes(2);
85
- expect(setStateSpy.mock.calls).toMatchSnapshot();
86
- expect(logger.warning).not.toHaveBeenCalled();
87
- });
73
+ instance.setFoo("new foo");
74
+ expect(instance.state.foo).toEqual("new foo");
88
75
 
89
- it("skips the update if the state validator doesn't pass", () => {
90
- expect(instance.state).toMatchSnapshot();
76
+ instance.setBar("new bar");
77
+ expect(instance.state.bar).toEqual("new bar");
78
+ });
91
79
 
92
- instance.setFoo("invalid foo");
93
- expect(instance.state).toMatchSnapshot();
80
+ it("skips the update if the state validator doesn't pass", () => {
81
+ expect(instance.state.foo).toEqual("foo");
82
+ expect(instance.state.bar).toEqual("bar");
94
83
 
95
- instance.setBar("invalid bar");
96
- expect(instance.state).toMatchSnapshot();
84
+ instance.setFoo("invalid foo");
85
+ expect(instance.state.foo).toEqual("foo");
97
86
 
98
- expect(setStateSpy).not.toHaveBeenCalled();
99
- expect(logger.warning).toHaveBeenCalledTimes(2);
100
- expect(logger.warning.mock.calls).toMatchSnapshot();
101
- });
87
+ instance.setBar("invalid bar");
88
+ expect(instance.state.bar).toEqual("bar");
89
+ });
102
90
 
103
- it("skips the update if the new value is the same as the previous one", () => {
104
- instance.setFoo("new foo");
105
- instance.setFoo("new foo");
106
- expect(instance.state).toMatchSnapshot();
107
- expect(setStateSpy).toHaveBeenCalledTimes(1);
91
+ it("skips the update if the new value is the same as the previous one", () => {
92
+ instance.setFoo("new foo");
93
+ instance.setFoo("new foo");
94
+ expect(instance.state).toMatchSnapshot();
95
+ });
108
96
  });
109
- });
110
-
111
- describe("when no state validator is provided", () => {
112
- class Component extends React.Component {
113
- constructor(props) {
114
- super(props);
115
- this.state = { foo: "foo", bar: "bar" };
116
- createContextSetters(["foo", "bar"], this);
117
- }
118
97
 
119
- render() {
120
- return (
121
- <View>
122
- <Text>I am a component </Text>
123
- </View>
124
- );
98
+ describe("when no state validator is provided", () => {
99
+ class Component extends React.Component {
100
+ constructor(props) {
101
+ super(props);
102
+ this.state = { foo: "foo", bar: "bar" };
103
+ createContextSetters(["foo", "bar"], this);
104
+ }
105
+
106
+ render() {
107
+ return (
108
+ <View>
109
+ <Text>I am a component </Text>
110
+ </View>
111
+ );
112
+ }
125
113
  }
126
- }
127
114
 
128
- const wrapper = shallow(<Component />);
129
- const instance = wrapper.instance();
130
- const setStateSpy = jest.spyOn(instance, "setState");
115
+ // const wrapper = new Component();
116
+ const instance = new Component();
117
+ const setStateSpy = jest.spyOn(instance, "setState");
131
118
 
132
- afterEach(() => {
133
- setStateSpy.mockClear();
134
- logger.warning.mockClear();
135
- });
119
+ afterEach(() => {
120
+ setStateSpy.mockClear();
121
+ });
136
122
 
137
- it("adds all properties and setters to the component", () => {
138
- expect(instance).toHaveProperty("setFoo");
139
- expect(instance.setFoo).toBeFunction();
140
- expect(instance).toHaveProperty("setBar");
141
- expect(instance.setBar).toBeFunction();
142
- });
123
+ it("adds all properties and setters to the component", () => {
124
+ expect(instance).toHaveProperty("setFoo");
125
+ expect(instance.setFoo).toBeFunction();
126
+ expect(instance).toHaveProperty("setBar");
127
+ expect(instance.setBar).toBeFunction();
128
+ });
143
129
 
144
- it("calls setState when the setters are called, no matter what the value is", () => {
145
- expect(instance.state).toMatchSnapshot();
130
+ it("calls setState when the setters are called, no matter what the value is", () => {
131
+ expect(instance.state).toMatchSnapshot();
146
132
 
147
- instance.setFoo("invalid foo");
148
- expect(instance.state).toMatchSnapshot();
133
+ instance.setFoo("invalid foo");
134
+ expect(instance.state).toMatchSnapshot();
149
135
 
150
- instance.setBar("invalid bar");
151
- expect(instance.state).toMatchSnapshot();
136
+ instance.setBar("invalid bar");
137
+ expect(instance.state).toMatchSnapshot();
152
138
 
153
- expect(setStateSpy).toHaveBeenCalledTimes(2);
154
- expect(setStateSpy.mock.calls).toMatchSnapshot();
155
- expect(logger.warning).not.toHaveBeenCalled();
139
+ expect(setStateSpy).toHaveBeenCalledTimes(2);
140
+ expect(setStateSpy.mock.calls).toMatchSnapshot();
141
+ });
156
142
  });
157
143
  });
158
144
  });
@@ -1,3 +1,5 @@
1
+ import { createContext } from "../";
2
+
1
3
  jest.mock("react", () => ({
2
4
  ...jest.requireActual("react"),
3
5
  createContext: jest.fn(() => ({
@@ -6,8 +8,6 @@ jest.mock("react", () => ({
6
8
  })),
7
9
  }));
8
10
 
9
- const { createContext } = require("../index");
10
-
11
11
  const mockedProvider = jest.fn();
12
12
  const mockedWithConsumer = jest.fn();
13
13
  const mockedWithProvider = jest.fn();
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable react/prop-types */
2
2
  import * as React from "react";
3
- import { shallow } from "enzyme";
4
- import toJson from "enzyme-to-json";
3
+ import { render } from "@testing-library/react-native";
4
+
5
5
  import { View } from "react-native";
6
6
 
7
7
  import { createProvider } from "../provider";
@@ -29,14 +29,12 @@ describe("createProvider", () => {
29
29
  it("creates a context Provider component", () => {
30
30
  const MockChild = (props) => <View>{props.context}</View>;
31
31
 
32
- const wrapper = shallow(
32
+ const wrapper = render(
33
33
  <Provider>
34
34
  <MockChild context={"context"} />
35
35
  </Provider>
36
36
  );
37
37
 
38
- expect(toJson(wrapper)).toMatchSnapshot();
39
-
40
- expect(wrapper.find(ReactContext.Provider).props()).toMatchSnapshot();
38
+ expect(wrapper.toJSON()).toMatchSnapshot();
41
39
  });
42
40
  });
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable react/prop-types */
2
2
  import * as React from "react";
3
- import { shallow } from "enzyme";
4
- import toJson from "enzyme-to-json";
3
+ import { render } from "@testing-library/react-native";
4
+
5
5
  import { View } from "react-native";
6
6
 
7
7
  import { createWithConsumerDecorator } from "../withConsumer";
@@ -11,21 +11,21 @@ describe("createConsumer", () => {
11
11
  const { Consumer } = ReactContext;
12
12
  const withConsumer = createWithConsumerDecorator(Consumer);
13
13
 
14
- it("returns a function", () => {
15
- expect(withConsumer).toBeFunction();
16
- });
17
-
18
14
  it("creates a context consumer function", () => {
19
- const Child = (props) => <View>{props.context}</View>;
20
- const DecoratedChild = withConsumer(Child);
15
+ expect(withConsumer).toBeFunction();
21
16
  const newContextValue = "newValue";
22
17
 
23
- const wrapper = shallow(<DecoratedChild />);
18
+ const Child = (props) => {
19
+ props.setContext(newContextValue);
20
+
21
+ return <View>{props.context}</View>;
22
+ };
23
+
24
+ const DecoratedChild = withConsumer(Child);
24
25
 
25
- const childWrapper = wrapper.dive();
26
+ const wrapper = render(<DecoratedChild />);
26
27
 
27
- expect(toJson(childWrapper)).toMatchSnapshot();
28
- childWrapper.props().setContext(newContextValue);
28
+ expect(wrapper.toJSON()).toMatchSnapshot();
29
29
 
30
30
  expect(mockContextData.setContext).toHaveBeenCalledWith(newContextValue);
31
31
  });
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable react/prop-types */
2
2
  import * as React from "react";
3
- import { shallow } from "enzyme";
4
- import toJson from "enzyme-to-json";
3
+ import { render } from "@testing-library/react-native";
4
+
5
5
  import { View, Text } from "react-native";
6
6
 
7
7
  import { createWithProviderDecorator } from "../withProvider";
@@ -19,8 +19,8 @@ describe("withProvider", () => {
19
19
 
20
20
  const DecoratedComponent = withProvider(Component);
21
21
 
22
- const wrapper = shallow(<DecoratedComponent />);
22
+ const wrapper = render(<DecoratedComponent />);
23
23
 
24
- expect(toJson(wrapper)).toMatchSnapshot();
24
+ expect(wrapper.toJSON()).toMatchSnapshot();
25
25
  });
26
26
  });
@@ -33,7 +33,12 @@ export const getSetterName: (property: string) => string = R.compose(
33
33
  export function createContextSetters(
34
34
  properties: string[],
35
35
  component: any,
36
- options: any = {}
36
+ options: {
37
+ stateValidator?: (
38
+ obj: { property: string; value: unknown },
39
+ oldValue: unknown
40
+ ) => boolean;
41
+ } = {}
37
42
  ) {
38
43
  const { stateValidator = R.T } = options;
39
44
 
@@ -1,5 +1,4 @@
1
1
  import * as React from "react";
2
- import createReactContext from "create-react-context";
3
2
  import * as R from "ramda";
4
3
 
5
4
  import { getSetterName, NOOP } from "./helpers";
@@ -7,33 +6,20 @@ import { createProvider } from "./provider";
7
6
  import { createWithConsumerDecorator } from "./withConsumer";
8
7
  import { createWithProviderDecorator } from "./withProvider";
9
8
 
10
- const reactContextCreator = React.createContext;
11
-
12
- // Depending on the version of React used, the `createContext` function may not be available
13
- // if this is the case, we fall back to a polyfill library
14
- const contextCreatorFn =
15
- reactContextCreator && typeof reactContextCreator === "function"
16
- ? reactContextCreator
17
- : createReactContext;
18
-
19
- /**
20
- * @typedef Context
21
- * @property {Object} Context.Provider react class component to use as context provider
22
- * @property {Function} Context.Consumer react functional component to use as context consumer
23
- * @property {Function} Context.withProvider HOC to apply the context provider
24
- * @property {function} Context.withConsumer HOC to apply the context consumer. passes the context as props
25
- * @property {React.Context} Context.ReactContext React context object
26
- * to the wrapped component
27
- */
28
-
29
9
  /**
30
10
  * Creates a React Context and returns consumer & providers components & decorators to interact
31
11
  * with this context.
32
- * @param {Object} initialContext map of context properties and their initial values
33
- * @param {Function} stateValidator optional predicate to tell whether the state update is valid or not
34
- * @returns {Context} Object containing the context components & decorators {@link Context}
12
+ * @param initialContext map of context properties and their initial values
13
+ * @param stateValidator optional predicate to tell whether the state update is valid or not
14
+ * @returns Object containing the context components & decorators
35
15
  */
36
- export function createContext(initialContext, stateValidator = R.T) {
16
+ export function createContext(
17
+ initialContext: Record<string, any>,
18
+ stateValidator: (
19
+ obj: { property: string; value: unknown },
20
+ oldValue: unknown
21
+ ) => boolean = R.T
22
+ ) {
37
23
  // first we extract the properties name, and create setters name for those
38
24
  const contextPropertiesNames = R.keys(initialContext);
39
25
  const contextSettersNames = R.map(getSetterName, contextPropertiesNames);
@@ -41,7 +27,7 @@ export function createContext(initialContext, stateValidator = R.T) {
41
27
  // we create a React Context with the properties & their setters, assigning a noop function
42
28
  // temporarily (will be overriden by proper setters in the provider component)
43
29
  const ReactContext = R.compose(
44
- contextCreatorFn,
30
+ React.createContext,
45
31
  R.merge(initialContext),
46
32
  R.zipObj(contextSettersNames),
47
33
  R.map(R.always(NOOP))
@@ -2,7 +2,6 @@
2
2
  import * as R from "ramda";
3
3
  import * as React from "react";
4
4
  import { Platform } from "react-native";
5
- import createRef from "create-react-ref/lib/createRef";
6
5
 
7
6
  import { addLifeCycleMethods, wrapInClass, isClassComponent } from "./helpers";
8
7
 
@@ -19,16 +18,6 @@ export function attachLifeCycleMethods(lifecycleMethods) {
19
18
  );
20
19
  }
21
20
 
22
- /**
23
- * creates a React Ref. if the version of React doesn't
24
- * have this API, will use a polyfill instead
25
- */
26
- export function createReactRef() {
27
- return React.createRef && typeof React.createRef === "function"
28
- ? React.createRef()
29
- : createRef();
30
- }
31
-
32
21
  /**
33
22
  * Clone the children and merge each of the cloned elements with otherProps.
34
23
  * @param {React.Children} children to clone
@@ -198,3 +187,12 @@ export const hasVizioAPIs = () => {
198
187
 
199
188
  return hasAPIs;
200
189
  };
190
+
191
+ /**
192
+ * Checks if the Android version is at least the expected version
193
+ * @param expectedVersion The version to compare against
194
+ * @returns True if the current Android version is at least the expected version, false otherwise
195
+ */
196
+ export const isAndroidVersionAtLeast = (expectedVersion: number) => {
197
+ return parseFloat(Platform.Version.toString()) >= expectedVersion;
198
+ };
@@ -1,6 +1,8 @@
1
1
  import { create } from "zustand";
2
2
  import { produce } from "immer";
3
3
  import { path } from "ramda";
4
+ import React from "react";
5
+ import { useShallow } from "zustand/react/shallow";
4
6
 
5
7
  type ScreenState = {
6
8
  selectedEntry: {
@@ -18,6 +20,8 @@ type ScreenStore = {
18
20
  setSelectedEntry: (screenId: string, entryId: string) => void;
19
21
  };
20
22
 
23
+ type SetSelectedEntry = (screenId: string, entryId: string) => void;
24
+
21
25
  const useScreenStore = create<ScreenStore>((set) => ({
22
26
  screens: screensInitialState,
23
27
  setSelectedEntry: (screenId, entryId) =>
@@ -35,17 +39,27 @@ const useScreenStore = create<ScreenStore>((set) => ({
35
39
  export function useScreenState(
36
40
  screenId: ScreenId
37
41
  ): null | { screen: ScreenState; setSelectedEntry: (entryId: string) => void } {
38
- // const state = useState(screenState);
39
- const screenState = useScreenStore(
40
- path(["screens", screenId])
41
- ) as ScreenState;
42
+ const screenState = useScreenStore<ScreenState>(
43
+ useShallow(path(["screens", screenId]))
44
+ );
42
45
 
43
- const setSelectedEntry = useScreenStore((state) => state.setSelectedEntry);
46
+ const setSelectedEntry = useScreenStore<SetSelectedEntry>(
47
+ useShallow(path(["setSelectedEntry"]))
48
+ );
44
49
 
45
- if (!screenId) return null;
50
+ const memoizedSetSelectedEntry = React.useCallback(
51
+ (entryId) => setSelectedEntry(screenId, entryId),
52
+ [screenId, setSelectedEntry]
53
+ );
46
54
 
47
- return {
48
- screen: screenState,
49
- setSelectedEntry: (entryId) => setSelectedEntry(screenId, entryId),
50
- };
55
+ return React.useMemo(
56
+ () =>
57
+ !screenId
58
+ ? null
59
+ : {
60
+ screen: screenState,
61
+ setSelectedEntry: memoizedSetSelectedEntry,
62
+ },
63
+ [screenId, screenState]
64
+ );
51
65
  }