File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
app/views/RoomsListView/hooks Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 11import { useCallback , useReducer } from 'react' ;
2+ import { AccessibilityInfo } from 'react-native' ;
23
34import { type IRoomItem } from '../../../containers/RoomItem/interfaces' ;
45import { search as searchLib } from '../../../lib/methods/search' ;
56import { useDebounce } from '../../../lib/methods/helpers/debounce' ;
7+ import i18n from '../../../i18n' ;
68
79interface SearchState {
810 searchEnabled : boolean ;
@@ -58,11 +60,22 @@ export const useSearch = () => {
5860
5961 const [ state , dispatch ] = useReducer ( searchReducer , initialState ) ;
6062
63+ const announceSearchResultsForAccessibility = ( count : number ) => {
64+ if ( count < 1 ) {
65+ AccessibilityInfo . announceForAccessibility ( i18n . t ( 'No_results_found' ) ) ;
66+ return ;
67+ }
68+
69+ const message = count === 1 ? i18n . t ( 'One_result_found' ) : i18n . t ( 'Search_Results_found' , { count } ) ;
70+ AccessibilityInfo . announceForAccessibility ( message ) ;
71+ } ;
72+
6173 const search = useDebounce ( async ( text : string ) => {
6274 if ( ! state . searchEnabled ) return ;
6375 dispatch ( { type : 'SET_SEARCHING' } ) ;
6476 const result = await searchLib ( { text } ) ;
6577 dispatch ( { type : 'SEARCH_SUCCESS' , payload : result as IRoomItem [ ] } ) ;
78+ announceSearchResultsForAccessibility ( result . length ) ;
6679 } , 500 ) ;
6780
6881 const startSearch = useCallback ( ( ) => {
You can’t perform that action at this time.
0 commit comments