1 | const lastFocusedViewOnPageKeyName = '__lastFocusedViewOnPage';
|
2 | export const accessibilityBlurEvent = 'accessibilityBlur';
|
3 | export const accessibilityFocusEvent = 'accessibilityFocus';
|
4 | export const accessibilityFocusChangedEvent = 'accessibilityFocusChanged';
|
5 | export const accessibilityPerformEscapeEvent = 'accessibilityPerformEscape';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export function notifyAccessibilityFocusState(view, receivedFocus, lostFocus) {
|
17 | if (!receivedFocus && !lostFocus) {
|
18 | return;
|
19 | }
|
20 | view.notify({
|
21 | eventName: accessibilityFocusChangedEvent,
|
22 | object: view,
|
23 | value: !!receivedFocus,
|
24 | });
|
25 | if (receivedFocus) {
|
26 | if (view.page) {
|
27 | view.page[lastFocusedViewOnPageKeyName] = new WeakRef(view);
|
28 | }
|
29 | view.notify({
|
30 | eventName: accessibilityFocusEvent,
|
31 | object: view,
|
32 | });
|
33 | }
|
34 | else if (lostFocus) {
|
35 | view.notify({
|
36 | eventName: accessibilityBlurEvent,
|
37 | object: view,
|
38 | });
|
39 | }
|
40 | }
|
41 | export function getLastFocusedViewOnPage(page) {
|
42 | try {
|
43 | const lastFocusedViewRef = page[lastFocusedViewOnPageKeyName];
|
44 | if (!lastFocusedViewRef) {
|
45 | return null;
|
46 | }
|
47 | const lastFocusedView = lastFocusedViewRef.deref();
|
48 | if (!lastFocusedView) {
|
49 | return null;
|
50 | }
|
51 | if (!lastFocusedView.parent || lastFocusedView.page !== page) {
|
52 | return null;
|
53 | }
|
54 | return lastFocusedView;
|
55 | }
|
56 | catch {
|
57 |
|
58 | }
|
59 | finally {
|
60 | delete page[lastFocusedViewOnPageKeyName];
|
61 | }
|
62 | return null;
|
63 | }
|
64 |
|
\ | No newline at end of file |