@applicaster/zapp-react-native-utils 12.0.0-alpha.4536343143 → 12.0.0-alpha.4584840011

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 (34) hide show
  1. package/appUtils/accessibilityManager/const.ts +50 -0
  2. package/appUtils/accessibilityManager/hooks.ts +40 -0
  3. package/appUtils/accessibilityManager/index.ts +155 -0
  4. package/appUtils/accessibilityManager/logger.ts +5 -0
  5. package/appUtils/focusManager/index.ts +0 -1
  6. package/appUtils/focusManager/treeDataStructure/Utils/index.js +1 -1
  7. package/appUtils/index.js +2 -0
  8. package/appUtils/keyCodes/keys.web.js +8 -0
  9. package/appUtils/keyCodes/keysByPlatform.js +11 -1
  10. package/appUtils/platform/const.ts +25 -0
  11. package/appUtils/platform/index.ts +3 -0
  12. package/appUtils/platform/platformUtils.ts +185 -0
  13. package/appUtils/playerManager/conts.ts +1 -0
  14. package/appUtils/playerManager/index.ts +11 -5
  15. package/appUtils/playerManager/nativePlayerManager.ts +12 -0
  16. package/appUtils/playerManager/player.ts +9 -3
  17. package/appUtils/playerManager/playerNative.ts +4 -13
  18. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -0
  19. package/booleanUtils/index.ts +4 -4
  20. package/cellUtils/index.ts +5 -5
  21. package/index.d.ts +15 -0
  22. package/keyboardState/index.ts +0 -0
  23. package/navigationUtils/index.ts +48 -0
  24. package/numberUtils/__tests__/toNumber.test.ts +2 -2
  25. package/package.json +2 -2
  26. package/playerUtils/imaScriptDom.ts +59 -0
  27. package/pluginUtils/index.ts +9 -0
  28. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
  29. package/reactHooks/feed/useFeedRefresh.tsx +9 -7
  30. package/reactHooks/navigation/index.ts +12 -2
  31. package/reactUtils/index.ts +104 -0
  32. package/appUtils/focusManager/FocusableEvents.ts +0 -8
  33. package/appUtils/focusManager/treeDataStructure/Utils/__tests__/Utils_android.test.js +0 -1094
  34. package/appUtils/focusManager/treeDataStructure/Utils/index.android.js +0 -261
@@ -72,6 +72,7 @@ export const usePlayerControllerSetup = ({
72
72
 
73
73
  return () => {
74
74
  playerManager.unregisterPlayer(playerId);
75
+ playerController.destroy?.();
75
76
  };
76
77
  }, [playerId, playerController]);
77
78
 
@@ -1,7 +1,7 @@
1
- import * as R from "ramda";
1
+ import { is, toLower } from "ramda";
2
2
 
