@applicaster/zapp-react-native-utils 13.0.0-alpha.1552112220 → 13.0.0-alpha.1612843433

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 (152) hide show
  1. package/README.md +0 -10
  2. package/actionsExecutor/ActionExecutor.ts +16 -9
  3. package/actionsExecutor/ActionExecutorContext.tsx +196 -11
  4. package/actionsExecutor/consts.ts +4 -0
  5. package/alertUtils/alert.ts +148 -0
  6. package/alertUtils/index.ts +1 -148
  7. package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
  8. package/analyticsUtils/currentScreenProperities.ts +6 -4
  9. package/analyticsUtils/helpers/hooks.ts +1 -1
  10. package/appUtils/HooksManager/Hook.ts +6 -2
  11. package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +7 -7
  12. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +186 -186
  13. package/appUtils/HooksManager/index.ts +3 -1
  14. package/appUtils/HooksManager/types.ts +5 -2
  15. package/appUtils/__tests__/__snapshots__/localizationsHelper.test.ts.snap +151 -0
  16. package/appUtils/__tests__/allZappLocales.ts +79 -0
  17. package/appUtils/__tests__/{localizationsHelper.test.js → localizationsHelper.test.ts} +11 -0
  18. package/appUtils/accessibilityManager/index.ts +42 -1
  19. package/appUtils/contextKeysManager/contextResolver.ts +66 -0
  20. package/appUtils/contextKeysManager/index.ts +2 -2
  21. package/appUtils/contextKeysManager/utils/index.ts +2 -1
  22. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +9 -6
  23. package/appUtils/focusManager/index.ios.ts +14 -4
  24. package/appUtils/focusManager/index.ts +108 -69
  25. package/appUtils/focusManager/treeDataStructure/Tree/index.js +23 -0
  26. package/appUtils/focusManager/utils/__tests__/findChild.test.ts +35 -0
  27. package/appUtils/focusManager/utils/enums.ts +4 -0
  28. package/appUtils/focusManager/utils/index.ts +5 -0
  29. package/appUtils/focusManagerAux/utils/index.ts +4 -3
  30. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
  31. package/appUtils/keyCodes/__tests__/keyCodes.test.js +1 -1
  32. package/appUtils/keyCodes/index.ts +11 -7
  33. package/appUtils/localizationsHelper.ts +31 -0
  34. package/appUtils/orientationHelper.ts +11 -13
  35. package/appUtils/platform/const.ts +14 -0
  36. package/appUtils/platform/platformUtils.ts +47 -4
  37. package/appUtils/playerManager/index.ts +1 -1
  38. package/appUtils/playerManager/player.ts +26 -14
  39. package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +11 -7
  40. package/appUtils/playerManager/playerNative.ts +19 -4
  41. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +7 -1
  42. package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
  43. package/cellUtils/index.ts +9 -5
  44. package/componentsUtils/__tests__/isFirstComponentGallery.test.ts +33 -0
  45. package/componentsUtils/__tests__/isFirstComponentScreenPicker.test.ts +33 -0
  46. package/componentsUtils/__tests__/isGallery.test.ts +33 -0
  47. package/componentsUtils/__tests__/isScreenPicker.test.ts +33 -0
  48. package/componentsUtils/index.ts +39 -0
  49. package/dateUtils/index.ts +19 -0
  50. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  51. package/equalUtils/index.ts +49 -30
  52. package/focusManager/FocusManager.ts +14 -2
  53. package/focusManager/index.ts +23 -4
  54. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
  55. package/functionUtils/index.ts +46 -8
  56. package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
  57. package/idleUtils/index.ts +1 -1
  58. package/idleUtils/withTimeout.ts +15 -2
  59. package/index.d.ts +0 -12
  60. package/localizationUtils/index.ts +8 -13
  61. package/logger/const.ts +9 -67
  62. package/manifestUtils/__tests__/createConfig.test.js +16 -16
  63. package/manifestUtils/defaultManifestConfigurations/generalContent.js +13 -0
  64. package/manifestUtils/defaultManifestConfigurations/player.js +9 -3
  65. package/manifestUtils/fonts/index.js +5 -6
  66. package/manifestUtils/keys.js +27 -2
  67. package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
  68. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +875 -0
  69. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
  70. package/modalState/__tests__/index.test.ts +51 -0
  71. package/modalState/index.ts +32 -2
  72. package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +7 -6
  73. package/navigationUtils/__tests__/itemTypes.test.js +2 -2
  74. package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
  75. package/navigationUtils/index.ts +6 -4
  76. package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +23 -3
  77. package/numberUtils/index.ts +11 -5
  78. package/package.json +5 -10
  79. package/playerUtils/configurationGenerator.ts +9 -11
  80. package/reactHooks/advertising/index.ts +5 -5
  81. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  82. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +6 -8
  83. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  84. package/reactHooks/cell-click/__tests__/index.test.js +10 -2
  85. package/reactHooks/cell-click/index.ts +7 -1
  86. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
  87. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
  88. package/reactHooks/feed/useBatchLoading.ts +10 -12
  89. package/reactHooks/feed/useFeedLoader.tsx +18 -9
  90. package/reactHooks/feed/usePipesCacheReset.ts +5 -5
  91. package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
  92. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +39 -0
  93. package/reactHooks/layout/__tests__/index.test.tsx +10 -10
  94. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
  95. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
  96. package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
  97. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  98. package/reactHooks/navigation/__tests__/index.test.tsx +6 -21
  99. package/reactHooks/navigation/index.ts +34 -236
  100. package/reactHooks/navigation/useGetBottomTabBarHeight.ts +12 -0
  101. package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
  102. package/reactHooks/navigation/useGetTabBarHeight.ts +10 -0
  103. package/reactHooks/navigation/useIsScreenActive.ts +17 -0
  104. package/reactHooks/navigation/useNavigationPluginData.ts +15 -0
  105. package/reactHooks/navigation/useNavigationType.ts +15 -0
  106. package/reactHooks/navigation/usePathname.ts +4 -0
  107. package/reactHooks/navigation/useProfilerLogging.ts +15 -0
  108. package/reactHooks/navigation/useRoute.ts +98 -0
  109. package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
  110. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +4 -4
  111. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +115 -0
  112. package/reactHooks/player/__tests__/useTapSeek._test.ts +94 -0
  113. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +69 -0
  114. package/reactHooks/screen/useScreenBackgroundColor.ts +3 -15
  115. package/reactHooks/state/useRefWithInitialValue.ts +14 -0
  116. package/reactHooks/state/useStateFromSubscribe.ts +23 -0
  117. package/reactHooks/useListenEventBusEvent.ts +1 -1
  118. package/reactHooks/usePluginConfiguration.ts +1 -1
  119. package/reactHooks/useSubscriberFor.ts +4 -3
  120. package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
  121. package/reactUtils/__tests__/reactUtils.test.js +1 -37
  122. package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
  123. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +13 -79
  124. package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +2 -2
  125. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
  126. package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
  127. package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
  128. package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
  129. package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
  130. package/reactUtils/createContext/__tests__/provider.test.js +4 -6
  131. package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
  132. package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
  133. package/reactUtils/createContext/helpers.ts +6 -1
  134. package/reactUtils/createContext/index.ts +11 -25
  135. package/reactUtils/index.ts +9 -11
  136. package/screenState/index.ts +24 -10
  137. package/services/js2native.ts +673 -0
  138. package/testUtils/index.tsx +0 -10
  139. package/theme/__mocks__/index.ts +4 -0
  140. package/theme/index.ts +1 -1
  141. package/time/BackgroundTimer.ts +55 -0
  142. package/time/Timer.ts +9 -6
  143. package/types.ts +1 -0
  144. package/utils/README.md +30 -0
  145. package/utils/chunk.ts +5 -0
  146. package/utils/index.ts +5 -0
  147. package/utils/times.ts +5 -0
  148. package/zappFrameworkUtils/localStorageHelper.ts +6 -0
  149. package/zappFrameworkUtils/loginPluginUtils.ts +6 -2
  150. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
  151. package/zappFrameworkUtils/types.ts +11 -0
  152. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
