AccessibilityInfo
Ta strona została przetłumaczona przez PageTurner AI (beta). Nie jest oficjalnie zatwierdzona przez projekt. Znalazłeś błąd? Zgłoś problem →
Czasami warto wiedzieć, czy na urządzeniu aktywny jest czytnik ekranu. API AccessibilityInfo służy właśnie temu celowi. Możesz go użyć do sprawdzenia aktualnego stanu czytnika ekranu oraz do zarejestrowania powiadomień o zmianie tego stanu.
Przykład
Dokumentacja
Metody
addEventListener()
static addEventListener(
eventName: AccessibilityChangeEventName | AccessibilityAnnouncementEventName,
handler: (
event: AccessibilityChangeEvent | AccessibilityAnnouncementFinishedEvent,
) => void,
): EmitterSubscription;
Dodaje obsługę zdarzenia. Obsługiwane zdarzenia:
| Event name | Description |
|---|---|
accessibilityServiceChangedAndroid | Fires when some services such as TalkBack, other Android assistive technologies, and third-party accessibility services are enabled. The argument to the event handler is a boolean. The boolean is true when a some accessibility services is enabled and false otherwise. |
announcementFinishediOS | Fires when the screen reader has finished making an announcement. The argument to the event handler is a dictionary with these keys:
|
boldTextChangediOS | Fires when the state of the bold text toggle changes. The argument to the event handler is a boolean. The boolean is true when bold text is enabled and false otherwise. |
grayscaleChangediOS | Fires when the state of the gray scale toggle changes. The argument to the event handler is a boolean. The boolean is true when a gray scale is enabled and false otherwise. |
invertColorsChangediOS | Fires when the state of the invert colors toggle changes. The argument to the event handler is a boolean. The boolean is true when invert colors is enabled and false otherwise. |
reduceMotionChanged | Fires when the state of the reduce motion toggle changes. The argument to the event handler is a boolean. The boolean is true when a reduce motion is enabled (or when "Transition Animation Scale" in "Developer options" is "Animation off") and false otherwise. |
reduceTransparencyChangediOS | Fires when the state of the reduce transparency toggle changes. The argument to the event handler is a boolean. The boolean is true when reduce transparency is enabled and false otherwise. |
screenReaderChanged | Fires when the state of the screen reader changes. The argument to the event handler is a boolean. The boolean is true when a screen reader is enabled and false otherwise. |
announceForAccessibility()
static announceForAccessibility(announcement: string);
Wysyła ciąg znaków do odczytania przez czytnik ekranu.
announceForAccessibilityWithOptions()
static announceForAccessibilityWithOptions(
announcement: string,
options: {queue?: boolean},
);
Wysyła ciąg znaków do odczytania przez czytnik ekranu z opcjami modyfikacji. Domyślnie ogłoszenia przerywają bieżącą mowę, ale w iOS można je umieścić w kolejce za istniejącą mową, ustawiając queue na true w obiekcie opcji.
Parametry:
| Name | Type | Description |
|---|---|---|
| announcement Required | string | The string to be announced |
| options Required | object | queue - queue the announcement behind existing speech iOS |
getRecommendedTimeoutMillis() Android
static getRecommendedTimeoutMillis(originalTimeout: number): Promise<number>;
Pobiera limit czasu w milisekundach wymagany przez użytkownika. Wartość ta jest ustawiana w "Czas na podjęcie akcji (Limit czasu dostępności)" w ustawieniach "Dostępność".
Parametry:
| Name | Type | Description |
|---|---|---|
| originalTimeout Required | number | The timeout to return if "Accessibility timeout" is not set. Specify in milliseconds. |
isAccessibilityServiceEnabled() Android
static isAccessibilityServiceEnabled(): Promise<boolean>;
Sprawdza, czy jakakolwiek usługa dostępności jest włączona. Dotyczy to TalkBack oraz innych aplikacji dostępności osób trzecich. Aby sprawdzić tylko stan TalkBack, użyj isScreenReaderEnabled. Zwraca obietnicę rozwiązującą się do wartości logicznej. Wynik to true, gdy jakakolwiek usługa dostępności jest włączona i false w przeciwnym przypadku.
Jeśli chcesz sprawdzić tylko stan TalkBack, użyj isScreenReaderEnabled.
isBoldTextEnabled() iOS
static isBoldTextEnabled(): Promise<boolean>:
Sprawdza, czy włączono pogrubienie tekstu. Zwraca obietnicę rozwiązującą się do wartości logicznej. Wynik to true, gdy pogrubienie jest włączone i false w przeciwnym przypadku.
isGrayscaleEnabled() iOS
static isGrayscaleEnabled(): Promise<boolean>;
Sprawdza, czy włączono skalę szarości. Zwraca obietnicę rozwiązującą się do wartości logicznej. Wynik to true, gdy skala szarości jest włączona i false w przeciwnym przypadku.
isInvertColorsEnabled() iOS
static isInvertColorsEnabled(): Promise<boolean>;
Sprawdza, czy włączono inwersję kolorów. Zwraca obietnicę rozwiązującą się do wartości logicznej. Wynik to true, gdy inwersja jest włączona i false w przeciwnym przypadku.
isReduceMotionEnabled()
static isReduceMotionEnabled(): Promise<boolean>;
Sprawdza, czy włączono redukcję ruchu. Zwraca obietnicę rozwiązującą się do wartości logicznej. Wynik to true, gdy redukcja ruchu jest włączona i false w przeciwnym przypadku.
isReduceTransparencyEnabled() iOS
static isReduceTransparencyEnabled(): Promise<boolean>;
Sprawdza, czy włączono redukcję przeźroczystości. Zwraca obietnicę rozwiązującą się do wartości logicznej. Wynik to true, gdy redukcja przeźroczystości jest włączona i false w przeciwnym przypadku.
isScreenReaderEnabled()
static isScreenReaderEnabled(): Promise<boolean>;
Sprawdza, czy czytnik ekranu jest włączony. Zwraca obietnicę rozwiązującą się do wartości logicznej. Wynik to true, gdy czytnik jest włączony i false w przeciwnym przypadku.
prefersCrossFadeTransitions() iOS
static prefersCrossFadeTransitions(): Promise<boolean>;
Sprawdza, czy włączono ustawienia redukcji ruchu i preferencji przejść typu cross-fade. Zwraca obietnicę rozwiązującą się do wartości logicznej. Wynik to true, gdy preferencje przejść cross-fade są włączone i false w przeciwnym przypadku.
setAccessibilityFocus()
Zaleca się użycie sendAccessibilityEvent z typem zdarzenia focus zamiast tej metody.
static setAccessibilityFocus(reactTag: number);
Ustawia fokus dostępności na komponencie Reacta.
W Androidzie wywołuje metodę UIManager.sendAccessibilityEvent z przekazanymi argumentami reactTag i UIManager.AccessibilityEventTypes.typeViewFocused.
Upewnij się, że każdy komponent View, który ma otrzymać fokus dostępności, ma ustawioną właściwość accessible={true}.
sendAccessibilityEvent()
static sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes);
Wywołuje imperatywnie zdarzenie dostępności na komponencie Reacta, np. zmianę fokusu dla czytnika ekranu.
Upewnij się, że każdy komponent View, który ma otrzymać fokus dostępności, ma ustawioną właściwość accessible={true}.
| Name | Type | Description |
|---|---|---|
| host Required | HostInstance | The component ref to send the event to. |
| eventType Required | AccessibilityEventTypes | One of 'click' (Android only), 'focus', 'viewHoverEnter' (Android only), or 'windowStateChange' (Android only) |