@applicaster/zapp-react-native-utils 13.0.0-alpha.5033140607 → 13.0.0-alpha.5049772260

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 (171) 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/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.js → Hook.ts} +39 -23
  12. package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +10 -8
  13. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +693 -0
  14. package/appUtils/HooksManager/__tests__/hook.test.js +196 -184
  15. package/appUtils/HooksManager/__tests__/hooksManager.test.js +96 -99
  16. package/appUtils/HooksManager/{constants.js → constants.ts} +1 -1
  17. package/appUtils/HooksManager/{index.js → index.ts} +124 -113
  18. package/appUtils/HooksManager/types.ts +119 -0
  19. package/appUtils/RiverFocusManager/index.js +17 -12
  20. package/appUtils/accessibilityManager/index.ts +42 -1
  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 +8 -6
  25. package/appUtils/focusManager/index.ts +108 -69
  26. package/appUtils/focusManager/treeDataStructure/Tree/index.js +25 -3
  27. package/appUtils/focusManager/treeDataStructure/Utils/index.js +1 -3
  28. package/appUtils/focusManager/utils/enums.ts +4 -0
  29. package/appUtils/focusManagerAux/utils/index.ts +4 -3
  30. package/appUtils/{index.js → index.ts} +1 -1
  31. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
  32. package/appUtils/keyCodes/__tests__/keyCodes.test.js +4 -4
  33. package/appUtils/keyCodes/{index.js → index.ts} +13 -7
  34. package/appUtils/keyCodes/keys/index.ts +3 -0
  35. package/appUtils/keyCodes/{keys.android.js → keys/keyEventMapper.ts} +0 -19
  36. package/appUtils/keyCodes/keys/keys.android.ts +18 -0
  37. package/appUtils/keyCodes/keys/keys.ios.ts +25 -0
  38. package/appUtils/keyCodes/keys/keys.ts +15 -0
  39. package/appUtils/keyCodes/{keysByPlatform.js → keys/keysByPlatform.ts} +4 -0
  40. package/appUtils/keyCodes/keysByPlatform.ts +8 -0
  41. package/appUtils/keyInputHandler/KeyInputHandler.ts +68 -0
  42. package/appUtils/{localizationsHelper.js → localizationsHelper.ts} +23 -0
  43. package/appUtils/orientationHelper.ts +11 -13
  44. package/appUtils/platform/const.ts +14 -0
  45. package/appUtils/platform/platformUtils.ts +47 -18
  46. package/appUtils/playerManager/index.ts +1 -1
  47. package/appUtils/playerManager/player.ts +42 -18
  48. package/appUtils/playerManager/playerNative.ts +18 -2
  49. package/appUtils/playerManager/usePlayerControllerSetup.tsx +3 -3
  50. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +7 -1
  51. package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
  52. package/componentsUtils/__tests__/isFirstComponentGallery.test.ts +33 -0
  53. package/componentsUtils/__tests__/isFirstComponentScreenPicker.test.ts +33 -0
  54. package/componentsUtils/__tests__/isGallery.test.ts +33 -0
  55. package/componentsUtils/__tests__/isScreenPicker.test.ts +33 -0
  56. package/componentsUtils/index.ts +32 -0
  57. package/dateUtils/index.ts +19 -0
  58. package/domUtils/{cookieManager.js → cookieManager.ts} +1 -2
  59. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  60. package/equalUtils/index.ts +49 -30
  61. package/focusManager/FocusManager.ts +14 -2
  62. package/focusManager/index.ts +23 -4
  63. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
  64. package/functionUtils/index.ts +61 -19
  65. package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
  66. package/idleUtils/index.ts +1 -1
  67. package/idleUtils/withTimeout.ts +15 -2
  68. package/index.d.ts +0 -12
  69. package/localizationUtils/index.ts +5 -10
  70. package/logger/const.ts +9 -67
  71. package/manifestUtils/__tests__/createConfig.test.js +16 -16
  72. package/manifestUtils/defaultManifestConfigurations/generalContent.js +13 -0
  73. package/manifestUtils/defaultManifestConfigurations/player.js +14 -0
  74. package/manifestUtils/fonts/index.js +5 -6
  75. package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
  76. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +875 -0
  77. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
  78. package/modalState/__tests__/index.test.ts +51 -0
  79. package/modalState/index.ts +33 -7
  80. package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +7 -6
  81. package/navigationUtils/__tests__/itemTypes.test.js +2 -2
  82. package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
  83. package/navigationUtils/index.ts +20 -9
  84. package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +23 -3
  85. package/numberUtils/index.ts +11 -5
  86. package/package.json +5 -10
  87. package/playerUtils/configurationGenerator.ts +14 -0
  88. package/reactHooks/advertising/index.ts +5 -5
  89. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  90. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +6 -8
  91. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  92. package/reactHooks/cell-click/__tests__/index.test.js +10 -2
  93. package/reactHooks/cell-click/index.ts +7 -1
  94. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
  95. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
  96. package/reactHooks/feed/useFeedLoader.tsx +18 -9
  97. package/reactHooks/feed/usePipesCacheReset.ts +5 -5
  98. package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
  99. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +39 -0
  100. package/reactHooks/layout/__tests__/index.test.tsx +10 -10
  101. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
  102. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
  103. package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
  104. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  105. package/reactHooks/navigation/__tests__/index.test.tsx +6 -21
  106. package/reactHooks/navigation/index.ts +41 -240
  107. package/reactHooks/navigation/useGetBottomTabBarHeight.ts +12 -0
  108. package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
  109. package/reactHooks/navigation/useGetTabBarHeight.ts +10 -0
  110. package/reactHooks/navigation/useIsScreenActive.ts +17 -0
  111. package/reactHooks/navigation/useNavigationPluginData.ts +15 -0
  112. package/reactHooks/navigation/useNavigationType.ts +15 -0
  113. package/reactHooks/navigation/usePathname.ts +4 -0
  114. package/reactHooks/navigation/useProfilerLogging.ts +15 -0
  115. package/reactHooks/navigation/useRoute.ts +98 -0
  116. package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
  117. package/reactHooks/player/TVSeekControlller/ISeekController.ts +32 -0
  118. package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +71 -0
  119. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +258 -0
  120. package/reactHooks/player/TVSeekControlller/TapSeekController.ts +53 -0
  121. package/reactHooks/player/__tests__/{useAutoSeek.test.tsx → useAutoSeek._test.tsx} +2 -3
  122. package/reactHooks/player/const.ts +0 -4
  123. package/reactHooks/player/index.ts +0 -6
  124. package/reactHooks/state/useRefWithInitialValue.ts +14 -0
  125. package/reactHooks/state/useStateFromSubscribe.ts +23 -0
  126. package/reactHooks/useListenEventBusEvent.ts +1 -1
  127. package/reactHooks/usePluginConfiguration.ts +1 -1
  128. package/reactHooks/useSubscriberFor.ts +4 -3
  129. package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
  130. package/reactUtils/__tests__/reactUtils.test.js +1 -37
  131. package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
  132. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +13 -79
  133. package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +2 -2
  134. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
  135. package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
  136. package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
  137. package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
  138. package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
  139. package/reactUtils/createContext/__tests__/provider.test.js +4 -6
  140. package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
  141. package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
  142. package/reactUtils/createContext/helpers.ts +6 -1
  143. package/reactUtils/createContext/index.ts +11 -25
  144. package/reactUtils/index.ts +0 -25
  145. package/screenState/index.ts +24 -10
  146. package/services/js2native.ts +673 -0
  147. package/testUtils/index.tsx +0 -10
  148. package/theme/__mocks__/index.ts +4 -0
  149. package/theme/index.ts +1 -1
  150. package/time/BackgroundTimer.ts +55 -0
  151. package/time/Timer.ts +9 -6
  152. package/types.ts +1 -0
  153. package/utils/README.md +30 -0
  154. package/utils/chunk.ts +5 -0
  155. package/utils/index.ts +5 -0
  156. package/utils/times.ts +5 -0
  157. package/zappFrameworkUtils/localStorageHelper.ts +6 -0
  158. package/zappFrameworkUtils/loginPluginUtils.ts +6 -2
  159. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
  160. package/zappFrameworkUtils/types.ts +11 -0
  161. package/appUtils/keyCodes/keys.ios.js +0 -46
  162. package/reactHooks/player/useAutoSeek.tsx +0 -87
  163. package/reactHooks/player/useSeek.tsx +0 -66
  164. package/reactHooks/player/useTapSeek.tsx +0 -58
  165. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
  166. /package/appUtils/HooksManager/{logger.js → logger.ts} +0 -0
  167. /package/appUtils/{directionHelper.js → directionHelper.ts} +0 -0
  168. /package/appUtils/keyCodes/{androidTVKeys.js → androidTVKeys.ts} +0 -0
  169. /package/appUtils/keyCodes/{keys.web.js → keys/keys.web.ts} +0 -0
  170. /package/domUtils/{logger.js → logger.ts} +0 -0
  171. /package/reactHooks/player/__tests__/{useTapSeek.test.ts → useTapSeek._test.ts} +0 -0
