@applicaster/zapp-react-native-utils 13.0.9-alpha.1792119437 → 13.0.9-alpha.8722424302

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 (32) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +60 -84
  2. package/actionsExecutor/ScreenActions.ts +164 -0
  3. package/actionsExecutor/StorageActions.ts +110 -0
  4. package/actionsExecutor/feedDecorator.ts +171 -0
  5. package/actionsExecutor/screenResolver.ts +11 -0
  6. package/appUtils/HooksManager/Hook.ts +4 -4
  7. package/appUtils/HooksManager/index.ts +11 -1
  8. package/appUtils/accessibilityManager/const.ts +0 -13
  9. package/appUtils/accessibilityManager/hooks.ts +1 -35
  10. package/appUtils/accessibilityManager/index.ts +28 -149
  11. package/appUtils/contextKeysManager/contextResolver.ts +42 -1
  12. package/appUtils/platform/platformUtils.ts +1 -31
  13. package/index.d.ts +0 -3
  14. package/package.json +2 -2
  15. package/reactHooks/cell-click/__tests__/index.test.js +3 -0
  16. package/reactHooks/cell-click/index.ts +8 -1
  17. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +3 -0
  18. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +71 -31
  19. package/reactHooks/feed/index.ts +2 -0
  20. package/reactHooks/feed/useBatchLoading.ts +13 -6
  21. package/reactHooks/feed/useFeedLoader.tsx +35 -33
  22. package/reactHooks/feed/useLoadPipesDataDispatch.ts +55 -0
  23. package/reactHooks/navigation/useRoute.ts +7 -2
  24. package/reactHooks/navigation/useScreenStateStore.ts +8 -0
  25. package/storage/ScreenSingleValueProvider.ts +208 -0
  26. package/storage/ScreenStateMultiSelectProvider.ts +293 -0
  27. package/storage/StorageMultiSelectProvider.ts +192 -0
  28. package/storage/StorageSingleSelectProvider.ts +108 -0
  29. package/appUtils/accessibilityManager/utils.ts +0 -24
  30. package/playerUtils/PlayerTTS/PlayerTTS.ts +0 -359
  31. package/playerUtils/PlayerTTS/index.ts +0 -1
  32. package/playerUtils/usePlayerTTS.ts +0 -21
@@ -65,17 +65,4 @@ export const BUTTON_ACCESSIBILITY_KEYS = {
65
65
  label: "accessibility_menu_item_label",
66
66
  hint: "accessibility_menu_item_hint",
67
67
  },
68
- skip_intro: {
69
- label: "accessibility_skip_intro_label",
70
- hint: "accessibility_skip_intro_hint",
71
- },
72
- // Top Menu Bar-specific buttons
73
- top_menu_bar_item_selected: {
74
- label: "accessibility_top_menu_bar_item_selected_label",
75
- hint: "accessibility_top_menu_bar_item_selected_hint",
76
- },
77
- top_menu_title: {
78
- label: "accessibility_top_menu_title_label",
79
- hint: "accessibility_top_menu_hint",
80
- },
81
68
  } as const;
@@ -1,4 +1,4 @@
1
- import { useEffect, useMemo, useState } from "react";
1
+ import { useEffect, useMemo } from "react";
2
2
  import { AccessibilityManager } from "./index";
3
3
 
