Przejdź do treści głównej
Wersja: 0.77

AccessibilityInfo

Nieoficjalne Tłumaczenie Beta

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()

tsx
static addEventListener(
eventName: AccessibilityChangeEventName | AccessibilityAnnouncementEventName,
handler: (
event: AccessibilityChangeEvent | AccessibilityAnnouncementFinishedEvent,
) => void,
): EmitterSubscription;

Dodaje obsługę zdarzenia. Obsługiwane zdarzenia:

Event nameDescription
accessibilityServiceChanged
Android
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.
announcementFinished
iOS
Fires when the screen reader has finished making an announcement. The argument to the event handler is a dictionary with these keys:
  • announcement: The string announced by the screen reader.
  • success: A boolean indicating whether the announcement was successfully made.
boldTextChanged
iOS
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.
grayscaleChanged
iOS
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.
invertColorsChanged
iOS
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.
reduceMotionChangedFires 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.
reduceTransparencyChanged
iOS
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.
screenReaderChangedFires 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()

tsx
static announceForAccessibility(announcement: string);

Wysyła ciąg znaków do odczytania przez czytnik ekranu.


announceForAccessibilityWithOptions()

tsx
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:

NameTypeDescription
announcement
Required
stringThe string to be announced
options
Required
objectqueue - queue the announcement behind existing speech
iOS

getRecommendedTimeoutMillis()
Android

tsx
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:

NameTypeDescription
originalTimeout
Required
numberThe timeout to return if "Accessibility timeout" is not set. Specify in milliseconds.

isAccessibilityServiceEnabled()
Android

tsx
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.

Uwaga: Użyj isScreenReaderEnabled, jeśli chcesz sprawdzić tylko stan TalkBack.


isBoldTextEnabled()
iOS

tsx
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

tsx
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

tsx
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()

tsx
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

tsx
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()

tsx
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

tsx
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()

Przestarzałe

Zaleca się użycie sendAccessibilityEvent z typem zdarzenia focus zamiast tej metody.

tsx
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.

uwaga

Upewnij się, że każdy komponent View, który ma otrzymać fokus dostępności, ma ustawioną właściwość accessible={true}.


sendAccessibilityEvent()

tsx
static sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes);

Wywołuje imperatywnie zdarzenie dostępności na komponencie Reacta, np. zmianę fokusu dla czytnika ekranu.

uwaga

Upewnij się, że każdy komponent View, który ma otrzymać fokus dostępności, ma ustawioną właściwość accessible={true}.

NameTypeDescription
host
Required
HostInstanceThe component ref to send the event to.
eventType
Required
AccessibilityEventTypesOne of 'click' (Android only), 'focus', 'viewHoverEnter' (Android only), or 'windowStateChange' (Android only)