@@ -0,0 +1,130 @@
1
+ const defaultPlatforms = {
2
+ tvos: "tvOS",
3
+ android_tv: "Android TV",
4
+ lg_tv: "LG TV",
5
+ samsung_tv: "Samsung TV",
6
+ };
7
+
8
+ const global_defaults = {
9
+ fontSize: 20,
10
+ lineHeight: 40,
11
+ letterSpacing: 0.4,
12
+ };
13
+
14
+ const generateFontConfiguration = (platforms = defaultPlatforms) => {
15
+ const platformEntries = Object.entries(platforms);
16
+ const defaultsEntries = Object.entries(global_defaults);
17
+ const splitCamelCase = (str) => str.replace(/([a-z](?=[A-Z]))/g, "$1_");
18
+
19
+ return platformEntries.reduce((acc, [platformKey, platformValue]) => {
20
+ acc.push(
21
+ ...defaultsEntries.reduce((acc2, [valueKey, defaultValue]) => {
22
+ acc2.push({
23
+ type: "number_input",
24
+ label: `${platformValue} ${splitCamelCase(valueKey).replace(
25
+ "_",
26
+ " "
27
+ )}`,
28
+ key: `${platformKey}_${splitCamelCase(valueKey)}`.toLowerCase(),
29
+ initial_value: defaultValue,
30
+ });
31
+
32
+ return acc2;
33
+ }, [])
34
+ );
35
+
36
+ return acc;
37
+ }, []);
38
+ };
39
+
40
+ const conditional_rule = (key, condition_value) => ({
41
+ key,
42
+ condition_value,
43
+ });
44
+
45
+ const createConditionalConfig = (rules, matchAll = false) => ({
46
+ rules: matchAll ? "all_conditions" : "conditional",
47
+ conditional_fields: rules.map((field) => conditional_rule(...field)),
48
+ });
49
+
50
+ const conditional_horizontal_type = createConditionalConfig([
51
+ ["styles/screen_picker_type", "horizontal"],
52
+ ]);
53
+
54
+ const conditional_vertical_type = createConditionalConfig([
55
+ ["styles/screen_picker_type", "vertical"],
56
+ ]);
57
+
58
+ const conditional_horizontal_type_item_fixed = createConditionalConfig(
59
+ [
60
+ ["styles/screen_picker_type", "horizontal"],
61
+ ["styles/screen_picker_item_size", "fixed"],
62
+ ],
63
+ true
64
+ );
65
+
66
+ const conditional_horizontal_type_item_dynamic = createConditionalConfig(
67
+ [
68
+ ["styles/screen_picker_type", "horizontal"],
69
+ ["screen_picker_horizontal_display_type", "dynamic"],
70
+ ],
71
+ true
72
+ );
73
+
74
+ const conditional_horizontal_display_type_fixed = createConditionalConfig(
75
+ [
76
+ ["styles/screen_picker_type", "horizontal"],
77
+ ["styles/screen_picker_horizontal_display_type", "fixed"],
78
+ ],
79
+ true
80
+ );
81
+
82
+ const conditional_horizontal_asset_on = createConditionalConfig(
83
+ [
84
+ ["styles/screen_picker_type", "horizontal"],
85
+ ["styles/screen_picker_asset_switch", true],
86
+ ],
87
+ true
88
+ );
89
+
90
+ const createVariationFields = ({
91
+ prefix = "screen_picker",
92
+ key,
93
+ type = "number_input",
94
+ label = "",
95
+ variants: [a, b],
96
+ }) => {
97
+ return [
98
+ {
99
+ type,
100
+ key: `${prefix}${prefix.length > 0 ? "_" : ""}${
101
+ a?.key ?? "vertical"
102
+ }_${key}`,
103
+ label: a?.label ?? label,
104
+ initial_value: a.initial_value,
105
+ ...conditional_vertical_type,
106
+ },
107
+ {
108
+ type,
109
+ key: `${prefix}${prefix.length > 0 ? "_" : ""}${
110
+ b.key ?? "horizontal"
111
+ }_${key}`,
112
+ label: b?.label ?? label,
113
+ initial_value: b.initial_value,
114
+ ...conditional_horizontal_type,
115
+ },
116
+ ];
117
+ };
118
+
119
+ module.exports = {
120
+ generateFontConfiguration,
121
+ createVariationFields,
122
+ createConditionalConfig,
123
+ conditional_rule,
124
+ conditional_horizontal_type,
125
+ conditional_vertical_type,
126
+ conditional_horizontal_type_item_fixed,
127
+ conditional_horizontal_type_item_dynamic,
128
+ conditional_horizontal_display_type_fixed,
129
+ conditional_horizontal_asset_on,
130
+ };
@@ -0,0 +1,51 @@
1
+ import { modalStore } from "../";
2
+
3
+ describe("Modal State", () => {
4
+ it("should have initial state", () => {
5
+ const state = modalStore.getState();
6
+
7
+ expect(state).toMatchObject({
8
+ modalState: {
9
+ visible: false,
10
+ screen: null,
11
+ options: {},
12
+ props: {},
13
+ },
14
+ });
15
+
16
+ expect(state.openModal).toBeDefined();
17
+ expect(state.dismissModal).toBeDefined();
18
+ });
19
+
20
+ describe("opening and dismissing modal", () => {
21
+ it("should open modal", () => {
22
+ const item = { id: "test", name: "Test Modal" };
23
+ const options = { animated: true, animationType: "slide" };
24
+ const props = { customProp: "value" };
25
+
26
+ modalStore.getState().openModal({ item, options, props });
27
+
28
+ const state = modalStore.getState();
29
+
30
+ expect(state.modalState).toMatchObject({
31
+ visible: true,
32
+ screen: item,
33
+ options,
34
+ props,
35
+ });
36
+ });
37
+
38
+ it("should dismiss modal", () => {
39
+ modalStore.getState().dismissModal();
40
+
41
+ const state = modalStore.getState();
42
+
43
+ expect(state.modalState).toMatchObject({
44
+ visible: false,
45
+ screen: null,
46
+ options: {},
47
+ props: {},
48
+ });
49
+ });
50
+ });
51
+ });
@@ -1,4 +1,4 @@
1
- import { create } from "zustand";
1
+ import { useStore, createStore } from "zustand";
2
2
 