4
4
  /**
@@ -38,37 +38,3 @@ export const useAccessibilityManager = (
38
38
 
39
39
  return accessibilityManager;
40
40
  };
41
-
42
- export const useInitialAnnouncementReady = (
43
- accessibilityManager: AccessibilityManager
44
- ) => {
45
- const [isReady, setIsReady] = useState(
46
- accessibilityManager.isInitialPlayerAnnouncementReady
47
- );
48
-
49
- useEffect(() => {
50
- const subscription = accessibilityManager
51
- .getInitialAnnouncementReadyObservable()
52
- .subscribe(setIsReady);
53
-
54
- return () => subscription.unsubscribe();
55
- }, [accessibilityManager]);
56
-
57
- return isReady;
58
- };
59
-
60
- export const useAnnouncementActive = (
61
- accessibilityManager: AccessibilityManager
62
- ) => {
63
- const [isActive, setIsActive] = useState(false);
64
-
65
- useEffect(() => {
66
- const subscription = accessibilityManager
67
- .getTTSStateObservable()
68
- .subscribe(setIsActive);
69
-
70
- return () => subscription.unsubscribe();
71
- }, [accessibilityManager]);
72
-
73
- return isActive;
74
- };
@@ -1,19 +1,15 @@
1
- import * as R from "ramda";
2
1
  import { BehaviorSubject } from "rxjs";
3
2
  import { accessibilityManagerLogger as logger } from "./logger";
4
3
  import { TTSManager } from "../platform/platformUtils";
5
4
  import { BUTTON_ACCESSIBILITY_KEYS } from "./const";
6
- import { calculateReadingTime } from "./utils";
7
5
  import { AccessibilityRole } from "react-native";
8
6
  import _ from "lodash";
9
7
 
10
8
  export class AccessibilityManager {
11
9
  private static _instance: AccessibilityManager | null = null;
12
10
  private headingTimeout: NodeJS.Timeout | null = null;
13
- private announcementDelayTimeout: NodeJS.Timeout | null = null;
14
- private WORDS_PER_MINUTE = 140;
11
+ private WORDS_PER_MINUTE = 160;
15
12
  private MINIMUM_PAUSE = 500;
16
- private ANNOUNCEMENT_DELAY = 700;
17
13
  private state$ = new BehaviorSubject<AccessibilityState>({
18
14
  screenReaderEnabled: false,
19
15
  reduceMotionEnabled: false,
@@ -29,12 +25,6 @@ export class AccessibilityManager {
29
25
  private ttsManager = TTSManager.getInstance();
30
26
  private localizations: { [key: string]: string } = {};
31
27
  private headingQueue: string[] = [];
32
- private currentFocusId: string | null = null;
33
- private headingFocusMap: Map<string, string> = new Map();
34
- private pendingFocusId: string | null = null;
35
- private isInitialPlayerAnnouncementReady$ = new BehaviorSubject<boolean>(
36
- false
37
- );
38
28
 
39
29
  private constructor() {}
40
30
 
@@ -46,26 +36,6 @@ export class AccessibilityManager {
46
36
  return AccessibilityManager._instance;
47
37
  }
48
38
 
49
- public get isInitialPlayerAnnouncementReady(): boolean {
50
- return this.isInitialPlayerAnnouncementReady$.getValue();
51
- }
52
-
53
- public setInitialPlayerAnnouncementReady(): void {
54
- this.isInitialPlayerAnnouncementReady$.next(true);
55
- }
56
-
57
- public resetInitialPlayerAnnouncementReady(): void {
58
- this.isInitialPlayerAnnouncementReady$.next(false);
59
- }
60
-
61
- public getInitialAnnouncementReadyObservable() {
62
- return this.isInitialPlayerAnnouncementReady$.asObservable();
63
- }
64
-
65
- public getTTSStateObservable() {
66
- return this.ttsManager.getStateAsObservable();
67
- }
68
-
69
39
  /**
70
40
  * The method now accepts any object with localizations using a flattened structure
71
41
  *
@@ -76,9 +46,7 @@ export class AccessibilityManager {
76
46
  * i.e. localizations: [{ en: { accessibility_close_label: "Close", accessibility_close_hint: "Press here to close" } }]
77
47
  */
78
48
  public updateLocalizations(localizations: { [key: string]: string }) {
79
- if (!R.isEmpty(localizations)) {
80
- this.localizations = localizations;
81
- }
49
+ this.localizations = localizations;
82
50
  }
83
51
 