@@ -0,0 +1,115 @@
1
+ import { act, renderHook } from "@testing-library/react-hooks";
2
+ import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
3
+
4
+ import { ON_HOLD_INTERVAL, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
5
+
6
+ import { useAutoSeek } from "../useAutoSeek";
7
+
8
+ jest.useFakeTimers({ legacyFakeTimers: true });
9
+
10
+ const rewind = jest.fn();
11
+ const forward = jest.fn();
12
+
13
+ jest
14
+ .spyOn(playerManager, "getInstanceController")
15
+ .mockReturnValue({ rewind, forward });
16
+
17
+ describe("useAutoSeek", () => {
18
+ beforeEach(() => {
19
+ rewind.mockReset();
20
+ forward.mockReset();
21
+ });
22
+
23
+ describe("autoSeekStart", () => {
24
+ it("should call forward method on playerInstance", () => {
25
+ const { result } = renderHook(() => useAutoSeek());
26
+
27
+ act(() => {
28
+ result.current.autoSeekStart(SEEK_TYPE.FORWARD);
29
+ });
30
+
31
+ expect(forward).toBeCalled();
32
+ result.current.autoSeekStop();
33
+ });
34
+
35
+ it("should call rewind method on playerManager", () => {
36
+ const { result } = renderHook(() => useAutoSeek());
37
+
38
+ act(() => {
39
+ result.current.autoSeekStart(SEEK_TYPE.REWIND);
40
+ });
41
+
42
+ expect(rewind).toBeCalled();
43
+ result.current.autoSeekStop();
44
+ });
45
+
46
+ it("should call rewind with default skip time", () => {
47
+ const { result } = renderHook(() => useAutoSeek());
48
+
49
+ act(() => {
50
+ result.current.autoSeekStart(SEEK_TYPE.REWIND);
51
+ });
52
+
53
+ expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
54
+ result.current.autoSeekStop();
55
+ });
56
+
57
+ it("should call forward with default skip time", () => {
58
+ const { result } = renderHook(() => useAutoSeek());
59
+
60
+ act(() => {
61
+ result.current.autoSeekStart(SEEK_TYPE.FORWARD);
62
+ });
63
+
64
+ expect(forward).toBeCalledWith(SKIP_TIME_BASE);
65
+ result.current.autoSeekStop();
66
+ });
67
+
68
+ it("should call rewind in intervals set in configuration", () => {
69
+ const { result } = renderHook(() => useAutoSeek());
70
+
71
+ act(() => {
72
+ result.current.autoSeekStart(SEEK_TYPE.REWIND);
73
+ });
74
+
75
+ expect(rewind).toBeCalled();
76
+ jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
77
+ expect(rewind).toBeCalledTimes(4);
78
+ result.current.autoSeekStop();
79
+ });
80
+
81
+ it("should call forward in intervals set in configuration", () => {
82
+ const { result } = renderHook(() => useAutoSeek());
83
+
84
+ act(() => {
85
+ result.current.autoSeekStart(SEEK_TYPE.FORWARD);
86
+ });
87
+
88
+ expect(forward).toBeCalled();
89
+ jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
90
+ expect(forward).toBeCalledTimes(4);
91
+ result.current.autoSeekStop();
92
+ });
93
+ });
94
+
95
+ describe("autoSeekStop", () => {
96
+ it("should stop calling playerManager method after autoSeekStop is called", () => {
97
+ const { result } = renderHook(() => useAutoSeek());
98
+
99
+ act(() => {
100
+ result.current.autoSeekStart(SEEK_TYPE.FORWARD);
101
+ });
102
+
103
+ expect(forward).toBeCalled();
104
+ jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
105
+ expect(forward).toBeCalledTimes(4);
106
+
107
+ act(() => {
108
+ result.current.autoSeekStop();
109
+ });
110
+
111
+ jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
112
+ expect(forward).toBeCalledTimes(4);
113
+ });
114
+ });
115
+ });
@@ -0,0 +1,94 @@
1
+ import { renderHook } from "@testing-library/react-hooks";
2
+ import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
3
+ import { useTapSeek } from "../useTapSeek";
4
+
5
+ import { ON_PRESS_RESET_DURATION, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
6
+
7
+ const rewind = jest.fn();
8
+ const forward = jest.fn();
9
+
10
+ jest
11
+ .spyOn(playerManager, "getInstanceController")
12
+ // @ts-ignore
13
+ .mockImplementation(() => ({ rewind, forward }));
14
+
15
+ describe("useTapSeek", () => {
16
+ beforeEach(() => {
17
+ rewind.mockReset();
18
+ forward.mockReset();
19
+ });
20
+
21
+ describe("forward", () => {
22
+ it("should call forward method on playerManager", () => {
23
+ const { result } = renderHook(() => useTapSeek());
24
+
25
+ result.current(SEEK_TYPE.FORWARD);
26
+ expect(forward).toBeCalled();
27
+ });
28
+
29
+ it("should call forward with default skip time", () => {
30
+ const { result } = renderHook(() => useTapSeek());
31
+
32
+ result.current(SEEK_TYPE.FORWARD);
33
+ expect(forward).toBeCalledWith(SKIP_TIME_BASE);
34
+ });
35
+
36
+ it("should multiply skip time for every call", async () => {
37
+ const { result } = renderHook(() => useTapSeek());
38
+
39
+ result.current(SEEK_TYPE.FORWARD);
40
+ expect(forward).toBeCalledWith(SKIP_TIME_BASE);
41
+ result.current(SEEK_TYPE.FORWARD);
42
+ expect(forward).toBeCalledWith(SKIP_TIME_BASE * 2);
43
+ });
44
+
45
+ it("should reset multiplier if waiting more then resetDuration between press actions", () => {
46
+ const { result, waitFor } = renderHook(() => useTapSeek());
47
+
48
+ result.current(SEEK_TYPE.FORWARD);
49
+ expect(forward).toBeCalledWith(SKIP_TIME_BASE);
50
+ waitFor(jest.fn(), { timeout: ON_PRESS_RESET_DURATION });
51
+ result.current(SEEK_TYPE.FORWARD);
52
+ expect(forward).toBeCalledWith(SKIP_TIME_BASE);
53
+ });
54
+ });
55
+
56
+ describe("rewind", () => {
57
+ it("should call rewind method on playerManager", () => {
58
+ const { result } = renderHook(() => useTapSeek());
59
+
60
+ result.current(SEEK_TYPE.REWIND);
61
+ expect(rewind).toBeCalled();
62
+ });
63
+
64
+ it("should call rewind with default skip time", () => {
65
+ const { result } = renderHook(() => useTapSeek());
66
+
67
+ result.current(SEEK_TYPE.REWIND);
68
+ expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
69
+ });
70
+
71
+ it("should multiply skip time for every call", async () => {
72
+ const { result } = renderHook(() => useTapSeek());
73
+
74
+ result.current(SEEK_TYPE.REWIND);
75
+ expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
76
+ result.current(SEEK_TYPE.REWIND);
77
+ expect(rewind).toBeCalledWith(SKIP_TIME_BASE * 2);
78
+ });
79
+ });
80
+
81
+ describe("mixed usage", () => {
82
+ it("should reset timer if different type of event is emitted", () => {
83
+ const { result } = renderHook(() => useTapSeek());
84
+ result.current(SEEK_TYPE.REWIND);
85
+ expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
86
+
87
+ result.current(SEEK_TYPE.REWIND);
88
+ expect(rewind).toBeCalledWith(SKIP_TIME_BASE * 2);
89
+
90
+ result.current(SEEK_TYPE.FORWARD);
91
+ expect(forward).toBeCalledWith(SKIP_TIME_BASE);
92
+ });
93
+ });
94
+ });
@@ -0,0 +1,69 @@
1
+ import { renderHook } from "@testing-library/react-hooks";
2
+
3
+ jest.mock(
4
+ "@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration",
5
+ () => ({
6
+ useScreenConfiguration: jest.fn(),
7
+ })
8
+ );
9
+
10
+ const {
11
+ useScreenConfiguration,
12
+ } = require("@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration");
13
+
14
+ const { useScreenBackgroundColor } = require("../useScreenBackgroundColor");
15
+
16
+ describe("useScreenBackgroundColor", () => {
17
+ afterEach(() => {
18
+ jest.clearAllMocks();
19
+ });
20
+
21
+ it("should return the background color from screen configuration", () => {
22
+ useScreenConfiguration.mockReturnValue({
23
+ backgroundColor: "#FF0000",
24
+ });
25
+
26
+ // Render the hook with a screen ID
27
+ const { result } = renderHook(() =>
28
+ useScreenBackgroundColor("test-screen-id")
29
+ );
30
+
31
+ expect(result.current).toBe("#FF0000");
32
+
33
+ expect(useScreenConfiguration).toHaveBeenCalledWith("test-screen-id");
34
+ });
35
+
36
+ it("should return 'transparent' when background color is empty", () => {
37
+ useScreenConfiguration.mockReturnValue({
38
+ backgroundColor: "",
39
+ });
40
+
41
+ const { result } = renderHook(() =>
42
+ useScreenBackgroundColor("test-screen-id")
43
+ );
44
+
45
+ expect(result.current).toBe("transparent");
46
+ });
47
+
48
+ it("should return 'transparent' when background color is null", () => {
49
+ useScreenConfiguration.mockReturnValue({
50
+ backgroundColor: null,
51
+ });
52
+
53
+ const { result } = renderHook(() =>
54
+ useScreenBackgroundColor("test-screen-id")
55
+ );
56
+
57
+ expect(result.current).toBe("transparent");
58
+ });
59
+
60
+ it("should return 'transparent' when background color is undefined", () => {
61
+ useScreenConfiguration.mockReturnValue({});
62
+
63
+ const { result } = renderHook(() =>
64
+ useScreenBackgroundColor("test-screen-id")
65
+ );
66
+
67
+ expect(result.current).toBe("transparent");
68
+ });
69
+ });
@@ -1,23 +1,11 @@
1
- import * as React from "react";
2
- import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
3
1
  import { useScreenConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration";
4
2
  import { ifEmptyUseFallback } from "@applicaster/zapp-react-native-utils/cellUtils";
5
3
 
4
+ const DEFAULT_BACKGROUND_FALLBACK = "transparent";
5
+
6
6
  export const useScreenBackgroundColor = (screenId: string): string => {
7
7
  const { backgroundColor: screenBackgroundColor } =
8
8
  useScreenConfiguration(screenId);
9
9
 
10
- const theme = useTheme();
11
-
12
- const themeBackgroundColor = React.useMemo(
13
- () => theme.app_background_color,
14
- [theme.app_background_color]
15
- );
16
-
17
- const backgroundColor = ifEmptyUseFallback(
18
- screenBackgroundColor,
19
- themeBackgroundColor
20
- );
21
-
22
- return backgroundColor;
10
+ return ifEmptyUseFallback(screenBackgroundColor, DEFAULT_BACKGROUND_FALLBACK);
23
11
  };
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+
3
+ /**
4
+ * returns a ref with an initial value that is lazily evaluated once
5
+ * */
6
+ export const useRefWithInitialValue = <T>(initialValueGetter: () => T) => {
7
+ const ref = React.useRef<T>(null);
8
+
9
+ if (ref.current === null) {
10
+ ref.current = initialValueGetter();
11
+ }
12
+
13
+ return ref;
14
+ };
@@ -0,0 +1,23 @@
1
+ import { useEffect, useState } from "react";
2
+ import type { Subject } from "rxjs";
3
+
4
+ export const useStateFromSubscribe = <T, U>(
5
+ subject: Subject<T>,
6
+ onUpdate: (
7
+ observerValue: T,
8
+ next: React.Dispatch<React.SetStateAction<U>>
9
+ ) => void,
10
+ initialValue: U
11
+ ) => {
12
+ const [state, setState] = useState<U>(initialValue);
13
+
14
+ useEffect(() => {
15
+ const subscription = subject.subscribe((observer) =>
16
+ onUpdate(observer, setState)
17
+ );
18
+
19
+ return () => subscription.unsubscribe();
20
+ }, [subject]);
21
+
22
+ return state;
23
+ };
@@ -23,5 +23,5 @@ export const useListenEventBusEvent = (
23
23
  sub.remove(); // stop listening to DeviceEventEmitter
24
24
  };
25
25
  }
26
- }, []);
26
+ }, [handler, subscriptionID, source, events]);
27
27
  };