3
3
  interface ModalState {
4
4
  visible: boolean;
@@ -25,17 +25,13 @@ const initialModalState: ModalState = {
25
25
  props: {},
26
26
  };
27
27
 
28
- export const useModalStore = create<ModalStore>((set) => ({
28
+ export const modalStore = createStore<ModalStore>((set) => ({
29
29
  modalState: initialModalState,
30
30
  setModalState: (newState) =>
31
31
  set((state) => ({
32
32
  modalState: { ...state.modalState, ...newState },
33
33
  })),
34
- openModal: ({
35
- item,
36
- options = {},
37
- props = { screenData: {} },
38
- }: OpenModalArg) =>
34
+ openModal: ({ item, options = {}, props }: OpenModalArg) =>
39
35
  set({
40
36
  modalState: {
41
37
  visible: true,
@@ -55,3 +51,33 @@ export const useModalStore = create<ModalStore>((set) => ({
55
51
  }),
56
52
  dismissModal: () => set(() => ({ modalState: initialModalState })),
57
53
  }));
54
+
55
+ export const useModalStore = <T>(selector: (state: ModalStore) => T) =>
56
+ useStore(modalStore, selector);
57
+
58
+ export const openModal = modalStore.getInitialState().openModal;
59
+
60
+ export const dismissModal = modalStore.getInitialState().dismissModal;
61
+
62
+ export const openBottomSheetModal = ({
63
+ ModalBottomSheetContent,
64
+ modalBottomSheetContentProps,
65
+ props = {},
66
+ options = {},
67
+ }: OpenModalBottomSheetArgs) => {
68
+ openModal({
69
+ item: {
70
+ ModalBottomSheetContent,
71
+ modalBottomSheetContentProps,
72
+ },
73
+ props,
74
+ options: {
75
+ animationType: "none",
76
+ animated: false,
77
+ ...options,
78
+ },
79
+ });
80
+ };
81
+
82
+ export const useModalStoreState = (): ModalState =>
83
+ useModalStore<ModalState>((state) => state.modalState);
@@ -1,19 +1,20 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`getNavigationProps returns the props otherwise 1`] = `
4
- Object {
5
- "assets": Object {
4
+ {
5
+ "assets": {
6
6
  "appLogo": "appLogo.png",
7
7
  },
8
+ "data": undefined,
8
9
  "home": false,
9
- "nav_items": Array [
10
- Object {
10
+ "nav_items": [
11
+ {
11
12
  "type": "label",
12
13
  },
13
14
  ],
14
- "rules": Object {},
15
+ "rules": {},
15
16
  "selected": "A1234",
16
- "styles": Object {
17
+ "styles": {
17
18
  "style": "foo",
18
19
  },
19
20
  "title": "testTitle",
@@ -61,8 +61,8 @@ describe("getTypeMatcher", () => {
61
61
 
62
62
  describe("isItemOfType", () => {
63
63
  it("is a curried function", () => {
64
- expect(itemIsOfType(river, SCREEN_TYPES.RIVER)).toBeBoolean();
65
- expect(itemIsOfType(river)).toBeFunction();
64
+ expect(itemIsOfType(river, SCREEN_TYPES.RIVER)).toBeTruthy();
65
+ expect(itemIsOfType(river)).toBeInstanceOf(Function);
66
66
  });
67
67
 
68
68
  it("returns true if the item is of the given type", () => {
@@ -243,7 +243,7 @@ describe("getTargetRoute", () => {
243
243
  it("returns a valid path when initial pathname is /", () => {
244
244
  const targetRoute = getTargetRoute(river, "/", { layoutVersion });
245
245
  expect(targetRoute).toEqual(`/river/${river.id}`);
246
- expect(targetRoute).not.toInclude("//");
246
+ expect(targetRoute).not.toContainEntry("//");
247
247
  });
248
248
  });
249
249
 
@@ -273,7 +273,7 @@ describe("getTargetRoute", () => {
273
273
  it("returns a valid path when initial pathname is /", () => {
274
274
  const targetRoute = getTargetRoute(river, "/", { layoutVersion });
275
275
  expect(targetRoute).toEqual(`/river/${river.id}`);
276
- expect(targetRoute).not.toInclude("//");
276
+ expect(targetRoute).not.toContainEntry("//");
277
277
  });
278
278
  });
279
279
  });
@@ -111,6 +111,7 @@ export function getNavigationProps({
111
111
  assets: ZappNavBarAssets;
112
112
  rules: ZappNavBarRules;
113
113
  nav_items: NavBarItem[];
114
+ data: MenuItemDataProperties;
114
115
  } | null {
115
116
  const { activeRiver } = navigator;
116
117
  const { navigations, id: selected, home } = activeRiver; // use useRiver hook instead
@@ -124,7 +125,7 @@ export function getNavigationProps({
124
125
  return null;
125
126
  }
126
127
 
127
- const { styles, assets, nav_items, rules } = navigation;
128
+ const { styles, assets, nav_items, rules, data } = navigation;
128
129
 
129
130
  return {
130
131
  selected,
@@ -134,6 +135,7 @@ export function getNavigationProps({
134
135
  assets: assets as ZappNavBarAssets,
135
136
  nav_items: nav_items as any as NavBarItem[],
136
137
  rules: rules as any as ZappNavBarRules,
138
+ data: data as MenuItemDataProperties,
137
139
  };
138
140
  }
139
141
 
@@ -324,7 +326,13 @@ export function getPathAttributes({
324
326
  * @param {object} rivers
325
327
  * @returns {object}
326
328
  */
327
- export function getRiverFromRoute({ route, rivers }) {
329
+ export function getRiverFromRoute({
330
+ route,
331
+ rivers,
332
+ }: {
333
+ route: string;
334
+ rivers: Record<string, ZappRiver>;
335
+ }) {
328
336
  if (!route) {
329
337
  return null;
330
338
  }
@@ -437,7 +445,7 @@ export const runZappHooksForEntry = async (
437
445
 
438
446
  let success;
439
447
  let payload;
440
- const rivers = appStore.get("rivers");
448
+ const rivers: Record<string, ZappRiver> = appStore.get("rivers");
441
449
  const plugins = appStore.get("plugins");
442
450
  const appData = appStore.get("appData");
443
451
 
@@ -492,13 +500,16 @@ export const runZappHooksForEntry = async (
492
500
  payload = _payload;
493
501
  };
494
502
 
495
- HooksManager(hooksOptions)
503
+ const hooksManager = HooksManager(hooksOptions);
504
+
505
+ hooksManager.subscriber
496
506
  .on(HOOKS_EVENTS.PRESENT_SCREEN_HOOK, handleHookPresent)
497
507
  .on(HOOKS_EVENTS.START_BACKGROUND_HOOK, handleBackgroundHook)
498
508
  .on(HOOKS_EVENTS.ERROR, onFinished(false))
499
509
  .on(HOOKS_EVENTS.CANCEL, onFinished(false))
500
- .on(HOOKS_EVENTS.COMPLETE, onFinished(true))
501
- .handleHooks(entry);
510
+ .on(HOOKS_EVENTS.COMPLETE, onFinished(true));
511
+
512
+ hooksManager.handleHooks(entry);
502
513
 
503
514
  // eslint-disable-next-line no-unmodified-loop-condition
504
515
  while (success === undefined) {
@@ -635,8 +646,8 @@ export const getScreenId = (
635
646
  fallbackRiver: ZappRiver
636
647
  ) => {
637
648
  return screenData?.targetScreen
638
- ? screenData?.targetScreen?.id ?? fallbackRiver.id
649
+ ? (screenData?.targetScreen?.id ?? fallbackRiver.id)
639
650
  : "screen_id" in screenData
640
- ? screenData.screen_id
641
- : fallbackRiver.id;
651
+ ? screenData.screen_id
652
+ : fallbackRiver.id;
642
653
  };
@@ -1,10 +1,10 @@
1
1
  import { toPositiveNumberWithDefault } from "..";
2
2
 
3
- describe("toNumber", () => {
3
+ describe("toPositiveNumberWithDefault", () => {
4
4
  const DEFAULT = 5;
5
5
 
6
6
  it("return number if input is positive number", () => {
7
- const inputs = [0, 1, 2, 100, 200.12, Infinity];
7
+ const inputs = [1, 2, 100, 200.12, Infinity];
8
8
  expect.assertions(inputs.length);
9
9
 
10
10
  inputs.forEach((input) => {
@@ -14,7 +14,7 @@ describe("toNumber", () => {
14
14
  });
15
15
 
16
16
  it("return number if input is positive number as string", () => {
17
- const inputs = ["0", "1", "2", "100", "200.12"];
17
+ const inputs = ["1", "2", "100", "200.12"];
18
18
  expect.assertions(inputs.length);
19
19
 
20
20
  inputs.forEach((input) => {
@@ -63,4 +63,24 @@ describe("toNumber", () => {
63
63
  expect(output).toBe(DEFAULT);
64
64
  });
65
65
  });
66
+
67
+ it("return default if input is zero number", () => {
68
+ const inputs = [0, -0];
69
+ expect.assertions(inputs.length);
70
+
71
+ inputs.forEach((input) => {
72
+ const output = toPositiveNumberWithDefault(DEFAULT, input);
73
+ expect(output).toBe(DEFAULT);
74
+ });
75
+ });
76
+
77
+ it("return default if input is zero string", () => {
78
+ const inputs = ["0", "-0"];
79
+ expect.assertions(inputs.length);
80
+
81
+ inputs.forEach((input) => {
82
+ const output = toPositiveNumberWithDefault(DEFAULT, input);
83
+ expect(output).toBe(DEFAULT);
84
+ });
85
+ });
66
86
  });
@@ -3,7 +3,7 @@ import { logger } from "@applicaster/zapp-react-native-utils/logger";
3
3
 
4
4
  const numberUtilsLogger = logger?.addSubsystem("NumberUtils");
5
5
 
6
- export const toNumber = (value: any): number | undefined => {
6
+ export const toNumber = (value: unknown): number | undefined => {
7
7
  if (R.isNil(value) || R.isEmpty(value)) {
8
8
  return undefined;
9
9
  }
@@ -17,10 +17,12 @@ export const toNumber = (value: any): number | undefined => {
17
17
  return undefined;
18
18
  };
19
19
 
20
- export const toNumberWithDefault = (defaultValue: number, value: any): number =>
21
- toNumber(value) ?? defaultValue;
20
+ export const toNumberWithDefault = (
21
+ defaultValue: number,
22
+ value: unknown
23
+ ): number => toNumber(value) ?? defaultValue;
22
24
 
23
- export const toNumberWithDefaultZero = (value: any): number =>
25
+ export const toNumberWithDefaultZero = (value: unknown): number =>
24
26
  toNumberWithDefault(0, value);
25
27
 
26
28
  export const requireNumber = (obj, key: string) => {
@@ -39,7 +41,7 @@ export const requireNumber = (obj, key: string) => {
39
41
 
40
42
  export const toFiniteNumberWithDefault = (
41
43
  defaultValue: number,
42
- value: any
44
+ value: unknown
43
45
  ): number => {
44
46
  const possibleNumber = toNumberWithDefault(defaultValue, value);
45
47
 
@@ -81,6 +83,10 @@ export const toPositiveNumberWithDefault = (
81
83
  return defaultValue;
82
84
  }
83
85
 
86
+ if (isZero(possibleNumber)) {
87
+ return defaultValue;
88
+ }
89
+
84
90
  return possibleNumber;
85
91
  };
86
92
 
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "13.0.0-alpha.5033140607",
3
+ "version": "13.0.0-alpha.5049772260",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "scripts": {
8
- "test": "jest -w=2",
9
8
  "build": "echo skipping hybrid ts build in main packages for now"
10
9
  },
11
10
  "publishConfig": {
@@ -28,11 +27,9 @@
28
27
  },
29
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
29
  "dependencies": {
31
- "@applicaster/applicaster-types": "13.0.0-alpha.5033140607",
30
+ "@applicaster/applicaster-types": "13.0.0-alpha.5049772260",
32
31
  "buffer": "^5.2.1",
33
32
  "camelize": "^1.0.0",
34
- "create-react-context": "^0.2.3",
35
- "create-react-ref": "^0.1.0",
36
33
  "dayjs": "^1.11.10",
37
34
  "memoizee": "0.4.15",
38
35
  "prop-types": "^15.0.0",
@@ -42,12 +39,10 @@
42
39
  "@applicaster/zapp-pipes-v2-client": "*",
43
40
  "@react-native-community/netinfo": "*",
44
41
  "immer": "*",
45
- "react": "17.0.2",
46
- "react-native": "0.68.6",
42
+ "react": "*",
43
+ "react-native": "*",
44
+ "uglify-js": "*",
47
45
  "validate-color": "*",
48
46
  "zustand": "*"
49
- },
50
- "devDependencies": {
51
- "@types/react-native": "0.69.6"
52
47
  }
53
48
  }
@@ -55,6 +55,14 @@ function getPlayerConfiguration({ platform }) {
55
55
  label_tooltip:
56
56
  "Set the query params which control the size of the image e.g width, height. This will help to optimize the loading time, when magic background is enabled.",
57
57
  },
58
+ {
59
+ key: "audio_player_background_image_default_color",
60
+ label: "Audio Player Background Image Default Color",
61
+ initial_value: "",
62
+ type: "text_input",
63
+ label_tooltip:
64
+ "Set the default color for the audio player background image if not image or set of gradient colors are not provided.",
65
+ },
58
66
  ],
59
67
  };
60
68
 
@@ -2549,6 +2557,12 @@ function getPlayerConfiguration({ platform }) {
2549
2557
  multiple: false,
2550
2558
  label_tooltip: "Choose the default aspect ratio for the artwork",
2551
2559
  },
2560
+ {
2561
+ key: "audio_player_artwork_border_radius",
2562
+ label: "Audio Player Artwork Corner Radius",
2563
+ type: "number_input",
2564
+ initial_value: 16,
2565
+ },
2552
2566
  ]
2553
2567
  )
2554
2568
  );
@@ -5,6 +5,7 @@ import * as R from "ramda";
5
5
  import { useNavigation } from "../navigation";
6
6
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
7
7
  import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
8
+ import { dismissModal, openModal } from "../../modalState";
8
9
 
9
10
  const GOOGLE_ADS_IDENTIFIER = "google-admob-ads-qb";
10
11
 
@@ -14,9 +15,8 @@ const ModalContainer = platformSelect({
14
15
  });
15
16
 
16
17
  export function useAdvertisingInterstitial() {
17
- const navigator = useNavigation();
18
+ const { screenData, currentRoute } = useNavigation();
18
19
  const { plugins } = usePickFromState();
19
- const { screenData } = navigator;
20
20
 
21
21
  return useEffect(() => {
22
22
  // TODD: typing problem: fix any type
@@ -26,7 +26,7 @@ export function useAdvertisingInterstitial() {
26
26
  plugins
27
27
  );
28
28
 
29
- navigator.openModal({
29
+ openModal({
30
30
  item: {},
31
31
  options: {
32
32
  ModalContainer,
@@ -36,11 +36,11 @@ export function useAdvertisingInterstitial() {
36
36
  screenType: "hooks",
37
37
  screenData: {
38
38
  payload: screenData,
39
- callback: navigator.dismissModal,
39
+ callback: dismissModal,
40
40
  hookPlugin: GoogleAdsPlugin,
41
41
  },
42
42
  },
43
43
  });
44
44
  }
45
- }, [navigator.currentRoute, screenData?.id]);
45
+ }, [currentRoute, screenData?.id]);
46
46
  }
@@ -14,7 +14,7 @@ jest.mock(
14
14
 
15
15
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
16
16
 
17
- jest.useFakeTimers();
17
+ jest.useFakeTimers({ legacyFakeTimers: true });
18
18
 
19
19
  const {
20
20
  useTrackCurrentAutoScrollingElement,
@@ -19,7 +19,7 @@ jest.mock(
19
19
  })
20
20
  );
21
21
 
22
- jest.useFakeTimers();
22
+ jest.useFakeTimers({ legacyFakeTimers: true });
23
23
 
24
24
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
25
25
 
@@ -35,25 +35,23 @@ const Wrapper = ({ children }: { children: React.ReactChild }) => (
35
35
  const { useTrackedView } = require("../useTrackedView");
36
36
 
37
37
  describe("useTrackCurrentAutoScrollingElement", () => {
38
- it("should update position for selected component", async () => {
38
+ it("should update position for selected component - onViewportEnter", () => {
39
39
  const { result } = renderHook(() => useTrackedView("123"), {
40
40
  wrapper: Wrapper,
41
41
  });
42
42
 
43
- // Fast-forward until all timers have been executed
44
- jest.advanceTimersByTime(3000);
45
-
46
43
  expect(result.current.inViewPort).toBe(false);
47
44
 
48
45
  const mockRect = {
49
46
  rect: { left: 1, right: 1, top: 1, bottom: 1 },
50
47
  };
51
48
 
52
- act(() => {
53
- result.current.onPositionUpdated(mockRect);
49
+ act(async () => {
50
+ await result.current.onPositionUpdated(mockRect);
54
51
  });
55
52
 
56
- jest.advanceTimersByTime(3000);
53
+ // Fast-forward until all timers have been executed
54
+ jest.runAllTimers();
57
55
 
58
56
  expect(result.current.inViewPort).toBe(true);
59
57
 
@@ -2,6 +2,10 @@ import { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import { useScreenTrackedViewPositionsContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenTrackedViewPositionsContext";
3
3
  import { useDimensions } from "@applicaster/zapp-react-native-utils/reactHooks/layout";
4
4
  import { findTrackedView } from "./utils/findTrackedView";
5
+ import { isNil } from "ramda";
6
+ import { withTimeout } from "@applicaster/zapp-react-native-utils/idleUtils";
7
+
8
+ const TIMEOUT_FOR_DELAY_ON_VIEWPORT_ENTER_EVENT = 500; // ms
5
9
 
6
10
  const getNormalizedRect = (rect, componentId, screenWidth, screenHeight) => {
7
11
  if (!rect) {
@@ -37,9 +41,16 @@ export const useTrackedView = (componentId: string) => {
37
41
  );
38
42
 
39
43
  const onPositionUpdated = useCallback(
40
- ({ rect }) => {
44
+ async ({ rect }) => {
41
45
  const currentPosition = normalizedRect(componentId, rect);
42
46
 
47
+ // There is an issue on the native side where they are unable to guarantee
48
+ // that the order of onViewportLeave and onViewportEnter events is always correct.
49
+ // This workaround/hack delays the onViewportEnter event to ensure it is received last.
50
+ if (!isNil(currentPosition)) {
51
+ await withTimeout(TIMEOUT_FOR_DELAY_ON_VIEWPORT_ENTER_EVENT);
52
+ }
53
+
43
54
  updateComponentsPositions(componentId, currentPosition as any);
44
55
 
45
56
  setInViewPort(!!currentPosition);