84
52
  public getState(): AccessibilityState {
@@ -89,25 +57,31 @@ export class AccessibilityManager {
89
57
  return this.state$.asObservable();
90
58
  }
91
59
 
60
+ /** Calculates the reading time for a given text
61
+ * This method is a bit of a hack because we don't have a callback, or promise from VIZIO API
62
+ * @param text - The text to calculate the reading time for
63
+ * @returns The reading time in milliseconds
64
+ */
65
+ private calculateReadingTime(text: string): number {
66
+ const words = text.trim().split(/\s+/).length;
67
+
68
+ return Math.max(
69
+ this.MINIMUM_PAUSE,
70
+ (words / this.WORDS_PER_MINUTE) * 60 * 1000
71
+ );
72
+ }
73
+
92
74
  /**
93
75
  * Adds a heading to the queue, headings will be read before the next text
94
76
  * Each heading will be read once and removed from the queue
95
77
  */
96
78
  public addHeading(heading: string) {
97
- if (!this.pendingFocusId) {
98
- this.pendingFocusId = Date.now().toString();
99
- }
100
-
101
- this.headingFocusMap.set(heading, this.pendingFocusId);
102
79
  this.headingQueue.push(heading);
103
80
  }
104
81
 
105
82
  /**
106
83
  * text you want to be read, if you want to use localized text pass keyOfLocalizedText instead
107
84
  * keyOfLocalizedText is the key to the localized text
108
- *
109
- * Implements a delay mechanism to reduce noise during rapid navigation.
110
- * Only the most recent announcement will be read after the delay period.
111
85
  */
112
86
  public readText({
113
87
  text,
@@ -138,27 +112,19 @@ export class AccessibilityManager {
138
112
  textToRead = localizedMessage;
139
113
  }
140
114
 
141
- const focusId = this.pendingFocusId || Date.now().toString();
142
- this.currentFocusId = focusId;
143
- this.pendingFocusId = null;
115
+ if (this.headingQueue.length > 0) {
116
+ const heading = this.headingQueue.shift()!;
117
+ this.ttsManager?.readText(heading);
144
118
 
145
- this.clearAnnouncement();
119
+ if (this.headingTimeout) {
120
+ clearTimeout(this.headingTimeout);
121
+ }
146
122
 
147
- this.announcementDelayTimeout = setTimeout(() => {
148
- this.executeAnnouncement(textToRead, keyOfLocalizedText, focusId);
149
- }, this.ANNOUNCEMENT_DELAY);
150
- }
123
+ const pauseTime = this.calculateReadingTime(heading);
151
124
 
152
- /**
153
- * Internal method to execute the actual announcement after the delay
154
- */
155
- private executeAnnouncement(
156
- textToRead: string,
157
- keyOfLocalizedText?: string,
158
- focusId?: string
159
- ) {
160
- if (this.headingQueue.length > 0) {
161
- this.processHeadingQueue(textToRead, focusId);
125
+ this.headingTimeout = setTimeout(() => {
126
+ this.ttsManager?.readText(textToRead);
127
+ }, pauseTime);
162
128
  } else {
163
129
  this.ttsManager?.readText(textToRead);
164
130
  }
@@ -170,54 +136,6 @@ export class AccessibilityManager {
170
136
  });
171
137
  }
172
138
 
173
- /**
174
- * Recursively processes all headings in the queue, reading them one by one
175
- */
176
- private processHeadingQueue(textToRead: string, focusId?: string) {
177
- // If focus has changed, abort this announcement
178
- if (focusId && this.currentFocusId !== focusId) {
179
- return;
180
- }
181
-
182
- if (this.headingQueue.length === 0) {
183
- if (focusId && this.currentFocusId === focusId) {
184
- this.ttsManager?.readText(textToRead);
185
- }
186
-
187
- return;
188
- }
189
-
190
- const heading = this.headingQueue.shift()!;
191
-
192
- const headingFocusId = this.headingFocusMap.get(heading);
193
-
194
- if (headingFocusId && headingFocusId !== focusId) {
195
- // This heading belongs to a previous focus, skip it
196
- this.headingFocusMap.delete(heading);
197
- this.processHeadingQueue(textToRead, focusId);
198
-
199
- return;
200
- }
201
-
202
- this.ttsManager?.readText(heading);
203
- this.headingFocusMap.delete(heading); // Clean up after reading
204
-
205
- if (this.headingTimeout) {
206
- clearTimeout(this.headingTimeout);
207
- }
208
-
209
- const pauseTime = calculateReadingTime(
210
- heading,
211
- this.WORDS_PER_MINUTE,
212
- this.MINIMUM_PAUSE,
213
- this.ANNOUNCEMENT_DELAY
214
- );
215
-
216
- this.headingTimeout = setTimeout(() => {
217
- this.processHeadingQueue(textToRead, focusId);
218
- }, pauseTime);
219
- }
220
-
221
139
  public getButtonAccessibilityProps(name: string): AccessibilityProps {
222
140
  const buttonName = _.toString(name);
223
141
 
@@ -225,15 +143,12 @@ export class AccessibilityManager {
225
143
 
226
144
  if (!buttonConfig) {
227
145
  return {
228
- accessible: true,
229
146
  accessibilityLabel: buttonName,
230
147
  accessibilityHint: `Press button to perform action on ${buttonName}`,
231
148
  "aria-label": buttonName,
232
149
  "aria-description": `Press button to perform action on ${buttonName}`,
233
150
  accessibilityRole: "button" as AccessibilityRole,
234
151
  "aria-role": "button",
235
- role: "button",
236
- tabindex: 0,
237
152
  };
238
153
  }
239
154
 
@@ -247,52 +162,23 @@ export class AccessibilityManager {
247
162
  `Press button to perform action on ${buttonName}`;
248
163
 
249
164
  return {
250
- accessible: true,
251
165
  accessibilityLabel: label,
252
166
  accessibilityHint: hint,
253
167
  "aria-label": label,
254
168
  "aria-description": hint,
255
169
  accessibilityRole: "button" as AccessibilityRole,
256
170
  "aria-role": "button",
257
- role: "button",
258
- tabindex: 0,
259
171
  };
260
172
  }
261
173
 
262
174
  public getInputAccessibilityProps(inputName: string): AccessibilityProps {
263
175
  return {
264
- accessible: true,
265
176
  accessibilityLabel: inputName,
266
177
  accessibilityHint: `Enter text into ${inputName}`,
267
178
  "aria-label": inputName,
268
179
  "aria-description": `Enter text into ${inputName}`,
269
- accessibilityRole: "text" as AccessibilityRole,
270
- "aria-role": "text",
271
- role: "text",
272
- tabindex: 0,
273
- };
274
- }
275
-
276
- /**
277
- * Extracts accessibility props from component props and returns them as HTML attributes
278
- * @param props - Component props containing accessibility properties
279
- * @returns Object with accessibility HTML attributes
280
- */
281
- public getWebAccessibilityProps(props: any): AccessibilityProps {
282
- const {
283
- "aria-label": ariaLabel,
284
- "aria-description": ariaDescription,
285
- "aria-role": ariaRole,
286
- role,
287
- tabindex,
288
- } = props;
289
-
290
- return {
291
- "aria-label": ariaLabel,
292
- "aria-description": ariaDescription,
293
- "aria-role": ariaRole,
294
- role: role || ariaRole,
295
- tabindex,
180
+ accessibilityRole: "textbox" as AccessibilityRole,
181
+ "aria-role": "textbox",
296
182
  };
297
183
  }
298
184
 
@@ -310,11 +196,4 @@ export class AccessibilityManager {
310
196
 
311
197
  return this.localizations[key];
312
198
  }
313
-
314
- private clearAnnouncement() {
315
- if (this.announcementDelayTimeout) {
316
- clearTimeout(this.announcementDelayTimeout);
317
- this.announcementDelayTimeout = null;
318
- }
319
- }
320
199
  }
@@ -1,10 +1,13 @@
1
1
  import { ContextKeysManager } from "./index";
2
2
  import * as R from "ramda";
3
+ import * as _ from "lodash";
4
+ import { useScreenStateStore } from "../../reactHooks/navigation/useScreenStateStore";
3
5
 
4
- interface IResolver {
6
+ export interface IResolver {
5
7
  resolve: (string) => Promise<string | number | object>;
6
8
  }
7
9
 
10
+ // TODO: Rename to ObjectKeyResolver or similar
8
11
  export class EntryResolver implements IResolver {
9
12
  entry: ZappEntry;
10
13
 
@@ -21,6 +24,28 @@ export class EntryResolver implements IResolver {
21
24
  }
22
25
  }
23
26
 
27
+ // TODO: Move to proper place
28
+
29
+ export class ScreenStateResolver implements IResolver {
30
+ constructor(
31
+ private screenStateStore: ReturnType<typeof useScreenStateStore>
32
+ ) {}
33
+
34
+ async resolve(key: string) {
35
+ const screenState = this.screenStateStore.getState().data;
36
+
37
+ if (!key || key.length === 0) {
38
+ return screenState;
39
+ }
40
+
41
+ if (key.includes(".")) {
42
+ return R.view(R.lensPath(key.split(".")), screenState);
43
+ }
44
+
45
+ return screenState?.[key];
46
+ }
47
+ }
48
+
24
49
  export class ContextResolver implements IResolver {
25
50
  resolve = async (compositeKey: string) =>
26
51
  ContextKeysManager.instance.getKey(compositeKey);
@@ -64,3 +89,19 @@ export const resolveObjectValues = async (
64
89
 
65
90
  return Object.fromEntries(resolvedEntries);
66
91
  };
92
+
93
+ export const extractAtValues = _.memoize((input: any): string[] => {
94
+ return _.flatMapDeep(input, (value: any) => {
95
+ if (_.isString(value)) {
96
+ const matches = value.match(/@\{([^}]*)\}/g);
97
+
98
+ return matches ? matches.map((match) => match.slice(2, -1)) : [];
99
+ }
100
+
101
+ if (_.isObject(value)) {
102
+ return extractAtValues(_.values(value));
103
+ }
104
+
105
+ return [];
106
+ });
107
+ });
@@ -10,7 +10,6 @@ import { PLATFORM_KEYS, PLATFORMS, ZappPlatform } from "./const";
10
10
  import { createLogger, utilsLogger } from "../../logger";
11
11
  import { getPlatform } from "../../reactUtils";
12
12
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
13
- import { calculateReadingTime } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager/utils";
14
13
 
15
14
  const { log_debug } = createLogger({
16
15
  category: "General",
@@ -213,16 +212,9 @@ export class TTSManager {
213
212
  }
214
213
 
215
214
  readText(text: string) {
216
- this.ttsState$.next(true);
217
-
218
215
  if (isSamsungPlatform() && window.speechSynthesis) {
219
216
  const utterance = new SpeechSynthesisUtterance(text);
220
-
221
- window.speechSynthesis.cancel(); // Cancel previous speech before speaking new text
222
217
  window.speechSynthesis.speak(utterance);
223
-
224
- // Estimate reading time and set inactive when done
225
- this.scheduleTTSComplete(text);
226
218
  }
227
219
 
228
220
  if (isLgPlatform() && window.webOS?.service) {
@@ -233,45 +225,23 @@ export class TTSManager {
233
225
  log_debug("There was a failure setting up webOS TTS service", {
234
226
  error,
235
227
  });
236
-
237
- this.ttsState$.next(false);
238
228
  },
239
229
  onSuccess(response: any) {
240
230
  log_debug("webOS TTS service is configured successfully", {
241
231
  response,
242
232
  });
243
-
244
- // Estimate reading time and set inactive when done
245
- this.scheduleTTSComplete(text);
246
233
  },
247
234
  parameters: {
248
235
  text,
249
- clear: true, // Clear any previous speech before speaking new text
250
236
  },
251
237
  });
252
238
  } catch (error) {
253
239
  log_debug("webOS TTS service error", { error });
254
- this.ttsState$.next(false);
255
240
  }
256
241
  }
257
242
 
258
- if (!window.VIZIO?.Chromevox) {
259
- // For platforms without TTS, estimate reading time
260
- this.scheduleTTSComplete(text);
261
-
262
- return;
263
- }
243
+ if (!window.VIZIO?.Chromevox) return;
264
244
 
265
245
  window.VIZIO.Chromevox.play(text);
266
- // Estimate reading time and set inactive when done
267
- this.scheduleTTSComplete(text);
268
- }
269
-
270
- private scheduleTTSComplete(text: string) {
271
- const readingTime = calculateReadingTime(text);
272
-
273
- setTimeout(() => {
274
- this.ttsState$.next(false);
275
- }, readingTime);
276
246
  }
277
247
  }
package/index.d.ts CHANGED
@@ -139,13 +139,10 @@ declare type AccessibilityState = {
139
139
  };
140
140
 
141
141
  declare type AccessibilityProps = {
142
- accessible?: boolean;
143
142
  accessibilityLabel?: string;
144
143
  accessibilityHint?: string;
145
144
  "aria-label"?: string;
146
145
  "aria-description"?: string;
147
146
  accessibilityRole?: string;
148
147
  "aria-role"?: string;
149
- role?: string;
150
- tabindex?: number;
151
148
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "13.0.9-alpha.1792119437",
3
+ "version": "13.0.9-alpha.8722424302",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "13.0.9-alpha.1792119437",
30
+ "@applicaster/applicaster-types": "13.0.9-alpha.8722424302",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -26,6 +26,9 @@ jest.mock("@applicaster/zapp-react-native-utils/analyticsUtils/", () => ({
26
26
  }));
27
27
 
28
28
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
29
+ ...jest.requireActual(
30
+ "@applicaster/zapp-react-native-utils/reactHooks/screen"
31
+ ),
29
32
  useTargetScreenData: jest.fn(() => ({})),
30
33
  useCurrentScreenData: jest.fn(() => ({})),
31
34
  }));
