@applicaster/zapp-react-native-utils 14.0.0-alpha.3514550494 → 14.0.0-alpha.3652810444
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.
- package/analyticsUtils/playerAnalyticsTracker.ts +2 -1
- package/appUtils/accessibilityManager/const.ts +0 -13
- package/appUtils/accessibilityManager/hooks.ts +1 -35
- package/appUtils/accessibilityManager/index.ts +30 -151
- package/appUtils/focusManager/events.ts +2 -0
- package/appUtils/platform/platformUtils.ts +1 -31
- package/focusManager/FocusManager.ts +63 -4
- package/focusManager/aux/index.ts +167 -0
- package/focusManager/utils.ts +12 -6
- package/manifestUtils/defaultManifestConfigurations/player.js +2 -16
- package/navigationUtils/index.ts +1 -1
- package/package.json +2 -2
- package/playerUtils/getPlayerActionButtons.ts +1 -1
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +7 -1
- package/screenPickerUtils/index.ts +6 -0
- package/utils/__tests__/endsWith.test.ts +30 -0
- package/utils/__tests__/equals.test.ts +65 -0
- package/utils/__tests__/max.test.ts +36 -0
- package/utils/__tests__/omit.test.ts +19 -0
- package/utils/__tests__/path.test.ts +33 -0
- package/utils/__tests__/take.test.ts +40 -0
- package/utils/__tests__/toLower.test.ts +39 -0
- package/utils/endsWith.ts +9 -0
- package/utils/equals.ts +5 -0
- package/utils/index.ts +14 -1
- package/utils/max.ts +5 -0
- package/utils/omit.ts +5 -0
- package/utils/path.ts +5 -0
- package/utils/take.ts +5 -0
- package/utils/toLower.ts +5 -0
- package/appUtils/accessibilityManager/utils.ts +0 -24
- package/playerUtils/PlayerTTS/PlayerTTS.ts +0 -359
- package/playerUtils/PlayerTTS/index.ts +0 -1
- package/playerUtils/usePlayerTTS.ts +0 -21
|
@@ -105,7 +105,8 @@ export class PlayerAnalyticsTracker implements PlayerAnalyticsTrackerI {
|
|
|
105
105
|
return this.getDateTimestamp();
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
this.mediaTime =
|
|
108
|
+
this.mediaTime =
|
|
109
|
+
this.playerState?.contentPosition || eventData?.currentTime;
|
|
109
110
|
|
|
110
111
|
return this.mediaTime;
|
|
111
112
|
}
|
|
@@ -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
|
|
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";
|
|
5
4
|
import { BUTTON_ACCESSIBILITY_KEYS } from "./const";
|
|
6
5
|
import { toString } from "../../utils";
|
|
7
|
-
import { calculateReadingTime } from "./utils";
|
|
8
6
|
import { AccessibilityRole } from "react-native";
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
115
|
+
if (this.headingQueue.length > 0) {
|
|
116
|
+
const heading = this.headingQueue.shift()!;
|
|
117
|
+
this.ttsManager?.readText(heading);
|
|
144
118
|
|
|
145
|
-
|
|
119
|
+
if (this.headingTimeout) {
|
|
120
|
+
clearTimeout(this.headingTimeout);
|
|
121
|
+
}
|
|
146
122
|
|
|
147
|
-
|
|
148
|
-
this.executeAnnouncement(textToRead, keyOfLocalizedText, focusId);
|
|
149
|
-
}, this.ANNOUNCEMENT_DELAY);
|
|
150
|
-
}
|
|
123
|
+
const pauseTime = this.calculateReadingTime(heading);
|
|
151
124
|
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
accessibilityRole: "button"
|
|
150
|
+
accessibilityRole: "button",
|
|
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
|
-
accessibilityRole: "button"
|
|
169
|
+
accessibilityRole: "button",
|
|
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: "
|
|
270
|
-
"aria-role": "
|
|
271
|
-
role: "searchbox",
|
|
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
|
}
|
|
@@ -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
|
}
|
|
@@ -7,6 +7,16 @@ import { TreeNode } from "./TreeNode";
|
|
|
7
7
|
import { Tree } from "./Tree";
|
|
8
8
|
import { subscriber } from "../functionUtils";
|
|
9
9
|
import { getFocusableId, toFocusDirection } from "./utils";
|
|
10
|
+
import {
|
|
11
|
+
isCurrentFocusOnMenu,
|
|
12
|
+
isCurrentFocusOnContent,
|
|
13
|
+
findSelectedMenuId,
|
|
14
|
+
isTabsScreenContentFocused,
|
|
15
|
+
findSelectedTabId,
|
|
16
|
+
contextWithoutScrolling,
|
|
17
|
+
} from "./aux";
|
|
18
|
+
|
|
19
|
+
export { contextWithoutScrolling } from "./aux";
|
|
10
20
|
|
|
11
21
|
export {
|
|
12
22
|
toFocusDirection,
|
|
@@ -221,7 +231,8 @@ class FocusManager {
|
|
|
221
231
|
|
|
222
232
|
private setNextFocus(
|
|
223
233
|
nextFocus: FocusManager.TouchableReactRef,
|
|
224
|
-
options?: FocusManager.Android.CallbackOptions
|
|
234
|
+
options?: FocusManager.Android.CallbackOptions,
|
|
235
|
+
context?: FocusManager.FocusContext
|
|
225
236
|
) {
|
|
226
237
|
if (nextFocus?.current?.props?.blockFocus) {
|
|
227
238
|
return;
|
|
@@ -250,7 +261,7 @@ class FocusManager {
|
|
|
250
261
|
|
|
251
262
|
FocusManager.instance.setPreviousNavigationDirection(options ?? null);
|
|
252
263
|
|
|
253
|
-
nextFocus?.current?.onFocus?.(nextFocus.current, options ?? {});
|
|
264
|
+
nextFocus?.current?.onFocus?.(nextFocus.current, options ?? {}, context);
|
|
254
265
|
}
|
|
255
266
|
}
|
|
256
267
|
|
|
@@ -291,7 +302,8 @@ class FocusManager {
|
|
|
291
302
|
|
|
292
303
|
setFocus(
|
|
293
304
|
newFocus: FocusManager.TouchableReactRef | string,
|
|
294
|
-
options?: FocusManager.Android.CallbackOptions
|
|
305
|
+
options?: FocusManager.Android.CallbackOptions,
|
|
306
|
+
context?: FocusManager.FocusContext
|
|
295
307
|
) {
|
|
296
308
|
// Checks if element is focusable
|
|
297
309
|
const { isFocusable, error } = FocusManager.isFocusable(newFocus);
|
|
@@ -316,7 +328,7 @@ class FocusManager {
|
|
|
316
328
|
}
|
|
317
329
|
|
|
318
330
|
if (newFocusRef) {
|
|
319
|
-
FocusManager.instance.setNextFocus(newFocusRef, options);
|
|
331
|
+
FocusManager.instance.setNextFocus(newFocusRef, options, context);
|
|
320
332
|
}
|
|
321
333
|
}
|
|
322
334
|
}
|
|
@@ -351,6 +363,11 @@ class FocusManager {
|
|
|
351
363
|
FocusManager.instance.focused.onBlur(FocusManager.instance.focused, {});
|
|
352
364
|
}
|
|
353
365
|
|
|
366
|
+
// send reset event to some handler to reset their internal state, before real reset happens
|
|
367
|
+
this.eventHandler?.invokeHandler?.(FOCUS_EVENTS.RESET, {
|
|
368
|
+
focusedId: FocusManager.instance.focusedId,
|
|
369
|
+
});
|
|
370
|
+
|
|
354
371
|
FocusManager.instance.setFocusLocal({ current: null });
|
|
355
372
|
}
|
|
356
373
|
|
|
@@ -417,6 +434,48 @@ class FocusManager {
|
|
|
417
434
|
throw new Error(`Group with id ${id} not found`);
|
|
418
435
|
}
|
|
419
436
|
}
|
|
437
|
+
|
|
438
|
+
isFocusOnMenu(): boolean {
|
|
439
|
+
return isCurrentFocusOnMenu(this.tree, FocusManager.instance.focusedId);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
isFocusOnContent(): boolean {
|
|
443
|
+
return isCurrentFocusOnContent(this.tree, FocusManager.instance.focusedId);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// Move focus to appropriate top navigation tab with context
|
|
447
|
+
focusTopNavigation(isTabsScreen: boolean, item: ZappEntry): void {
|
|
448
|
+
const landFocusTo = (id) => {
|
|
449
|
+
if (id) {
|
|
450
|
+
// set focus on selected menu item
|
|
451
|
+
const direction = undefined;
|
|
452
|
+
|
|
453
|
+
const context: FocusManager.FocusContext =
|
|
454
|
+
contextWithoutScrolling("back");
|
|
455
|
+
|
|
456
|
+
logger.log({ message: "landFocusTo", data: { id } });
|
|
457
|
+
|
|
458
|
+
this.setFocus(id, direction, context);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
if (
|
|
463
|
+
isTabsScreen &&
|
|
464
|
+
isTabsScreenContentFocused(this.tree, FocusManager.instance.focusedId)
|
|
465
|
+
) {
|
|
466
|
+
const selectedTabId = findSelectedTabId(this.tree, item);
|
|
467
|
+
|
|
468
|
+
// Set focus with back button context to tabs-menu
|
|
469
|
+
landFocusTo(selectedTabId);
|
|
470
|
+
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const selectedMenuItemId = findSelectedMenuId(this.tree);
|
|
475
|
+
|
|
476
|
+
// Set focus with back button context to top-menu
|
|
477
|
+
landFocusTo(selectedMenuItemId);
|
|
478
|
+
}
|
|
420
479
|
}
|
|
421
480
|
|
|
422
481
|
export const focusManager = FocusManager.getInstance();
|