@@ -91,7 +91,7 @@ export function useLayoutConfiguration<
91
91
  S extends unknown,
92
92
  G extends unknown,
93
93
  R extends unknown,
94
- L extends unknown
94
+ L extends unknown,
95
95
  >(layoutData, manifest, options: Options = {}) {
96
96
  const keys = options.keys || [
97
97
  "assets",
@@ -4,9 +4,10 @@ import { subscriber } from "@applicaster/zapp-react-native-utils/functionUtils";
4
4
  const subscriberObjects = Object.create({});
5
5
 
6
6
  interface UseSubscriberFor {
7
- (eventName: string, handler?: (...args: unknown[]) => void): (
8
- ...args: unknown[]
9
- ) => ReturnType<typeof subscriber>;
7
+ (
8
+ eventName: string,
9
+ handler?: (...args: unknown[]) => void
10
+ ): (...args: unknown[]) => ReturnType<typeof subscriber>;
10
11
  }
11
12
 
12
13
  /**
@@ -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
+ `;
@@ -1,4 +1,3 @@
1
- jest.mock("create-react-ref/lib/createRef", () => jest.fn());
2
1
  import * as React from "react";
3
2
  import * as helpers from "../helpers";
4
3
 
@@ -8,13 +7,7 @@ import {
8
7
  componentDidMount,
9
8
  } from "./fixtures";
10
9
 
11
- const {
12
- attachLifeCycleMethods,
13
- createReactRef,
14
- mergeChildrenProps,
15
- } = require("../index");
16
-
17
- const createRef = require("create-react-ref/lib/createRef");
10
+ import { attachLifeCycleMethods, mergeChildrenProps } from "..";
18
11
 
19
12
  describe("attachLifeCycleMethods", () => {
20
13
  let addLifeCycleMethodsSpy;
@@ -48,35 +41,6 @@ describe("attachLifeCycleMethods", () => {
48
41
  });
49
42
  });
50
43
 
51
- describe("createReactRef", () => {
52
- it("calls the React.createRef function if it exists", () => {
53
- jest.resetModules();
54
-
55
- jest.doMock("react", () => ({
56
- ...jest.requireActual("react"),
57
- createRef: jest.fn(),
58
- }));
59
-
60
- const React = require("react");
61
-
62
- createReactRef();
63
- expect(React.createRef).toHaveBeenCalled();
64
- expect(createRef).not.toHaveBeenCalled();
65
- });
66
-
67
- it("calls the polyfill if React.createRef doesn't exist", () => {
68
- jest.resetModules();
69
-
70
- jest.doMock("react", () => ({
71
- ...jest.requireActual("react"),
72
- createRef: undefined,
73
- }));
74
-
75
- createReactRef();
76
- expect(createRef).toHaveBeenCalled();
77
- });
78
- });
79
-
80
44
  describe("mergeChildrenProps", () => {
81
45
  it("returns the cloned children with the merged props", () => {
82
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
  });