@@ -16,7 +16,8 @@ import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/acti
16
16
  import { isFunction, noop } from "../../functionUtils";
17
17
  import { useSendAnalyticsOnPress } from "../analytics";
18
18
  import { logOnPress, warnEmptyContentType } from "./helpers";
19
- import { useCurrentScreenData } from "../screen";
19
+ import { useCurrentScreenData, useScreenContext } from "../screen";
20
+ import { useScreenStateStore } from "../navigation/useScreenStateStore";
20
21
 
21
22
  /**
22
23
  * If onCellTap is defined execute the function and
@@ -42,10 +43,12 @@ export const useCellClick = ({
42
43
  }: Props): onPressReturnFn => {
43
44
  const { push, currentRoute } = useNavigation();
44
45
  const { pathname } = useRoute();
46
+ const screenStateStore = useScreenStateStore();
45
47
 
46
48
  const onCellTap: Option<Function> = React.useContext(CellTapContext);
47
49
  const actionExecutor = React.useContext(ActionExecutorContext);
48
50
  const screenData = useCurrentScreenData();
51
+ const screenState = useScreenContext()?.options;
49
52
 
50
53
  const cellSelectable = toBooleanWithDefaultTrue(
51
54
  component?.rules?.component_cells_selectable
@@ -83,6 +86,9 @@ export const useCellClick = ({
83
86
  await actionExecutor?.handleEntryActions(selectedItem, {
84
87
  component,
85
88
  screenData,
89
+ screenState,
90
+ screenRoute: pathname,
91
+ screenStateStore,
86
92
  });
87
93
  }
88
94
 
@@ -117,6 +123,7 @@ export const useCellClick = ({
117
123
  push,
118
124
  sendAnalyticsOnPress,
119
125
  screenData,
126
+ screenState,
120
127
  ]
121
128
  );
122
129
 
@@ -9,6 +9,9 @@ jest.mock("../../navigation");
9
9
  jest.mock(
10
10
  "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext",
11
11
  () => ({
12
+ ...jest.requireActual(
13
+ "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext"
14
+ ),
12
15
  useScreenContext: jest.fn().mockReturnValue({ screen: {}, entry: {} }),
13
16
  })
14
17
  );