@applicaster/zapp-react-native-utils 13.0.0-alpha.9433330286 → 13.0.0-rc.10

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 (37) hide show
  1. package/appUtils/HooksManager/{Hook.ts → Hook.js} +23 -35
  2. package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +2 -4
  3. package/appUtils/HooksManager/__tests__/hook.test.js +184 -196
  4. package/appUtils/HooksManager/__tests__/hooksManager.test.js +99 -96
  5. package/appUtils/HooksManager/{constants.ts → constants.js} +1 -1
  6. package/appUtils/HooksManager/{index.ts → index.js} +112 -121
  7. package/appUtils/RiverFocusManager/index.js +12 -17
  8. package/appUtils/focusManager/treeDataStructure/Tree/index.js +3 -2
  9. package/appUtils/focusManager/treeDataStructure/Utils/index.js +3 -1
  10. package/appUtils/{index.ts → index.js} +1 -1
  11. package/appUtils/keyCodes/__tests__/keyCodes.test.js +3 -3
  12. package/appUtils/keyCodes/{index.ts → index.js} +0 -2
  13. package/appUtils/keyCodes/{keys/keyEventMapper.ts → keys.android.js} +19 -0
  14. package/appUtils/keyCodes/keys.ios.js +46 -0
  15. package/appUtils/platform/platformUtils.ts +14 -0
  16. package/appUtils/playerManager/index.ts +6 -2
  17. package/domUtils/{cookieManager.ts → cookieManager.js} +2 -1
  18. package/functionUtils/index.ts +11 -15
  19. package/modalState/index.ts +5 -1
  20. package/navigationUtils/index.ts +5 -14
  21. package/package.json +2 -2
  22. package/reactHooks/navigation/index.ts +4 -7
  23. package/reactUtils/index.ts +14 -0
  24. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -693
  25. package/appUtils/HooksManager/types.ts +0 -116
  26. package/appUtils/keyCodes/keys/index.ts +0 -3
  27. package/appUtils/keyCodes/keys/keys.android.ts +0 -18
  28. package/appUtils/keyCodes/keys/keys.ios.ts +0 -25
  29. package/appUtils/keyCodes/keys/keys.ts +0 -15
  30. package/appUtils/keyCodes/keysByPlatform.ts +0 -8
  31. /package/appUtils/HooksManager/{logger.ts → logger.js} +0 -0
  32. /package/appUtils/{directionHelper.ts → directionHelper.js} +0 -0
  33. /package/appUtils/keyCodes/{androidTVKeys.ts → androidTVKeys.js} +0 -0
  34. /package/appUtils/keyCodes/{keys/keys.web.ts → keys.web.js} +0 -0
  35. /package/appUtils/keyCodes/{keys/keysByPlatform.ts → keysByPlatform.js} +0 -0
  36. /package/appUtils/{localizationsHelper.ts → localizationsHelper.js} +0 -0
  37. /package/domUtils/{logger.ts → logger.js} +0 -0
