@applicaster/zapp-react-native-utils 12.0.0-rc.10 → 12.0.0-rc.100

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 (110) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +16 -8
  2. package/analyticsUtils/AnalyticsEvents/index.ts +13 -0
  3. package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
  4. package/analyticsUtils/AnalyticsEvents/sendShareEvent.ts +21 -0
  5. package/analyticsUtils/__tests__/analyticsManager.test.js +75 -73
  6. package/analyticsUtils/analyticsPlugins.ts +25 -0
  7. package/analyticsUtils/events.ts +12 -0
  8. package/analyticsUtils/helpers/hooks.ts +1 -1
  9. package/analyticsUtils/index.tsx +12 -0
  10. package/appUtils/HooksManager/index.js +3 -1
  11. package/appUtils/accessibilityManager/const.ts +50 -0
  12. package/appUtils/accessibilityManager/hooks.ts +40 -0
  13. package/appUtils/accessibilityManager/index.ts +155 -0
  14. package/appUtils/accessibilityManager/logger.ts +5 -0
  15. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -3
  16. package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
  17. package/appUtils/focusManager/__tests__/index.test.ts +2 -3
  18. package/appUtils/focusManager/index.ts +76 -57
  19. package/appUtils/focusManager/treeDataStructure/Utils/index.js +75 -35
  20. package/appUtils/focusManager/utils/index.ts +100 -0
  21. package/appUtils/focusManagerAux/index.ts +76 -0
  22. package/appUtils/focusManagerAux/utils/index.ts +100 -0
  23. package/appUtils/index.js +2 -0
  24. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +1 -1
  25. package/appUtils/keyCodes/__tests__/keyCodes.test.js +80 -85
  26. package/appUtils/keyCodes/keys.web.js +9 -0
  27. package/appUtils/keyCodes/keysByPlatform.js +11 -1
  28. package/appUtils/platform/const.ts +25 -0
  29. package/appUtils/platform/index.ts +3 -0
  30. package/appUtils/platform/platformUtils.ts +185 -0
  31. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +53 -0
  32. package/appUtils/playerManager/conts.ts +6 -0
  33. package/appUtils/playerManager/index.ts +11 -5
  34. package/appUtils/playerManager/nativePlayerManager.ts +12 -0
  35. package/appUtils/playerManager/player.ts +56 -7
  36. package/appUtils/playerManager/playerFactory.ts +15 -1
  37. package/appUtils/playerManager/playerNative.ts +40 -14
  38. package/appUtils/playerManager/usePlayerControllerSetup.tsx +7 -1
  39. package/appUtils/playerManager/usePlayerState.tsx +13 -1
  40. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +50 -0
  41. package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
  42. package/arrayUtils/index.ts +5 -0
  43. package/booleanUtils/index.ts +4 -4
  44. package/cellUtils/__tests__/cellUtils.test.ts +48 -0
  45. package/cellUtils/__tests__/fixtures.ts +13 -0
  46. package/cellUtils/index.ts +45 -7
  47. package/dateUtils/index.ts +11 -0
  48. package/focusManager/index.ts +1 -1
  49. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +2 -2
  50. package/functionUtils/__tests__/functionUtils.test.js +244 -248
  51. package/headersUtils/index.ts +1 -0
  52. package/index.d.ts +15 -0
  53. package/inflatedUrlUtils/index.ts +4 -4
  54. package/keyboardState/index.ts +0 -0
  55. package/localizationUtils/__tests__/localizationUtils.test.ts +78 -55
  56. package/localizationUtils/index.ts +13 -19
  57. package/logger/index.ts +1 -1
  58. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  59. package/manifestUtils/defaultManifestConfigurations/player.js +10 -1
  60. package/manifestUtils/index.js +5 -1
  61. package/manifestUtils/secondaryImage/index.js +18 -15
  62. package/modalState/index.ts +57 -0
  63. package/navigationUtils/index.ts +104 -7
  64. package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
  65. package/numberUtils/index.ts +9 -18
  66. package/package.json +3 -2
  67. package/playerUtils/configurationGenerator.ts +11 -1
  68. package/pluginUtils/index.ts +20 -7
  69. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
  70. package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
  71. package/reactHooks/cell-click/__tests__/index.test.js +16 -3
  72. package/reactHooks/cell-click/index.ts +14 -14
  73. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
  74. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
  75. package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
  76. package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
  77. package/reactHooks/feed/useFeedRefresh.tsx +9 -7
  78. package/reactHooks/feed/useInflatedUrl.ts +44 -15
  79. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +16 -9
  80. package/reactHooks/index.ts +2 -0
  81. package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +66 -59
  82. package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
  83. package/reactHooks/layout/types/index.ts +2 -0
  84. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +11 -16
  85. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +12 -14
  86. package/reactHooks/layout/useDimensions/useDimensions.ts +13 -7
  87. package/reactHooks/navigation/__mocks__/index.ts +15 -0
  88. package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
  89. package/reactHooks/navigation/__tests__/index.test.tsx +240 -81
  90. package/reactHooks/navigation/index.ts +239 -80
  91. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
  92. package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
  93. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
  94. package/reactHooks/screen/index.ts +4 -0
  95. package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
  96. package/reactHooks/screen/useScreenContext.ts +4 -4
  97. package/reactHooks/screen/useScreenData.ts +1 -1
  98. package/reactHooks/screen/useTargetScreenData.ts +7 -0
  99. package/reactHooks/state/useRivers.ts +3 -1
  100. package/reactHooks/useListenEventBusEvent.ts +1 -4
  101. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +10 -9
  102. package/reactUtils/index.ts +105 -0
  103. package/riverComponetsMeasurementProvider/index.tsx +2 -2
  104. package/stringUtils/index.ts +5 -0
  105. package/testUtils/getByTestId.ts +14 -0
  106. package/testUtils/index.tsx +38 -23
  107. package/types.ts +4 -0
  108. package/appUtils/focusManager/FocusableEvents.ts +0 -8
  109. package/appUtils/focusManager/treeDataStructure/Utils/__tests__/Utils_android.test.js +0 -1094
  110. package/appUtils/focusManager/treeDataStructure/Utils/index.android.js +0 -261