3
3
  export const toBoolean = (value: any): boolean | undefined => {
4
- if (R.is(Boolean, value)) {
4
+ if (is(Boolean, value)) {
5
5
  return value;
6
6
  }
7
7
 
@@ -17,12 +17,12 @@ export const toBooleanWithDefaultTrue = toBooleanWithDefault(true);
17
17
 
18
18
  export const toBooleanWithDefaultFalse = toBooleanWithDefault(false);
19
19
 
20
- export const isTrue = (value: any): boolean => {
20
+ export const isTrue = (value: unknown): boolean => {
21
21
  if (value === true) {
22
22
  return true;
23
23
  }
24
24
 
25
- if (R.is(String, value) && value.toLowerCase() === "true") {
25
+ if (is(String, value) && toLower(value) === "true") {
26
26
  return true;
27
27
  }
28
28
 
@@ -31,13 +31,12 @@ export const getKeyForLabel = (dataKey, customKey) => {
31
31
  * This method will return true if the argument passed to it is either empty or nil
32
32
  * The method prevents zero from being evaluated as falsey in an || condition
33
33
  * i.e. - NaN, null, {}, "", [], should all return true
34
- * @param {*} argument - argument passed to it could be any type
35
34
  * @returns {Boolean} returns true if empty or nil
35
+ * @param value
36
36
  */
37
- export const isEmptyOrNil = R.either(
38
- R.equals(NaN),
39
- R.either(R.isEmpty, R.isNil)
40
- );
37
+
38
+ export const isEmptyOrNil = (value: any): boolean =>
39
+ Number.isNaN(value) || value == null || R.isEmpty(value);
41
40
 
42
41
  /**
43
42
  * This method is used to find the appropriate label for any given text field.
@@ -320,6 +319,7 @@ export const ifElseFocusedSelected = (
320
319
  * @param {Object} stylesObj styles object with keys from zapp { button_icon_width: "10" }
321
320
  * @returns {*} value, returns any type that can be used as styles
322
321
  */
322
+
323
323
  export const getValue = (stylesObj) => (key) => {
324
324
  return R.propOr(null, key, stylesObj);
325
325
  };
package/index.d.ts CHANGED
@@ -143,3 +143,18 @@ declare type BuilderData = {
143
143
  river?: ZappRiver;
144
144
  method?: string;
145
145
  };
146
+
147
+ declare type AccessibilityState = {
148
+ screenReaderEnabled: boolean;
149
+ reduceMotionEnabled: boolean;
150
+ boldTextEnabled: boolean;
151
+ };
152
+
153
+ declare type AccessibilityProps = {
154
+ accessibilityLabel?: string;
155
+ accessibilityHint?: string;
156
+ "aria-label"?: string;
157
+ "aria-description"?: string;
158
+ accessibilityRole?: string;
159
+ "aria-role"?: string;
160
+ };
File without changes
@@ -592,3 +592,51 @@ export function isMenuDisabled(
592
592
  export function routeIsPlayerScreen(currentRoute) {
593
593
  return currentRoute?.includes("/playable");
594
594
  }
595
+
596
+ export const getNavBarProps =
597
+ (currentRiver: ZappRiver, pathname: string, title: string) => () => {
598
+ const props = getNavigationPropsV2({
599
+ currentRiver,
600
+ title,
601
+ category: "nav_bar",
602
+ });
603
+
604
+ if (props) {
605
+ return {
606
+ ...props,
607
+ id: pathname,
608
+ pathname: pathname,
609
+ };
610
+ }
611
+
612
+ return null;
613
+ };
614
+
615
+ export const findMenuPlugin = (
616
+ navigations: ZappNavigation[],
617
+ plugins
618
+ ): QuickBrickPlugin => {
619
+ return resolveNavigationPlugin({
620
+ category: "menu",
621
+ navigations,
622
+ plugins,
623
+ }) as QuickBrickPlugin;
624
+ };
625
+
626
+ export const shouldNavBarDisplayMenu = (currentRiver: ZappRiver, plugins) =>
627
+ findMenuPlugin(currentRiver.navigations, plugins)?.identifier ===
628
+ "quick_brick_side_menu" ||
629
+ currentRiver?.navigations.findIndex(
630
+ (nav) => nav.category === "nav_bar" && nav.general?.override_menu_target
631
+ ) > -1;
632
+
633
+ export const getScreenId = (
634
+ screenData: LegacyNavigationScreenData,
635
+ fallbackRiver: ZappRiver
636
+ ) => {
637
+ return screenData?.targetScreen
638
+ ? screenData?.targetScreen?.id ?? fallbackRiver.id
639
+ : "screen_id" in screenData
640
+ ? screenData.screen_id
641
+ : fallbackRiver.id;
642
+ };
@@ -2,7 +2,7 @@ import { toNumber } from "..";
2
2
 
3
3
  describe("toNumber", () => {
4
4
  it("return number if input is number", () => {
5
- const inputs = [-1, 0, 1, 100];
5
+ const inputs = [-1, 0, 1, 100, 0.2];
6
6
  expect.assertions(inputs.length);
7
7
 
8
8
  inputs.forEach((input) => {
@@ -12,7 +12,7 @@ describe("toNumber", () => {
12
12
  });
13
13
 
14
14
  it("return number if input is string as number", () => {
15
- const inputs = ["-1", "0", "1", "100"];
15
+ const inputs = ["-1", "0", "1", "100", "0.2"];
16
16
  expect.assertions(inputs.length);
17
17
 
18
18
  inputs.forEach((input) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "12.0.0-alpha.4536343143",
3
+ "version": "12.0.0-alpha.4584840011",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "12.0.0-alpha.4536343143",
31
+ "@applicaster/applicaster-types": "12.0.0-alpha.4584840011",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -0,0 +1,59 @@
1
+ import { createLogger } from "../logger";
2
+
3
+ export const logger = createLogger({
4
+ category: "ImaDomUtils",
5
+ subsystem: "Player/ImaDomUtils",
6
+ });
7
+
8
+ const { log_debug, log_error, log_verbose } = logger;
9
+
10
+ const removeElement = (node) => {
11
+ if (node) {
12
+ const parentNode = node.parentNode;
13
+
14
+ if (parentNode) {
15
+ parentNode.removeChild(node);
16
+ }
17
+ }
18
+ };
19
+
20
+ // TODO: This should probably be loaded to root of project before player init
21
+ export const loadIMAScript = async () => {
22
+ return new Promise((resolve) => {
23
+ // If ima script is already loaded, resolve
24
+ const imaScript = document.getElementById("ima-script");
25
+
26
+ if (imaScript) {
27
+ log_verbose("loadIMAScript: IMA script already loaded");
28
+
29
+ return resolve(true);
30
+ }
31
+
32
+ const script = document.createElement("script");
33
+
34
+ if (__DEV__) {
35
+ script.src = "https://imasdk.googleapis.com/js/sdkloader/ima3_debug.js";
36
+ } else {
37
+ script.src = "https://imasdk.googleapis.com/js/sdkloader/ima3.js";
38
+ }
39
+
40
+ script.async = true;
41
+ script.id = "ima-script";
42
+
43
+ script.onload = () => {
44
+ removeElement(script);
45
+ log_debug("loadIMAScript: Loaded ima script", script.src);
46
+ resolve(true);
47
+ };
48
+
49
+ script.onerror = (_e) => {
50
+ removeElement(script);
51
+ log_error("loadIMAScript: Failed to load ima script", script.src);
52
+ resolve(false);
53
+ };
54
+
55
+ if (document.head) {
56
+ document.head.appendChild(script);
57
+ }
58
+ });
59
+ };
@@ -245,3 +245,12 @@ export function generateManifest({ manifestConfig, version }) {
245
245
 
246
246
  return manifestConfig({ platform, version });
247
247
  }
248
+
249
+ const getPluginType = R.pathOr("unknown_plugin_type", [
250
+ "state",
251
+ "screen",
252
+ "plugin_type",
253
+ ]);
254
+
255
+ export const isPlayerPlugin = (routeState): boolean =>
256
+ getPluginType(routeState) === "player";
@@ -1,9 +1,13 @@
1
1
  import { renderHook } from "@testing-library/react-hooks";
2
2
 
3
- import { useFeedRefresh, feedRefreshLogger } from "../";
4
-
5
3
  jest.useFakeTimers();
6
4
 
5
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
6
+ useIsScreenActive: () => true,
7
+ }));
8
+
9
+ const { useFeedRefresh, feedRefreshLogger } = require("..");
10
+
7
11
  describe("useFeedRefresh", () => {
8
12
  const reloadData = jest.fn();
9
13
 
@@ -1,7 +1,8 @@
1
1
  import * as React from "react";
2
- import * as R from "ramda";
2
+ import { path, max } from "ramda";
3
3
  import { isTrue } from "@applicaster/zapp-react-native-utils/booleanUtils";
4
4
  import { toNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
5
+ import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
5
6
 
6
7
  import { reactHooksLogger } from "../logger";
7
8
  import { ReloadDataFunction } from "./useFeedLoader";
@@ -18,9 +19,8 @@ const minimumRefreshingInterval = 5;
18
19
  const defaultRefreshInterval = 60;
19
20
 
20
21
  export const useFeedRefresh = ({ reloadData, component }: Props): void => {
21
- const enable_data_refreshing = R.path(
22
- ["rules", "enable_data_refreshing"],
23
- component
22
+ const isDataRefreshingEnabled = isTrue(
23
+ path(["rules", "enable_data_refreshing"], component)
24
24
  );
25
25
 
26
26
  const refreshing_interval = toNumberWithDefault(
@@ -29,10 +29,12 @@ export const useFeedRefresh = ({ reloadData, component }: Props): void => {
29
29
  );
30
30
 
31
31
  const refreshingIntervalInMilliseconds =
32
- R.max(refreshing_interval, minimumRefreshingInterval) * 1000;
32
+ max(refreshing_interval, minimumRefreshingInterval) * 1000;
33
+
34
+ const isScreenActive = useIsScreenActive();
33
35
 
34
36
  React.useEffect(() => {
35
- if (isTrue(enable_data_refreshing) && refreshing_interval) {
37
+ if (isDataRefreshingEnabled && refreshing_interval && isScreenActive) {
36
38
  if (refreshing_interval < minimumRefreshingInterval) {
37
39
  feedRefreshLogger.warning({
38
40
  message: `You set your feed refresh interval to ${refreshing_interval} when minimum value is ${minimumRefreshingInterval}seconds.Your feed will refresh after ${minimumRefreshingInterval}seconds.`,
@@ -59,5 +61,5 @@ export const useFeedRefresh = ({ reloadData, component }: Props): void => {
59
61
  clearInterval(refreshInterval);
60
62
  };
61
63
  }
62
- }, [reloadData]);
64
+ }, [reloadData, isScreenActive]);
63
65
  };
@@ -31,7 +31,7 @@ import { platformSelect } from "../../reactUtils";
31
31
  import { useConnectionInfo } from "../connection";
32
32
  import { getTargetScreenData } from "../screen/useTargetScreenData";
33
33
 
34
- import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
34
+ import { isTV, isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
35
35
  import { useNavbarState } from "../screen";
36
36
  import { useNavigation } from "./useNavigation";
37
37
  import { useModalStore } from "../../modalState";
@@ -78,6 +78,10 @@ export function isNavBarVisible(
78
78
  return false;
79
79
  }
80
80
 
81
+ if (screenData?.plugin_type === "login" && isTV()) {
82
+ return false;
83
+ }
84
+
81
85
  /* Match if screen is Hook */
82
86
  if (route.startsWith("/hooks/")) {
83
87
  const module = screenData?.module;
@@ -462,7 +466,13 @@ export const useUniqueRouteSuffix = (): Return => {
462
466
  const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
463
467
 
464
468
  const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
465
- return `${prefix}___${suffix}`;
469
+ if (isWeb()) {
470
+ // we should use extended route prefix only on Web, where we have stack-navigator
471
+ return `${prefix}___${suffix}`;
472
+ }
473
+
474
+ // for other platforms use previous version
475
+ return prefix;
466
476
  }, []);
467
477
 
468
478
  return withUniqueRouteSuffix;
@@ -108,3 +108,107 @@ export const isAndroidPlatform = () => Platform.OS === "android";
108
108
  export const isTvOSPlatform = () => getPlatform() === "tvos";
109
109
 
110
110
  export const isAndroidTVPlatform = () => getPlatform() === "android_tv";
111
+
112
+ declare global {
113
+ interface Window {
114
+ VIZIO?: {
115
+ Chromevox: {
116
+ play: (text: string) => void;
117
+ };
118
+ exitApplication: () => void;
119
+ setClosedCaptionHandler: (
120
+ callback: (isCCEnabled: boolean) => void
121
+ ) => void;
122
+ };
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Platforms found in userAgent string, please note that simulators
128
+ * might not have the same agents that the devices have
129
+ */
130
+ export const PLATFORMS = {
131
+ webos: "Web0S",
132
+ tizen: "Tizen",
133
+ samsung: "SMART-TV",
134
+ mac: "Mac",
135
+ win: "Win",
136
+ linux: "Linux",
137
+ iphone: "iPhone",
138
+ android: "Android",
139
+ mobile: "Mobile",
140
+ vizio: "VIZIO",
141
+ smartcast: "SmartCast",
142
+ conjure: "Conjure",
143
+ };
144
+
145
+ /**
146
+ * Simple way of identifying if we have access to the tizen APIs
147
+ */
148
+ export const hasTizen = typeof window?.tizen !== "undefined";
149
+
150
+ /**
151
+ * Simple way of identifying if we have access to the webOS APIs
152
+ */
153
+ export const hasWebOS = typeof window?.webOS !== "undefined";
154
+
155
+ export const getUserAgent = () => window?.navigator?.userAgent;
156
+
157
+ export const isLgPlatform = () => {
158
+ const userAgent = getUserAgent();
159
+
160
+ if (!userAgent) {
161
+ return false;
162
+ }
163
+
164
+ // Note: LG uses the number 0 in their userAgent, possibly because of Palm WebOS
165
+ return hasWebOS || userAgent.includes(PLATFORMS.webos);
166
+ };
167
+
168
+ export const isSamsungPlatform = () => {
169
+ const userAgent = getUserAgent();
170
+
171
+ if (!userAgent) {
172
+ return false;
173
+ }
174
+
175
+ return (
176
+ hasTizen ||
177
+ userAgent.includes(PLATFORMS.samsung) ||
178
+ userAgent.includes(PLATFORMS.tizen)
179
+ );
180
+ };
181
+
182
+ /**
183
+ * Checks if we are on the Vizio platform by using the userAgent string
184
+ *
185
+ * Use this method when you need to identify the platform on runtime
186
+ * before the VIZIO Companion Library has loaded
187
+ */
188
+ export const isVizioPlatform = () => {
189
+ const userAgent = getUserAgent();
190
+
191
+ if (!userAgent) {
192
+ return false;
193
+ }
194
+
195
+ const isVizioAgent =
196
+ userAgent.includes(PLATFORMS.vizio) ||
197
+ userAgent.includes(PLATFORMS.smartcast) ||
198
+ userAgent.includes(PLATFORMS.conjure);
199
+
200
+ return isVizioAgent;
201
+ };
202
+
203
+ /**
204
+ * Checks if we are on the Vizio platform by checking for the global VIZIO object
205
+ * and the VIZIO Companion Library. This method does not use the userAgent string,
206
+ * because it mainly checks whether we have access to apis, which may not be available yet
207
+ */
208
+ export const hasVizioAPIs = () => {
209
+ const hasAPIs =
210
+ typeof window.VIZIO !== "undefined" &&
211
+ window?.applicaster?.vizioLibraryDidLoad;
212
+
213
+ return hasAPIs;
214
+ };
@@ -1,8 +0,0 @@
1
- export const FOCUSABLE_EVENTS = {
2
- IS_REGISTERED: "isRegistered",
3
- WILL_RECEIVE_FOCUS: "willReceiveFocus",
4
- HAS_RECEIVED_FOCUS: "hasReceivedFocus",
5
- WILL_LOSE_FOCUS: "willLoseFocus",
6
- HAS_LOST_FOCUS: "hasLostFocus",
7
- WILL_UNREGISTER: "willUnregister",
8
- };