@@ -26,7 +26,7 @@ export const riverFocusManager = (function () {
26
26
  /**
27
27
  * Retrieve screen focus data by id
28
28
  *
29
- * @param {{screenFocusableGroupId: string}} screenFocusableGroupId Unique Id of the screen from layout.json
29
+ * @param {String} screenFocusableGroupId Id that was used to save screen data.
30
30
  *
31
31
  */
32
32
  function screenFocusableData({ screenFocusableGroupId }) {
@@ -36,9 +36,8 @@ export const riverFocusManager = (function () {
36
36
  /**
37
37
  * Clear screen data for specific screen
38
38
  *
39
- * @param {{ screenId: string, isInsideContainer: boolean }}
40
- * screenId Unique Id of the screen from layout.json
41
- * isInsideContainer If this screen a screen picker child
39
+ * @param {String} screenId Unique Id of the screen from layout.json
40
+ * @param {boolean} isInsideContainer If this screen a screen picker child
42
41
  *
43
42
  */
44
43
  function clearScreenData({ screenId, isInsideContainer }) {
@@ -61,13 +60,9 @@ export const riverFocusManager = (function () {
61
60
  /**
62
61
  * Focus on selected items
63
62
  *
64
- * @param {{
65
- * screenFocusableGroupId: string,
66
- * screenFocusedOnItem: () => void,
67
- * previousAction: QuickBrickNavigationActionType,
68
- * isDeepLink: boolean }} object contains data for focus
69
- * - `screenFocusedOnItem` focusable item to focus
70
- * - `previousActionhistory` navigator history object
63
+ * @param {String} screenFocusableGroupId Top group id that was saved as screenn
64
+ * @param {String} screenFocusedOnItem focusable item to focus
65
+ * @param {object} history navigator history object
71
66
  *
72
67
  */
73
68
  function focusOnSelectedItem({
@@ -120,15 +115,15 @@ export const riverFocusManager = (function () {
120
115
 
121
116
  /**
122
117
  * Create unique key that will be used for save focused group data inside specific screen
123
- * @param {{ screenId: string, isInsideContainer: boolean }}
124
- * screenId Unique Id of the screen from layout.json
125
- * isInsideContainer If this screen a screen picker child
118
+ *
119
+ * @param {String} screenId Unique Id of the screen from layout.json
120
+ * @param {boolean} isInsideContainer If this screen a screen picker child
126
121
  *
127
122
  */
128
123
  function screenFocusableGroupId({ screenId, isInsideContainer }) {
129
- return `RiverFocusableGroup-${screenId}${
130
- R.isNil(isInsideContainer) ? "" : "-isInsideContainer"
131
- }`;
124
+ return R.isNil(isInsideContainer)
125
+ ? `RiverFocusableGroup-${screenId}`
126
+ : `RiverFocusableGroup-${screenId}-isInsideContainer`;
132
127
  }
133
128
 
134
129
  return {
@@ -59,7 +59,7 @@ export class Tree {
59
59
  /**
60
60
  * Update node with provided data from newNode
61
61
  * @private
62
- * @param {Object} currentNode to update
62
+ * @param {Object} node to update
63
63
  * @param {Object} newNode node to take data from
64
64
  */
65
65
  updateNode(currentNode, newNode) {
@@ -175,6 +175,7 @@ export class Tree {
175
175
  * @private
176
176
  * @param {Object} node to check
177
177
  * @returns True if node has defined groupID
178
+ * @returns False if node has NOT defined groupID
178
179
  */
179
180
  hasGroupID(node) {
180
181
  return node.component && node.component.props.groupId;
@@ -190,7 +191,7 @@ export class Tree {
190
191
  const findChildNode = this.findInTree(node.component.props.groupId);
191
192
 
192
193
  if (findChildNode) {
193
- this.root.children.pop();
194
+ this.root.children.pop(findChildNode);
194
195
  node.children.push(findChildNode);
195
196
  }
196
197
  }
@@ -191,6 +191,7 @@ const toDistance = ({ target, direction, comparisonRect }) => {
191
191
  * Get target in shortest distance in specified direction
192
192
  * @private
193
193
  * @param {Object} direction of the navigation, which led to this focus change
194
+ * @param {Object} excludedNode node which should be excluded from target group
194
195
  * @param {Array} targetNodes array of input target nodes
195
196
  * @param {Object} comparisonRect rectangle to compare sides in direction.
196
197
  * @returns {Object} target in direction.
@@ -299,7 +300,8 @@ export function findFocusableNode(direction, currentFocusNode) {
299
300
  * @public
300
301
  * @param {Object} direction of the navigation, which led to this focus change
301
302
  * @param {Object} component - object to check props.prioritiseFocusOn
302
- * @returns {Boolean} TRUE if object has priority in direction. FALSE if object has NO priority in direction.
303
+ * @returns {Boolean} TRUE if object has priority in direction.
304
+ * @returns {Boolean} FALSE if object has NO priority in direction.
303
305
  */
304
306
  export function hasPriorityInDirection(direction, component) {
305
307
  const { prioritiseFocusOn = 0 } = component.props;
@@ -9,7 +9,7 @@ export { KEYS, ARROW_KEYS } from "./keyCodes/keys";
9
9
 
10
10
  export { playerManager } from "./playerManager";
11
11
 
12
- export { AccessibilityManager } from "./accessibilityManager";
12
+ export { accessibilityManager } from "./accessibilityManager";
13
13
 
14
14
  export function deprecationMessage(fn, replacement) {
15
15
  if (__DEV__ && process.env.NODE_ENV !== "test") {
@@ -13,7 +13,7 @@ const globalTizen = {
13
13
  describe("keyCodes", () => {
14
14
  describe("keyCode", () => {
15
15
  const { keyCode } = require("..");
16
- const { KEYS } = require("../keys/keys.web");
16
+ const { KEYS } = require("../keys.web");
17
17
 
18
18
  it("returns an object for a given key event", () => {
19
19
  expect(keyCode(KEYS.Enter)).toMatchSnapshot();
@@ -63,7 +63,7 @@ describe("keyCodes", () => {
63
63
  it("uses the proper keyCode for the environment", () => {
64
64
  Platform.OS = "samsung_tv";
65
65
  const { keyCode } = require("../");
66
- const { KEYS } = require("../keys/keys.web");
66
+ const { KEYS } = require("../keys.web");
67
67
 
68
68
  expect(globalTizen.tvinputdevice.registerKeyBatch).toHaveBeenCalledWith([
69
69
  "MediaPlay",
@@ -97,7 +97,7 @@ describe("keyCodes", () => {
97
97
  it("uses the proper keyCode for the environment", () => {
98
98
  Platform.OS = "lg_tv";
99
99
  const { keyCode } = require("..");
100
- const { KEYS } = require("../keys/keys.web");
100
+ const { KEYS } = require("../keys.web");
101
101
  // Back is reserved on LG
102
102
  expect(keyCode({ keyCode: 417 }).matches(KEYS.Forward)).toBeTruthy();
103
103
  });
@@ -6,8 +6,6 @@ import * as R from "ramda";
6
6
  import { directionHelper } from "../directionHelper";
7
7
  import { KEYS, ARROW_KEYS } from "./keys";
8
8
 
9
- export { KEYS, ARROW_KEYS, keyEventMapper } from "./keys";
10
-
11
9
  /**
12
10
  * @typedef KeyCode
13
11
  * @property {Object} value of the Key
@@ -1,3 +1,22 @@
1
+ export const KEYS = {
2
+ Enter: { code: "Enter", keyCode: 13 },
3
+ EnterKeyboard: { code: "EnterKeyboard", keyCode: 66 },
4
+ Back: { code: "Back", keyCode: 8 },
5
+ Space: { code: "Space", keyCode: 32 },
6
+ m: { code: "m", keyCode: 77 },
7
+ ArrowLeft: { code: "ArrowLeft", keyCode: 37 },
8
+ ArrowUp: { code: "ArrowUp", keyCode: 38 },
9
+ ArrowRight: { code: "ArrowRight", keyCode: 39 },
10
+ ArrowDown: { code: "ArrowDown", keyCode: 40 },
11
+ };
12
+
13
+ export const ARROW_KEYS = [
14
+ KEYS.ArrowUp,
15
+ KEYS.ArrowLeft,
16
+ KEYS.ArrowDown,
17
+ KEYS.ArrowRight,
18
+ ];
19
+
1
20
  export function keyEventMapper(keyCode) {
2
21
  switch (keyCode) {
3
22
  case 19: // ArrowUp
@@ -0,0 +1,46 @@
1
+ /* global tizen */
2
+ const isTizen = typeof tizen !== "undefined";
3
+
4
+ export const KEYS = {
5
+ Enter: { code: "Enter", keyCode: 13 },
6
+ Space: { code: "Space", keyCode: 32 },
7
+ m: { code: "m", keyCode: 77 },
8
+ ArrowLeft: { code: "ArrowLeft", keyCode: 37 },
9
+ ArrowUp: { code: "ArrowUp", keyCode: 38 },
10
+ ArrowRight: { code: "ArrowRight", keyCode: 39 },
11
+ ArrowDown: { code: "ArrowDown", keyCode: 40 },
12
+ Back: isTizen
13
+ ? { code: "Back", keyCode: 10009 }
14
+ : { code: "Backspace", keyCode: 8 },
15
+ Play: isTizen
16
+ ? { code: "MediaPlay", keyCode: 10252 }
17
+ : { code: "PlayPause", keyCode: 179 },
18
+ Pause: isTizen
19
+ ? { code: "MediaPause", keyCode: 19 }
20
+ : { code: "Pause", keyCode: 179 },
21
+ Forward: isTizen
22
+ ? { code: "MediaFastForward", keyCode: 417 }
23
+ : { code: "Forward", keyCode: 176 },
24
+ Rewind: isTizen
25
+ ? { code: "MediaRewind", keyCode: 412 }
26
+ : { code: "Rewind", keyCode: 177 },
27
+ VolumeUp: isTizen
28
+ ? { code: "VolumeUp", keyCode: 447 }
29
+ : { code: "VolumeUp", keyCode: 175 },
30
+ VolumeDown: isTizen
31
+ ? { code: "VolumeDown", keyCode: 448 }
32
+ : { code: "VolumeDown", keyCode: 174 },
33
+ ToggleMute: isTizen
34
+ ? { code: "VolumeMute", keyCode: 449 }
35
+ : { code: "VolumeMute", keyCode: 173 },
36
+ Stop: isTizen
37
+ ? { code: "MediaStop", keyCode: 413 }
38
+ : { code: "Q", keyCode: 81 },
39
+ };
40
+
41
+ export const ARROW_KEYS = [
42
+ KEYS.ArrowUp,
43
+ KEYS.ArrowLeft,
44
+ KEYS.ArrowDown,
45
+ KEYS.ArrowRight,
46
+ ];
@@ -9,6 +9,20 @@ import {
9
9
  import { PLATFORM_KEYS, PLATFORMS } from "./const";
10
10
  import { createLogger, utilsLogger } from "../../logger";
11
11
 
12
+ declare global {
13
+ interface Window {
14
+ VIZIO?: {
15
+ exitApplication: () => void;
16
+ Chromevox: {
17
+ play: (text: string) => void;
18
+ };
19
+ setClosedCaptionHandler: (
20
+ callback: (isCCEnabled: boolean) => void
21
+ ) => void;
22
+ };
23
+ }
24
+ }
25
+
12
26
  const { log_debug } = createLogger({
13
27
  category: "General",
14
28
  subsystem: "PlatformUtils",
@@ -169,8 +169,12 @@ export class PlayerManager {
169
169
  this.addPlayer(id, playerController);
170
170
 
171
171
  if (playerController.playerRole === PlayerRole.Primary) {
172
- if (playerController.playerPluginId !== "QuickBrickPlayerPlugin") {
173
- RNPlayerManager?.["QuickBrickPlayerPlugin"]?.stopBackgroundPlayback?.();
172
+ if (RNPlayerManager) {
173
+ Object.keys(RNPlayerManager).forEach((pluginId) => {
174
+ if (pluginId !== playerController.playerPluginId) {
175
+ RNPlayerManager[pluginId]?.stopBackgroundPlayback?.();
176
+ }
177
+ });
174
178
  }
175
179
 
176
180
  playerController.addListener({
@@ -2,6 +2,7 @@ import { domUtilsLogger } from "./logger";
2
2
 
3
3
  /**
4
4
  * Gets an object of cookies and sets them on the DOM.
5
+ * @param {Object} cookies selected data key for label.
5
6
  */
6
7
  export function setCookies(cookies): void {
7
8
  const cookieKeys = Object.keys(cookies);
@@ -24,7 +25,7 @@ export function setCookies(cookies): void {
24
25
  /**
25
26
  * Gets cookies set on DOM
26
27
  */
27
- export function getCookies(): typeof document.cookie {
28
+ export function getCookies(): Object {
28
29
  try {
29
30
  if (document) {
30
31
  return document.cookie;
@@ -111,12 +111,12 @@ type SubscriberFn<T> = (
111
111
 
112
112
  export type EventHandlerFn<T> = (event: string, ...args: unknown[]) => T;
113
113
 
114
- export type SubscriberObj<T extends {} = {}> = {
115
- on: SubscriberFn<SubscriberObj<T>>;
116
- invokeHandler: EventHandlerFn<SubscriberObj<T>>;
117
- removeHandler: EventHandlerFn<SubscriberObj<T>>;
118
- handlers: Record<string, SubscriberFn<SubscriberObj<T>>[] | []>;
119
- } & T;
114
+ type SubscriberObj = Partial<{
115
+ on?: SubscriberFn<SubscriberObj>;
116
+ invokeHandler: EventHandlerFn<SubscriberObj>;
117
+ removeHandler: EventHandlerFn<SubscriberObj>;
118
+ handlers: Record<string, SubscriberFn<SubscriberObj>[] | []>;
119
+ }>;
120
120
 
121
121
  export const clearObject = (object: { [key: string]: unknown }) =>
122
122
  Object.keys(object).forEach((key) => delete object[key]);
@@ -126,11 +126,7 @@ export const clearObject = (object: { [key: string]: unknown }) =>
126
126
  * @param {Object} obj to add the subscription feature on
127
127
  * @returns {Object} subscriber object
128
128
  */
129
- export function subscriber<T extends Partial<SubscriberObj> = {}>(
130
- _obj: T = {} as T
131
- ): SubscriberObj {
132
- const obj: T = _obj;
133
-
129
+ export function subscriber(obj: SubscriberObj = {}): SubscriberObj {
134
130
  if (!obj.handlers) {
135
131
  obj.handlers = {};
136
132
  }
@@ -176,7 +172,7 @@ export function subscriber<T extends Partial<SubscriberObj> = {}>(
176
172
  | SubscriberFn<SubscriberObj>[]
177
173
  | [];
178
174
 
179
- return obj as SubscriberObj;
175
+ return obj;
180
176
  };
181
177
 
182
178
  /**
@@ -192,16 +188,16 @@ export function subscriber<T extends Partial<SubscriberObj> = {}>(
192
188
 
193
189
  R.compose(R.forEach(callHandlerWithDispose), R.propOr([], event))(handlers);
194
190
 
195
- return obj as SubscriberObj;
191
+ return obj;
196
192
  };
197
193
 
198
194
  obj.removeHandler = function (event, handler) {
199
195
  handlers[event] = R.reject(R.equals(handler), handlers[event]);
200
196
 
201
- return obj as SubscriberObj;
197
+ return obj;
202
198
  };
203
199
 
204
- return obj as SubscriberObj;
200
+ return obj;
205
201
  }
206
202
 
207
203
  /**
@@ -31,7 +31,11 @@ export const useModalStore = create<ModalStore>((set) => ({
31
31
  set((state) => ({
32
32
  modalState: { ...state.modalState, ...newState },
33
33
  })),
34
- openModal: ({ item, options = {}, props }: OpenModalArg) =>
34
+ openModal: ({
35
+ item,
36
+ options = {},
37
+ props = { screenData: {} },
38
+ }: OpenModalArg) =>
35
39
  set({
36
40
  modalState: {
37
41
  visible: true,
@@ -324,13 +324,7 @@ export function getPathAttributes({
324
324
  * @param {object} rivers
325
325
  * @returns {object}
326
326
  */
327
- export function getRiverFromRoute({
328
- route,
329
- rivers,
330
- }: {
331
- route: string;
332
- rivers: Record<string, ZappRiver>;
333
- }) {
327
+ export function getRiverFromRoute({ route, rivers }) {
334
328
  if (!route) {
335
329
  return null;
336
330
  }
@@ -443,7 +437,7 @@ export const runZappHooksForEntry = async (
443
437
 
444
438
  let success;
445
439
  let payload;
446
- const rivers: Record<string, ZappRiver> = appStore.get("rivers");
440
+ const rivers = appStore.get("rivers");
447
441
  const plugins = appStore.get("plugins");
448
442
  const appData = appStore.get("appData");
449
443
 
@@ -498,16 +492,13 @@ export const runZappHooksForEntry = async (
498
492
  payload = _payload;
499
493
  };
500
494
 
501
- const hooksManager = HooksManager(hooksOptions);
502
-
503
- hooksManager.subscriber
495
+ HooksManager(hooksOptions)
504
496
  .on(HOOKS_EVENTS.PRESENT_SCREEN_HOOK, handleHookPresent)
505
497
  .on(HOOKS_EVENTS.START_BACKGROUND_HOOK, handleBackgroundHook)
506
498
  .on(HOOKS_EVENTS.ERROR, onFinished(false))
507
499
  .on(HOOKS_EVENTS.CANCEL, onFinished(false))
508
- .on(HOOKS_EVENTS.COMPLETE, onFinished(true));
509
-
510
- hooksManager.handleHooks(entry);
500
+ .on(HOOKS_EVENTS.COMPLETE, onFinished(true))
501
+ .handleHooks(entry);
511
502
 
512
503
  // eslint-disable-next-line no-unmodified-loop-condition
513
504
  while (success === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "13.0.0-alpha.9433330286",
3
+ "version": "13.0.0-rc.10",
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": "13.0.0-alpha.9433330286",
31
+ "@applicaster/applicaster-types": "13.0.0-rc.10",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -320,19 +320,16 @@ export const useZappHooksForEntry = (
320
320
  callbacks?.handleHookComplete?.(props);
321
321
  };
322
322
 
323
- const hookManager = HooksManager(hooksOptions);
324
-
325
- hookManager.subscriber
323
+ const hookManager = HooksManager(hooksOptions)
326
324
  .on(HOOKS_EVENTS.PRESENT_SCREEN_HOOK, handleHookPresent)
327
325
  .on(HOOKS_EVENTS.ERROR, handleHookError)
328
326
  .on(HOOKS_EVENTS.CANCEL, handleHookCancel)
329
327
  .on(HOOKS_EVENTS.START_BACKGROUND_HOOK, handleBackgroundHook)
330
- .on(HOOKS_EVENTS.COMPLETE, handleHookComplete);
331
-
332
- hookManager.handleHooks(entry);
328
+ .on(HOOKS_EVENTS.COMPLETE, handleHookComplete)
329
+ .handleHooks(entry);
333
330
 
334
331
  return () => {
335
- hookManager.subscriber
332
+ hookManager
336
333
  .removeHandler(HOOKS_EVENTS.PRESENT_SCREEN_HOOK, handleHookPresent)
337
334
  .removeHandler(HOOKS_EVENTS.ERROR, handleHookError)
338
335
  .removeHandler(HOOKS_EVENTS.CANCEL, handleHookCancel)
@@ -109,6 +109,20 @@ export const isTvOSPlatform = () => getPlatform() === "tvos";
109
109
 
110
110
  export const isAndroidTVPlatform = () => getPlatform() === "android_tv";
111
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
+
112
126
  /**
113
127
  * Platforms found in userAgent string, please note that simulators
114
128
  * might not have the same agents that the devices have