@@ -11,11 +11,9 @@ import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickB
11
11
  import { showConfirmationDialog } from "../alertUtils";
12
12
  import { createCloudEvent, sendCloudEvent } from "../cloudEventsUtils";
13
13
  import { createLogger } from "../logger";
14
- import {
15
- StorageMultiSelectProvider
16
- } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
14
+ import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
17
15
 
18
- const { log_error, log_debug, log_info } = createLogger({
16
+ const { log_error, log_info } = createLogger({
19
17
  subsystem: "ActionExecutorContext",
20
18
  category: "General",
21
19
  });
@@ -110,11 +108,17 @@ const prepareDefaultActions = (actionExecutor) => {
110
108
  const tag = entry?.extensions?.tag;
111
109
 
112
110
  if (keyNamespace && tag) {
113
- const multiSelectProvider = StorageMultiSelectProvider.getProvider(keyNamespace);
111
+ const multiSelectProvider =
112
+ StorageMultiSelectProvider.getProvider(keyNamespace);
114
113
 
115
114
  const selectedItems = await multiSelectProvider.getSelectedAsync();
116
115
  const isTagInSelectedItems = selectedItems.includes(tag);
117
- log_info(`handleAction: localStorageToggleFlag event will ${isTagInSelectedItems ? "remove" : "add"} tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`);
116
+
117
+ log_info(
118
+ `handleAction: localStorageToggleFlag event will ${
119
+ isTagInSelectedItems ? "remove" : "add"
120
+ } tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`
121
+ );
118
122
 
119
123
  if (selectedItems.includes(tag)) {
120
124
  await multiSelectProvider.removeItem(tag);
@@ -122,13 +126,17 @@ const prepareDefaultActions = (actionExecutor) => {
122
126
  await multiSelectProvider.addItem(tag);
123
127
  }
124
128
  } else {
125
- log_error("handleAction: localStorageToggleFlag event missing keyNamespace or tag", { keyNamespace, tag });
129
+ log_error(
130
+ "handleAction: localStorageToggleFlag event missing keyNamespace or tag",
131
+ { keyNamespace, tag }
132
+ );
126
133
 
127
134
  return ActionResult.Error;
128
135
  }
129
136
 
130
137
  return ActionResult.Success;
131
- });
138
+ }
139
+ );
132
140
  };
