Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Str} from 'expensify-common';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import type {BlurEvent, FocusEvent, GestureResponderEvent, LayoutChangeEvent, StyleProp, TextInput, ViewStyle} from 'react-native';
import {StyleSheet, View} from 'react-native';
import {AccessibilityInfo, Platform, StyleSheet, View} from 'react-native';
import {Easing, useSharedValue, withTiming} from 'react-native-reanimated';
import ActivityIndicator from '@components/ActivityIndicator';
import Checkbox from '@components/Checkbox';
Expand Down Expand Up @@ -112,6 +112,7 @@ function BaseTextInput({
const labelTranslateY = useSharedValue<number>(initialActiveLabel ? styleConst.ACTIVE_LABEL_TRANSLATE_Y : styleConst.INACTIVE_LABEL_TRANSLATE_Y);
const input = useRef<TextInput | null>(null);
const isLabelActive = useRef(initialActiveLabel);
const lastAnnouncedErrorTextRef = useRef('');
const hasLabel = !!label?.length;

useHtmlPaste(input, undefined, isMarkdownEnabled, maxLength);
Expand Down Expand Up @@ -228,6 +229,29 @@ function BaseTextInput({
hasValueRef.current = false;
}, [value]);

useEffect(() => {
if (!isFocused) {
return;
}

const trimmedErrorText = errorText.trim();
if (!trimmedErrorText) {
lastAnnouncedErrorTextRef.current = '';
return;
}

if (trimmedErrorText === lastAnnouncedErrorTextRef.current) {
return;
}

lastAnnouncedErrorTextRef.current = trimmedErrorText;
if (Platform.OS === CONST.PLATFORM.IOS) {
AccessibilityInfo.announceForAccessibilityWithOptions(trimmedErrorText, {queue: true});
return;
}
AccessibilityInfo.announceForAccessibility(trimmedErrorText);
}, [errorText, isFocused]);

/**
* Set Value & activateLabel
*/
Expand Down
Loading