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

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 +242 -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 +16 -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
@@ -0,0 +1,55 @@
1
+ import { DeviceEventEmitter, NativeModules } from "react-native";
2
+ import { platformSelect } from "../reactUtils";
3
+
4
+ const { BackgroundTimer: RNBackgroundTimer } = NativeModules;
5
+
6
+ class BackgroundTimer {
7
+ private uniqueId: number;
8
+ private readonly callbacks: Record<number, () => void>;
9
+
10
+ constructor() {
11
+ this.uniqueId = 0;
12
+ this.callbacks = {};
13
+
14
+ const EventEmitter = platformSelect({
15
+ android: DeviceEventEmitter,
16
+ ios: undefined,
17
+ default: undefined,
18
+ });
19
+
20
+ EventEmitter?.addListener("BackgroundTimer.timer.fired", (id: number) => {
21
+ if (this.callbacks[id]) {
22
+ const callback = this.callbacks[id];
23
+ delete this.callbacks[id];
24
+ callback();
25
+ }
26
+ });
27
+ }
28
+
29
+ setTimeout(callback, timeout): number | NodeJS.Timeout {
30
+ if (!RNBackgroundTimer) {
31
+ return global.setTimeout(callback, timeout);
32
+ }
33
+
34
+ this.uniqueId += 1;
35
+ const timeoutId = this.uniqueId;
36
+
37
+ this.callbacks[timeoutId] = callback;
38
+ RNBackgroundTimer.setTimeout(timeoutId, timeout);
39
+
40
+ return timeoutId;
41
+ }
42
+
43
+ clearTimeout(timeoutId: number | NodeJS.Timeout): void {
44
+ if (!RNBackgroundTimer) {
45
+ return global.clearTimeout(timeoutId as NodeJS.Timeout);
46
+ }
47
+
48
+ if (this.callbacks[timeoutId as number]) {
49
+ delete this.callbacks[timeoutId as number];
50
+ RNBackgroundTimer.clearTimeout(timeoutId);
51
+ }
52
+ }
53
+ }
54
+
55
+ export default new BackgroundTimer();
package/time/Timer.ts CHANGED
@@ -1,16 +1,19 @@
1
+ import BackgroundTimer from "./BackgroundTimer";
2
+
1
3
  export class Timer {
2
4
  private startTime: number;
3
- private remaining: number;
4
- private timeoutId: NodeJS.Timeout | null;
5
+ private timeoutId: number | NodeJS.Timeout | null;
5
6
 
6
- constructor(private callback: () => void, private duration: number) {
7
- this.remaining = duration;
7
+ constructor(
8
+ private callback: () => void,
9
+ private remaining: number = null
10
+ ) {
8
11
  this.timeoutId = null;
9
12
  }
10
13
 
11
14
  start(): void {
12
15
  this.startTime = Date.now();
13
- this.timeoutId = setTimeout(this.callback, this.remaining);
16
+ this.timeoutId = BackgroundTimer.setTimeout(this.callback, this.remaining);
14
17
 
15
18
  this.remaining = 0;
16
19
  }
@@ -26,6 +29,6 @@ export class Timer {
26
29
  }
27
30
 
28
31
  clear(): void {
29
- clearTimeout(this.timeoutId);
32
+ BackgroundTimer.clearTimeout(this.timeoutId);
30
33
  }
31
34
  }
@@ -0,0 +1,3 @@
1
+ export const isString = (value: unknown) => {
2
+ return typeof value === "string";
3
+ };
package/types.ts CHANGED
@@ -8,4 +8,5 @@ export type ManifestField<T> = {
8
8
 
9
9
  export enum ENDPOINT_TAGS {
10
10
  allow_missing_keys = "allow_missing_keys",
11
+ observe_storage = "observe_storage",
11
12
  }
@@ -0,0 +1,30 @@
1
+ ### ramda replacement utils
2
+
3
+ See contribution guide below
4
+
5
+ ## Reference
6
+
7
+ Prefer non-fp variant as it more performant - if refactoring assumes you need more efforts rewrite ramda sample to lodash and it can be easily replaced with lodash-fp - use lodash-fp.
8
+
9
+ ### Ramda alternatives:
10
+
11
+ Custom
12
+ - `splitEvery` => `chunk`
13
+ - `times` => `times`
14
+
15
+ From `lodash`
16
+ - `clone` => `clone`
17
+ - `flatten` => `flatten`
18
+ - `drop` => `drop`
19
+ - `length` => `size`
20
+
21
+
22
+ ## Contribution
23
+
24
+ To add new helper function as ramda replacement
25
+
26
+ 1. Search for replacement ( you can use lodash or pure JS solution), arguments should match with Ramda definition (for easier transition).
27
+ 2. Add new file if needed, add test, update exports in index file. 2.1. Make sure it's well-typed.
28
+ 3. If the function can-be reexported from other 3rd party lib - update index.ts to re-export it.
29
+ 4. Make sure README is updated and contains reference for newly added function.
30
+ 5. You can use AI's help. Use query like 'lodash & lodash/fp equivalent of Ramda's R.clone function' to get an options you can use.
package/utils/chunk.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { chunk as _chunk } from "lodash";
2
+
3
+ export const chunk = <T>(size: number, array: T[]): T[][] => {
4
+ return _chunk(array, size);
5
+ };
package/utils/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ export { chunk } from "./chunk";
2
+
3
+ export { times } from "./times";
4
+
5
+ export {
6
+ cloneDeep as clone,
7
+ flatten,
8
+ drop,
9
+ size,
10
+ isNil,
11
+ isEmpty,
12
+ get,
13
+ has,
14
+ flatMap,
15
+ difference,
16
+ } from "lodash";
package/utils/times.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { times as _times } from "lodash";
2
+
3
+ export const times = <T>(iteratee: (index: number) => T, n: number) => {
4
+ return _times(n, iteratee);
5
+ };
@@ -1,6 +1,13 @@
1
1
  import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
2
2
  import { isNilOrEmpty } from "../reactUtils/helpers";
3
3
  import { parseJsonIfNeeded } from "@applicaster/zapp-react-native-utils/functionUtils";
4
+ import {
5
+ StorageOwnedValues,
6
+ NamespaceValues,
7
+ StorageValuesToRemove,
8
+ StorageValuesToAdd,
9
+ } from "./types";
10
+ import { Storage } from "@applicaster/zapp-react-native-bridge/ZappStorage/Storage";
4
11
 
5
12
  const defaultOwnedKey = "owned_keys";
6
13
  const DEFAULT_NAMESPACE = "applicaster.v2";
@@ -44,8 +51,9 @@ function mapOwnedKeysToAdd(
44
51
  return mappedData;
45
52
  }
46
53
 
47
- export async function batchSaveToLocalStorage(
48
- storageValues: StorageValuesToAdd
54
+ export async function batchSave(
55
+ storageValues: StorageValuesToAdd,
56
+ storage: Storage
49
57
  ) {
50
58
  if (isNilOrEmpty(storageValues)) {
51
59
  return false;
@@ -58,24 +66,37 @@ export async function batchSaveToLocalStorage(
58
66
  const value = namespaceData[key];
59
67
 
60
68
  if (!isNilOrEmpty(value)) {
61
- await localStorage.setItem(key, value, namespace);
69
+ await storage.setItem(key, value, namespace);
62
70
  }
63
71
  }
64
72
  }
65
73
  }
66
74
 
67
- export async function batchRemoveFromLocalStorage(
68
- storageValues: StorageValuesToRemove
75
+ export async function batchSaveToLocalStorage(
76
+ storageValues: StorageValuesToAdd
77
+ ) {
78
+ return await batchSave(storageValues, localStorage);
79
+ }
80
+
81
+ export async function batchRemoveFromStorage(
82
+ storageValues: StorageValuesToRemove,
83
+ storage: Storage = localStorage
69
84
  ) {
70
85
  for (const namespace of Object.keys(storageValues)) {
71
86
  const namespaceData = storageValues[namespace];
72
87
 
73
88
  for (const key of namespaceData) {
74
- await localStorage.removeItem(key, namespace);
89
+ await storage.removeItem(key, namespace);
75
90
  }
76
91
  }
77
92
  }
78
93
 
94
+ export async function batchRemoveFromLocalStorage(
95
+ storageValues: StorageValuesToRemove
96
+ ) {
97
+ await batchRemoveFromStorage(storageValues, localStorage);
98
+ }
99
+
79
100
  async function addOwnedKeys({
80
101
  newKeys,
81
102
  ownershipKey,
@@ -218,13 +239,20 @@ export async function batchRemoveOwnedNamespaceKeys({
218
239
  });
219
240
  }
220
241
 
221
- export async function batchRemoveAllFromNamespace(namespace) {
222
- const allDataInNamespace = await localStorage.getAllItems(namespace);
242
+ export async function batchRemoveAllFromNamespaceForStorage(
243
+ namespace: string,
244
+ storage: Storage
245
+ ) {
246
+ const allDataInNamespace = await storage.getAllItems(namespace);
223
247
  const keysToRemove = Object.keys(allDataInNamespace);
224
248
 
225
- const dataToRemove = {
249
+ const dataToRemove: StorageValuesToRemove = {
226
250
  [namespace]: keysToRemove,
227
251
  };
228
252
 
229
- await batchRemoveFromLocalStorage(dataToRemove);
253
+ await batchRemoveFromStorage(dataToRemove, storage);
254
+ }
255
+
256
+ export async function batchRemoveAllFromNamespace(namespace: string) {
257
+ await batchRemoveAllFromNamespaceForStorage(namespace, localStorage);
230
258
  }
@@ -89,11 +89,15 @@ const runInBackground = async ({
89
89
  const shouldPresent = await hookPresentPolicy.shouldPresentScreen();
90
90
 
91
91
  if (!shouldPresent) {
92
+ const isRefreshed = await checkUserAuthenticated();
93
+
92
94
  log_info(
93
- "runInBackground: Background mode finished, hook plugin will be skipped"
95
+ `runInBackground: Background mode finished, ${isRefreshed ? "finish hook with completion true" : "refresh failed will presentUI"}`
94
96
  );
95
97
 
96
- await checkUserAuthenticated();
98
+ isRefreshed
99
+ ? callback({ success: isRefreshed, payload: item })
100
+ : presentUI();
97
101
 
98
102
  return;
99
103
  }
@@ -92,9 +92,8 @@ export const PresentHookPluginOneTime = (
92
92
  const presentOneTimeVersionName =
93
93
  await getLatestWatchedVersionNumberFromStorage(storageKey, namespace);
94
94
 
95
- const applicationVersionName = await sessionStorage.getItem(
96
- versionNameKey
97
- );
95
+ const applicationVersionName =
96
+ await sessionStorage.getItem(versionNameKey);
98
97
 
99
98
  if (!presentOneTimeVersionName || !applicationVersionName) {
100
99
  log_info(
@@ -0,0 +1,11 @@
1
+ export type StorageValuesToAdd = Record<string, NamespaceValues>;
2
+
3
+ export type StorageValuesToRemove = {
4
+ string?: string[];
5
+ };
6
+
7
+ export type StorageOwnedValues = {
8
+ string?: string[];
9
+ };
10
+
11
+ export type NamespaceValues = Record<string, string>;
@@ -1,87 +0,0 @@
1
- import React, { useEffect, useState } from "react";
2
- import { usePrevious } from "@applicaster/zapp-react-native-utils/reactHooks/utils";
3
- import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
4
- import {
5
- MAX_SEEK_TIME,
6
- ON_HOLD_INTERVAL,
7
- SEEK_TYPE,
8
- SKIP_TIME_BASE,
9
- } from "./const";
10
- import { noop } from "../../functionUtils";
11
-
12
- export const useAutoSeek = (resetHUDTimer = noop) => {
13
- const [isRunning, setIsRunning] = useState<boolean>(false);
14
- const [direction, setDirection] = useState<Nullable<SEEK_TYPE>>(null);
15
- const [multiplier, setMultiplier] = useState(1);
16
- const intervalTimer = React.useRef(null);
17
- const prevRunning = usePrevious(isRunning);
18
-
19
- const clearIntervalTimer = () => {
20
- try {
21
- clearInterval(intervalTimer.current);
22
- } catch (err) {
23
- intervalTimer.current = null;
24
- }
25
- };
26
-
27
- const setIntervalTimer = (cb) => {
28
- clearIntervalTimer();
29
- intervalTimer.current = setInterval(cb, ON_HOLD_INTERVAL);
30
- };
31
-
32
- const resetState = () => {
33
- setIsRunning(false);
34
- setDirection(null);
35
- setMultiplier(1);
36
- clearIntervalTimer();
37
- };
38
-
39
- useEffect(() => {
40
- const player = playerManager.getInstanceController();
41
-
42
- if (!player) return;
43
-
44
- if (direction) {
45
- player[direction](Math.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier));
46
- resetHUDTimer();
47
- }
48
- }, [multiplier, direction]);
49
-
50
- useEffect(() => {
51
- if (isRunning && isRunning !== prevRunning) {
52
- setIntervalTimer(() => {
53
- setMultiplier((prev) => {
54
- return prev + 1;
55
- });
56
- });
57
- } else if (!isRunning && isRunning !== prevRunning) {
58
- resetState();
59
- }
60
-
61
- return () => {
62
- clearIntervalTimer();
63
- };
64
- }, [isRunning, direction]);
65
-
66
- const autoSeekStop = React.useCallback(() => {
67
- resetState();
68
- }, []);
69
-
70
- const autoSeekStart = React.useCallback(
71
- (eventType: SEEK_TYPE) => {
72
- // Check if there is another session running
73
- if (isRunning) {
74
- autoSeekStop();
75
- }
76
-
77
- setDirection(eventType);
78
- setIsRunning(true);
79
- },
80
- [isRunning]
81
- );
82
-
83
- return React.useMemo(
84
- () => ({ autoSeekStart, autoSeekStop }),
85
- [autoSeekStart, autoSeekStop]
86
- );
87
- };
@@ -1,66 +0,0 @@
1
- import React from "react";
2
- import { SEEK_TYPE } from "./const";
3
- import { useTapSeek } from "./useTapSeek";
4
- import { useAutoSeek } from "./useAutoSeek";
5
- import { noop } from "../../functionUtils";
6
-
7
- export const useSeek = (resetHUDTimer = noop) => {
8
- const handlePressEvent = useTapSeek();
9
- const { autoSeekStart, autoSeekStop } = useAutoSeek(resetHUDTimer);
10
-
11
- const onForwardPress = () => {
12
- handlePressEvent(SEEK_TYPE.FORWARD);
13
- };
14
-
15
- const onRewindPress = () => {
16
- handlePressEvent(SEEK_TYPE.REWIND);
17
- };
18
-
19
- const onForwardPressIn = () => {
20
- autoSeekStart(SEEK_TYPE.FORWARD);
21
- };
22
-
23
- const onForwardPressOut = () => {
24
- autoSeekStop();
25
- };
26
-
27
- const onRewindPressIn = () => {
28
- autoSeekStart(SEEK_TYPE.REWIND);
29
- };
30
-
31
- const onRewindLongPress = () => {
32
- autoSeekStart(SEEK_TYPE.REWIND);
33
- };
34
-
35
- const onForwardLongPress = () => {
36
- autoSeekStart(SEEK_TYPE.FORWARD);
37
- };
38
-
39
- const onRewindPressOut = () => {
40
- autoSeekStop();
41
- };
42
-
43
- return React.useMemo(
44
- () => ({
45
- onForwardPress,
46
- onRewindPress,
47
- onForwardPressIn,
48
- onForwardPressOut,
49
- onRewindPressIn,
50
- onRewindPressOut,
51
- onRewindLongPress,
52
- onForwardLongPress,
53
- }),
54
- [handlePressEvent, autoSeekStart]
55
- );
56
- };
57
-
58
- export const withUseSeek = (Component) =>
59
- Object.assign(
60
- (props) => {
61
- const seekMethods = useSeek(props?.resetHUDTimer);
62
-
63
- return <Component {...props} seekMethods={seekMethods} />;
64
- },
65
- { displayName: "WithUseSeek" }
66
- );
@@ -1,58 +0,0 @@
1
- import { useCallback, useRef } from "react";
2
- import * as R from "ramda";
3
- import {
4
- MAX_SEEK_TIME,
5
- ON_PRESS_RESET_DURATION,
6
- SEEK_TYPE,
7
- SKIP_TIME_BASE,
8
- } from "./const";
9
- import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils";
10
-
11
- type SeekType = SEEK_TYPE | null;
12
-
13
- const getSkipTime = (multiplier) => {
14
- const skipTime = R.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier);
15
-
16
- return skipTime;
17
- };
18
-
19
- export const useTapSeek = () => {
20
- const onPressMultiplier = useRef(1);
21
- const lastPressTime = useRef(0);
22
- const currentOnPressEventType = useRef<SeekType>(null);
23
-
24
- const resetMultiplier = useCallback(() => {
25
- onPressMultiplier.current = 1;
26
- }, []);
27
-
28
- const handlePressEvent = useCallback(
29
- (eventType) => {
30
- const player = playerManager.getInstanceController();
31
- if (!player) return;
32
-
33
- const now = Date.now();
34
- const timeSinceLastPress = now - lastPressTime.current;
35
- const isSameEventType = eventType === currentOnPressEventType.current;
36
-
37
- const isWithinResetDuration =
38
- timeSinceLastPress <= ON_PRESS_RESET_DURATION;
39
-
40
- const shouldIncreaseMultiplier = isSameEventType && isWithinResetDuration;
41
-
42
- if (shouldIncreaseMultiplier) {
43
- onPressMultiplier.current += 1;
44
- } else {
45
- resetMultiplier();
46
- }
47
-
48
- const seekTime = getSkipTime(onPressMultiplier.current);
49
- player[eventType](seekTime);
50
-
51
- lastPressTime.current = now;
52
- currentOnPressEventType.current = eventType;
53
- },
54
- [resetMultiplier]
55
- );
56
-
57
- return handlePressEvent;
58
- };
@@ -1,27 +0,0 @@
1
- jest.mock("create-react-context", () =>
2
- jest.fn(() => ({
3
- Consumer: jest.fn(),
4
- Provider: jest.fn(),
5
- }))
6
- );
7
-
8
- jest.mock("react", () => ({
9
- ...jest.requireActual("react"),
10
- createContext: undefined,
11
- }));
12
-
13
- const { createContext } = require("../index");
14
- const createReactContext = require("create-react-context");
15
-
16
- describe("when react context api is not defined", () => {
17
- it("uses the polyfill", () => {
18
- createContext({ foo: "bar" });
19
-
20
- expect(createReactContext).toHaveBeenCalledWith(
21
- expect.objectContaining({
22
- foo: "bar",
23
- setFoo: expect.any(Function),
24
- })
25
- );
26
- });
27
- });