133
141
 
134
142
  export const ActionExecutorContext =
@@ -7,6 +7,15 @@ import { sendHeaderClickEvent } from "./sendHeaderClickEvent";
7
7
  import { sendHardwareBackButtonClickEvent } from "./sendHardwareBackButtonClickEvent";
8
8
  import { sendDownloadsEvent } from "./sendDownloadsEvent";
9
9
  import { sendScreenEvent } from "./sendScreenEvent";
10
+ import {
11
+ sendSearchCanceledEvent,
12
+ sendSearchExecutedEvent,
13
+ } from "./searchEvents";
14
+
15
+ import {
16
+ sendShareInitiatedEvent,
17
+ sendShareSuccessEvent,
18
+ } from "./sendShareEvent";
10
19
 
11
20
  export {
12
21
  sendScreenEvent,
@@ -18,4 +27,8 @@ export {
18
27
  sendHeaderClickEvent,
19
28
  sendHardwareBackButtonClickEvent,
20
29
  sendDownloadsEvent,
30
+ sendSearchCanceledEvent,
31
+ sendSearchExecutedEvent,
32
+ sendShareInitiatedEvent,
33
+ sendShareSuccessEvent,
21
34
  };
@@ -0,0 +1,21 @@
1
+ import { log_debug } from "../logger";
2
+ import { postAnalyticEvent } from "../manager";
3
+ import { ANALYTICS_CORE_EVENTS } from "../events";
4
+
5
+ export const sendSearchCanceledEvent = (analyticsProps) => {
6
+ const eventName = ANALYTICS_CORE_EVENTS.SEARCH_CANCELED;
7
+ postAnalyticEvent(eventName, analyticsProps);
8
+
9
+ log_debug(`sendSearchCanceledEvent: send event: ${eventName}`, {
10
+ analyticsProps,
11
+ });
12
+ };
13
+
14
+ export const sendSearchExecutedEvent = (analyticsProps) => {
15
+ const eventName = ANALYTICS_CORE_EVENTS.SEARCH_EXECUTED;
16
+ postAnalyticEvent(eventName, analyticsProps);
17
+
18
+ log_debug(`sendSearchExecutedEvent: send event: ${eventName}`, {
19
+ analyticsProps,
20
+ });
21
+ };
@@ -0,0 +1,21 @@
1
+ import { log_debug } from "../logger";
2
+ import { postAnalyticEvent } from "../manager";
3
+ import { ANALYTICS_CORE_EVENTS } from "../events";
4
+
5
+ export const sendShareInitiatedEvent = (analyticsProps) => {
6
+ const eventName = ANALYTICS_CORE_EVENTS.SHARE_INITIATED;
7
+ postAnalyticEvent(eventName, analyticsProps);
8
+
9
+ log_debug(`sendShareInitiatedEvent: send event: ${eventName}`, {
10
+ analyticsProps,
11
+ });
12
+ };
13
+
14
+ export const sendShareSuccessEvent = (analyticsProps) => {
15
+ const eventName = ANALYTICS_CORE_EVENTS.SHARE_SUCCESS;
16
+ postAnalyticEvent(eventName, analyticsProps);
17
+
18
+ log_debug(`sendShareSuccessEvent: send event: ${eventName}`, {
19
+ analyticsProps,
20
+ });
21
+ };
@@ -1,18 +1,18 @@
1
+ import * as ReactNative from "react-native";
2
+
1
3
  const mock_postEvent = jest.fn();
2
4
  const mock_setPlugins = jest.fn();
3
5
  const mock_postTimedEvent = jest.fn();
4
6
  const mock_endTimedEvent = jest.fn();
5
7
 
6
- jest.mock("react-native", () => ({
7
- NativeModules: {
8
- AnalyticsBridge: {
9
- postEvent: mock_postEvent,
10
- setPlugins: mock_setPlugins,
11
- postTimedEvent: mock_postTimedEvent,
12
- endTimedEvent: mock_endTimedEvent,
13
- },
14
- },
15
- }));
8
+ const AnalyticsBridge = {
9
+ postEvent: mock_postEvent,
10
+ setPlugins: mock_setPlugins,
11
+ postTimedEvent: mock_postTimedEvent,
12
+ endTimedEvent: mock_endTimedEvent,
13
+ };
14
+
15
+ ReactNative.NativeModules.AnalyticsBridge = AnalyticsBridge;
16
16
 
17
17
  const eventName = "event";
18
18
  const payload = {};
@@ -26,90 +26,92 @@ function clearAllMocks() {
26
26
  mock_endTimedEvent.mockClear();
27
27
  }
28
28
 
29
- describe("isValidAnalyticsData", () => {
30
- beforeEach(clearAllMocks);
29
+ describe("AnalyticsManager", () => {
30
+ describe("isValidAnalyticsData", () => {
31
+ beforeEach(clearAllMocks);
31
32
 
32
- it("returns false if eventName is not a string", () => {
33
- expect(analyticsManager.isValidAnalyticsData(42)).toBe(false);
34
- expect(analyticsManager.isValidAnalyticsData({})).toBe(false);
35
- expect(analyticsManager.isValidAnalyticsData([])).toBe(false);
36
- expect(analyticsManager.isValidAnalyticsData(() => ({}))).toBe(false);
37
- });
33
+ it("returns false if eventName is not a string", () => {
34
+ expect(analyticsManager.isValidAnalyticsData(42)).toBe(false);
35
+ expect(analyticsManager.isValidAnalyticsData({})).toBe(false);
36
+ expect(analyticsManager.isValidAnalyticsData([])).toBe(false);
37
+ expect(analyticsManager.isValidAnalyticsData(() => ({}))).toBe(false);
38
+ });
38
39
 
39
- it("returns false if payload is not an object", () => {
40
- expect(analyticsManager.isValidAnalyticsData(eventName, "string")).toBe(
41
- false
42
- );
40
+ it("returns false if payload is not an object", () => {
41
+ expect(analyticsManager.isValidAnalyticsData(eventName, "string")).toBe(
42
+ false
43
+ );
43
44
 
44
- expect(analyticsManager.isValidAnalyticsData(eventName, 42)).toBe(false);
45
+ expect(analyticsManager.isValidAnalyticsData(eventName, 42)).toBe(false);
45
46
 
46
- expect(analyticsManager.isValidAnalyticsData(eventName, () => ({}))).toBe(
47
- false
48
- );
49
- });
47
+ expect(analyticsManager.isValidAnalyticsData(eventName, () => ({}))).toBe(
48
+ false
49
+ );
50
+ });
50
51
 
51
- it("returns true if eventName is a string and payload is null or an object", () => {
52
- expect(analyticsManager.isValidAnalyticsData(eventName)).toBe(true);
52
+ it("returns true if eventName is a string and payload is null or an object", () => {
53
+ expect(analyticsManager.isValidAnalyticsData(eventName)).toBe(true);
53
54
 
54
- expect(analyticsManager.isValidAnalyticsData(eventName, payload)).toBe(
55
- true
56
- );
55
+ expect(analyticsManager.isValidAnalyticsData(eventName, payload)).toBe(
56
+ true
57
+ );
58
+ });
57
59
  });
58
- });
59
60
 
60
- describe("postAnalyticEvent", () => {
61
- beforeEach(clearAllMocks);
61
+ describe("postAnalyticEvent", () => {
62
+ beforeEach(clearAllMocks);
62
63
 
63
- it("calls the postEvent method of the analytic bridge", () => {
64
- analyticsManager.postAnalyticEvent(eventName, payload);
65
- expect(mock_postEvent).toHaveBeenCalledWith(eventName, payload);
66
- });
64
+ it("calls the postEvent method of the analytic bridge", () => {
65
+ analyticsManager.postAnalyticEvent(eventName, payload);
66
+ expect(mock_postEvent).toHaveBeenCalledWith(eventName, payload);
67
+ });
67
68
 
68
- it("skips the event if it is not valid", () => {
69
- analyticsManager.postAnalyticEvent(42);
70
- expect(mock_postTimedEvent).not.toHaveBeenCalled();
69
+ it("skips the event if it is not valid", () => {
70
+ analyticsManager.postAnalyticEvent(42);
71
+ expect(mock_postTimedEvent).not.toHaveBeenCalled();
72
+ });
71
73
  });
72
- });
73
74
 
74
- describe("providePlugins", () => {
75
- beforeEach(clearAllMocks);
75
+ describe("providePlugins", () => {
76
+ beforeEach(clearAllMocks);
76
77
 
77
- it("calls the setPlugins method of the analytic bridge", () => {
78
- const plugins = [];
79
- const plugin_configurations = {};
80
- const callback = jest.fn();
78
+ it("calls the setPlugins method of the analytic bridge", () => {
79
+ const plugins = [];
80
+ const plugin_configurations = {};
81
+ const callback = jest.fn();
81
82
 
82
- analyticsManager.providePlugins(plugins, plugin_configurations, callback);
83
+ analyticsManager.providePlugins(plugins, plugin_configurations, callback);
83
84
 
84
- expect(mock_setPlugins).toHaveBeenCalledWith(
85
- plugins,
86
- plugin_configurations,
87
- callback
88
- );
85
+ expect(mock_setPlugins).toHaveBeenCalledWith(
86
+ plugins,
87
+ plugin_configurations,
88
+ callback
89
+ );
90
+ });
89
91
  });
90
- });
91
92
 
92
- describe("startAnalyticsTimedEvent", () => {
93
- beforeEach(clearAllMocks);
93
+ describe("startAnalyticsTimedEvent", () => {
94
+ beforeEach(clearAllMocks);
94
95
 
95
- it("skips the event if it is not valid", () => {
96
- analyticsManager.startAnalyticsTimedEvent(42);
97
- expect(mock_postTimedEvent).not.toHaveBeenCalled();
96
+ it("skips the event if it is not valid", () => {
97
+ analyticsManager.startAnalyticsTimedEvent(42);
98
+ expect(mock_postTimedEvent).not.toHaveBeenCalled();
99
+ });
98
100
  });
99
- });
100
101
 
101
- describe("endAnalyticsTimedEvent", () => {
102
- beforeEach(clearAllMocks);
102
+ describe("endAnalyticsTimedEvent", () => {
103
+ beforeEach(clearAllMocks);
103
104
 
104
- it("emits a time_on_screen event and adds duration to payload", () => {
105
- analyticsManager.endAnalyticsTimedEvent(eventName, payload);
106
- const newEventName = "time_on_screen";
107
- payload.duration = "N/A";
108
- expect(mock_postEvent).toHaveBeenCalledWith(newEventName, payload);
109
- });
105
+ it("emits a time_on_screen event and adds duration to payload", () => {
106
+ analyticsManager.endAnalyticsTimedEvent(eventName, payload);
107
+ const newEventName = "time_on_screen";
108
+ payload.duration = "N/A";
109
+ expect(mock_postEvent).toHaveBeenCalledWith(newEventName, payload);
110
+ });
110
111
 
111
- it("skips the event if it is not valid", () => {
112
- analyticsManager.endAnalyticsTimedEvent(42);
113
- expect(mock_postEvent).not.toHaveBeenCalled();
112
+ it("skips the event if it is not valid", () => {
113
+ analyticsManager.endAnalyticsTimedEvent(42);
114
+ expect(mock_postEvent).not.toHaveBeenCalled();
115
+ });
114
116
  });
115
117
  });
@@ -0,0 +1,25 @@
1
+ import * as R from "ramda";
2
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
3
+
4
+ export const getVideojsAnalyticPluginsConfig = async (entry: ZappEntry) => {
5
+ let videojsConfiguration = {};
6
+
7
+ const plugins = appStore.get("plugins");
8
+ const analyticPlugins = R.filter(R.propEq("type", "analytics"), plugins);
9
+
10
+ const configurations = await Promise.all(
11
+ analyticPlugins.map(async (plugin) => {
12
+ const { configuration, module } = plugin;
13
+
14
+ return module?.getPlayerConfiguration?.(configuration, entry);
15
+ })
16
+ );
17
+
18
+ configurations.forEach((analyticConfig) => {
19
+ if (typeof analyticConfig === "object" && analyticConfig !== null) {
20
+ videojsConfiguration = { ...videojsConfiguration, ...analyticConfig };
21
+ }
22
+ });
23
+
24
+ return videojsConfiguration;
25
+ };
@@ -23,10 +23,22 @@ export const TAPPING_EVENTS = {
23
23
  TAP_NAVBAR_BACK_BUTTON: "tap_navbar_back_button",
24
24
  };
25
25
 
26
+ export const SEARCH_EVENTS = {
27
+ SEARCH_EXECUTED: "search_executed",
28
+ SEARCH_CANCELED: "search_canceled",
29
+ };
30
+
31
+ export const SHARE_EVENTS = {
32
+ SHARE_INITIATED: "share_initiated",
33
+ SHARE_SUCCESS: "share_success",
34
+ };
35
+
26
36
  export const ANALYTICS_CORE_EVENTS = {
27
37
  ...LEGACY_EVENTS,
28
38
  ...SCREEN_VIEW_EVENTS,
29
39
  ...TAPPING_EVENTS,
40
+ ...SEARCH_EVENTS,
41
+ ...SHARE_EVENTS,
30
42
  };
31
43
 
32
44
  export const WEBVIEW_EVENTS = {
@@ -26,7 +26,7 @@ export const useHookAnalytics = (props): void => {
26
26
  if (screenData?.hookPlugin?.module?.runInBackground) {
27
27
  sendScreenEvent({ analyticsScreenData });
28
28
  }
29
- }, [hookPlugin.screen_id]);
29
+ }, [sendScreenEvent, screenData, hookPlugin.screen_id]);
30
30
  };
31
31
 
32
32
  export const useScreenAnalytics = (props) => {
@@ -18,6 +18,10 @@ import {
18
18
  sendHardwareBackButtonClickEvent,
19
19
  sendDownloadsEvent,
20
20
  sendScreenEvent,
21
+ sendSearchCanceledEvent,
22
+ sendSearchExecutedEvent,
23
+ sendShareInitiatedEvent,
24
+ sendShareSuccessEvent,
21
25
  } from "./AnalyticsEvents";
22
26
 
23
27
  import { postAnalyticEvent } from "./manager";
@@ -66,6 +70,10 @@ type AnalyticsFunctions = {
66
70
  item: ZappEntry;
67
71
  state: OfflineItemState;
68
72
  }) => void;
73
+ sendSearchCanceledEvent: (props: AnalyticsDefaultProperties) => void;
74
+ sendSearchExecutedEvent: (props: AnalyticsDefaultProperties) => void;
75
+ sendShareInitiatedEvent: (props: AnalyticsDefaultProperties) => void;
76
+ sendShareSuccessEvent: (props: AnalyticsDefaultProperties) => void;
69
77
  };
70
78
 
71
79
  type GetAnalyticsFunctions = (
@@ -102,6 +110,10 @@ export function getAnalyticsFunctions({
102
110
  sendHardwareBackButtonClickEvent,
103
111
  sendScreenEvent,
104
112
  sendDownloadsEvent,
113
+ sendSearchCanceledEvent,
114
+ sendSearchExecutedEvent,
115
+ sendShareInitiatedEvent,
116
+ sendShareSuccessEvent,
105
117
  };
106
118
  }
107
119
 
@@ -270,7 +270,9 @@ export function HooksManager({
270
270
  });
271
271
 
272
272
  const isHookInHomescreen = payload?.home;
273
- const isHookFlowBlocker = hookPlugin?.module?.isFlowBlocker();
273
+
274
+ const isHookFlowBlocker =
275
+ hookPlugin?.module?.isFlowBlocker?.() ?? false;
274
276
 
275
277
  // TODO: We technically need to also support the case where there is more than one hook in the stack,
276
278
  // if needed we could add differentiation explicit user cancellation (when we should go to background) and other types of cancellation
@@ -0,0 +1,50 @@
1
+ export const BUTTON_ACCESSIBILITY_KEYS = {
2
+ play: {
3
+ label: "accessibility_play_label",
4
+ hint: "accessibility_play_hint",
5
+ mini: {
6
+ label: "accessibility_play_mini_label",
7
+ hint: "accessibility_play_mini_hint",
8
+ },
9
+ },
10
+ pause: {
11
+ label: "accessibility_pause_label",
12
+ hint: "accessibility_pause_hint",
13
+ mini: {
14
+ label: "accessibility_pause_mini_label",
15
+ hint: "accessibility_pause_mini_hint",
16
+ },
17
+ },
18
+ rewind: {
19
+ label: "accessibility_rewind_label",
20
+ hint: "accessibility_rewind_hint",
21
+ },
22
+ forward: {
23
+ label: "accessibility_forward_label",
24
+ hint: "accessibility_forward_hint",
25
+ },
26
+ close: {
27
+ label: "accessibility_close_label",
28
+ hint: "accessibility_close_hint",
29
+ mini: {
30
+ label: "accessibility_close_mini_label",
31
+ hint: "accessibility_close_mini_hint",
32
+ },
33
+ },
34
+ maximize: {
35
+ label: "accessibility_maximize_label",
36
+ hint: "accessibility_maximize_hint",
37
+ },
38
+ subtitles: {
39
+ label: "accessibility_subtitle_label",
40
+ hint: "accessibility_subtitle_hint",
41
+ },
42
+ back: {
43
+ label: "accessibility_back_label",
44
+ hint: "accessibility_back_hint",
45
+ },
46
+ fullscreen: {
47
+ label: "accessibility_fullscreen_label",
48
+ hint: "accessibility_fullscreen_hint",
49
+ },
50
+ } as const;
@@ -0,0 +1,40 @@
1
+ import { useEffect, useMemo } from "react";
2
+ import { AccessibilityManager } from "./index";
3
+
4
+ /**
5
+ * This hook is used to instantiate the accessibility manager and update localizations used by the class.
6
+ * If the plugin config is not provided or it does not contain any localizations, the accessibility manager will not be updated.
7
+ * We use the plugin configuration because it offers a flattened structure where we can easily access the accessibility labels and hints
8
+ * i.e. pluginConfiguration = {
9
+ * accessibility_close_label: "Close",
10
+ * accessibility_close_hint: "Press here to close",
11
+ * }
12
+ */
13
+ export const useAccessibilityManager = (
14
+ pluginConfiguration: Record<string, any> = {}
15
+ ) => {
16
+ const accessibilityManager = useMemo(() => {
17
+ return AccessibilityManager.getInstance();
18
+ }, []);
19
+
20
+ useEffect(() => {
21
+ if (pluginConfiguration) {
22
+ accessibilityManager.updateLocalizations(pluginConfiguration);
23
+ }
24
+ }, [pluginConfiguration, accessibilityManager]);
25
+
26
+ useEffect(() => {
27
+ const subscription = accessibilityManager.getStateAsObservable().subscribe({
28
+ next: () => {
29
+ // TODO: handle accessibility states
30
+ // screenReaderEnabled: false
31
+ // reduceMotionEnabled: false
32
+ // boldTextEnabled: false
33
+ },
34
+ });
35
+
36
+ return () => subscription.unsubscribe();
37
+ }, [accessibilityManager]);
38
+
39
+ return accessibilityManager;
40
+ };
@@ -0,0 +1,155 @@
1
+ import { BehaviorSubject } from "rxjs";
2
+ import { accessibilityManagerLogger as logger } from "./logger";
3
+ import { TTSManager } from "../platform/platformUtils";
4
+ import { BUTTON_ACCESSIBILITY_KEYS } from "./const";
5
+ import { AccessibilityRole } from "react-native";
6
+
7
+ export class AccessibilityManager {
8
+ private static _instance: AccessibilityManager | null = null;
9
+ private state$ = new BehaviorSubject<AccessibilityState>({
10
+ screenReaderEnabled: false,
11
+ reduceMotionEnabled: false,
12
+ boldTextEnabled: false,
13
+ });
14
+
15
+ private announcements$ = new BehaviorSubject<{
16
+ message: string;
17
+ localizedMessage?: string | undefined;
18
+ timestamp: number;
19
+ } | null>(null);
20
+
21
+ private ttsManager = TTSManager.getInstance();
22
+ private localizations: { [key: string]: string } = {};
23
+
24
+ private constructor() {}
25
+
26
+ public static getInstance(): AccessibilityManager {
27
+ if (!AccessibilityManager._instance) {
28
+ AccessibilityManager._instance = new AccessibilityManager();
29
+ }
30
+
31
+ return AccessibilityManager._instance;
32
+ }
33
+
34
+ /**
35
+ * The method now accepts any object with localizations using a flattened structure
36
+ *
37
+ * i.e. { accessibility_close_label: "Close", accessibility_close_hint: "Press here to close" }
38
+ *
39
+ * No longer accepts:
40
+ *
41
+ * i.e. localizations: [{ en: { accessibility_close_label: "Close", accessibility_close_hint: "Press here to close" } }]
42
+ */
43
+ public updateLocalizations(localizations: { [key: string]: string }) {
44
+ this.localizations = localizations;
45
+ }
46
+
47
+ public getState(): AccessibilityState {
48
+ return this.state$.getValue();
49
+ }
50
+
51
+ public getStateAsObservable() {
52
+ return this.state$.asObservable();
53
+ }
54
+
55
+ /**
56
+ * text you want to be read, if you want to use localized text pass keyOfLocalizedText instead
57
+ * keyOfLocalizedText is the key to the localized text
58
+ */
59
+ public readText({
60
+ text,
61
+ keyOfLocalizedText,
62
+ }: {
63
+ text: string;
64
+ keyOfLocalizedText?: string;
65
+ }) {
66
+ let textToRead = text;
67
+
68
+ if (keyOfLocalizedText) {
69
+ if (!this.localizations) {
70
+ logger.error(
71
+ "Attempting to use localized key without initialized localizations"
72
+ );
73
+
74
+ return;
75
+ }
76
+
77
+ const localizedMessage = this.getLocalizedMessage(keyOfLocalizedText);
78
+
79
+ if (!localizedMessage) {
80
+ logger.warn(`No localization found for key: ${keyOfLocalizedText}`);
81
+
82
+ return;
83
+ }
84
+
85
+ textToRead = localizedMessage;
86
+ }
87
+
88
+ if (this.ttsManager) {
89
+ logger.debug({
90
+ message: `Reading text: ${textToRead}`,
91
+ data: {
92
+ textToRead,
93
+ text,
94
+ keyOfLocalizedText,
95
+ },
96
+ });
97
+
98
+ this.ttsManager.readText(textToRead);
99
+ }
100
+
101
+ this.announcements$.next({
102
+ message: textToRead,
103
+ localizedMessage: keyOfLocalizedText ? textToRead : undefined,
104
+ timestamp: Date.now(),
105
+ });
106
+ }
107
+
108
+ public getButtonAccessibilityProps(buttonName: string): AccessibilityProps {
109
+ const buttonConfig = BUTTON_ACCESSIBILITY_KEYS[buttonName];
110
+
111
+ if (!buttonConfig) {
112
+ return {
113
+ accessibilityLabel: buttonName,
114
+ accessibilityHint: `Press button to perform action on ${buttonName}`,
115
+ "aria-label": buttonName,
116
+ "aria-description": `Press button to perform action on ${buttonName}`,
117
+ accessibilityRole: "button" as AccessibilityRole,
118
+ "aria-role": "button",
119
+ };
120
+ }
121
+
122
+ const labelKey = buttonConfig.label;
123
+ const hintKey = buttonConfig.hint;
124
+
125
+ const label = this.getLocalizedMessage(labelKey) || buttonName;
126
+
127
+ const hint =
128
+ this.getLocalizedMessage(hintKey) ||
129
+ `Press button to perform action on ${buttonName}`;
130
+
131
+ return {
132
+ accessibilityLabel: label,
133
+ accessibilityHint: hint,
134
+ "aria-label": label,
135
+ "aria-description": hint,
136
+ accessibilityRole: "button" as AccessibilityRole,
137
+ "aria-role": "button",
138
+ };
139
+ }
140
+
141
+ public getLocalizedMessage(key: string): string | void {
142
+ if (!key) return;
143
+
144
+ if (!this.localizations) {
145
+ logger.error(
146
+ "Attempting to use localized key without initialized localizations",
147
+ { key }
148
+ );
149
+
150
+ return;
151
+ }
152
+
153
+ return this.localizations[key];
154
+ }
155
+ }
@@ -0,0 +1,5 @@
1
+ import { utilsLogger } from "../../logger";
2
+
3
+ export const accessibilityManagerLogger = utilsLogger.addSubsystem(
4
+ "accessibilityManager"
5
+ );