Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore/5057-streamlineUseIsScreenReaderEnabledHook #10362

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
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

This file was deleted.

3 changes: 2 additions & 1 deletion VAMobile/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'

import { useIsScreenReaderEnabled } from '@department-of-veterans-affairs/mobile-component-library'
import { ActionSheetProvider, connectActionSheet } from '@expo/react-native-action-sheet'
import { QueryClientProvider } from '@tanstack/react-query'
import { ThemeProvider } from 'styled-components'
Expand Down Expand Up @@ -64,7 +65,7 @@ import { SnackBarState } from 'store/slices/snackBarSlice'
import { useColorScheme } from 'styles/themes/colorScheme'
import theme, { getTheme, setColorScheme } from 'styles/themes/standardTheme'
import getEnv from 'utils/env'
import { useAppDispatch, useFontScale, useIsScreenReaderEnabled } from 'utils/hooks'
import { useAppDispatch, useFontScale } from 'utils/hooks'
import { useHeaderStyles, useTopPaddingAsHeaderStyles } from 'utils/hooks/headerStyles'
import i18n from 'utils/i18n'
import { isIOS } from 'utils/platform'
Expand Down
6 changes: 4 additions & 2 deletions VAMobile/src/components/Templates/CategoryLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {
} from 'react-native'
import { useSafeAreaInsets } from 'react-native-safe-area-context'

import { useIsScreenReaderEnabled } from '@department-of-veterans-affairs/mobile-component-library'

import { CrisisLineButton, HeaderButton, TextView, TextViewProps, WaygateWrapper } from 'components'
import VAScrollView, { VAScrollViewProps } from 'components/VAScrollView'
import { useIsScreenReaderEnabled, useTheme } from 'utils/hooks'
import { useTheme } from 'utils/hooks'

import HeaderBanner, { HeaderBannerProps } from './HeaderBanner'

Expand Down Expand Up @@ -43,7 +45,7 @@ export const CategoryLanding: FC<CategoryLandingProps> = ({
const insets = useSafeAreaInsets()
const fontScale = useWindowDimensions().fontScale
const theme = useTheme()
const screenReaderEnabled = useIsScreenReaderEnabled(true)
const screenReaderEnabled = useIsScreenReaderEnabled()

const [scrollOffset, setScrollOffset] = useState(0)
const [trackScrollOffset, setTrackScrollOffset] = useState(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React, { FC, ReactNode, useState } from 'react'
import { LayoutChangeEvent, StatusBar, View, ViewStyle, useWindowDimensions } from 'react-native'
import { useSafeAreaInsets } from 'react-native-safe-area-context'

import { useIsScreenReaderEnabled } from '@department-of-veterans-affairs/mobile-component-library'

import { HeaderButton, TextView, TextViewProps, WaygateWrapper } from 'components'
import VAScrollView, { VAScrollViewProps } from 'components/VAScrollView'
import { useIsScreenReaderEnabled, useTheme } from 'utils/hooks'
import { useTheme } from 'utils/hooks'

import HeaderBanner, { HeaderBannerProps } from './HeaderBanner'

Expand Down Expand Up @@ -56,7 +58,7 @@ export const ChildTemplate: FC<ChildTemplateProps> = ({
const insets = useSafeAreaInsets()
const fontScale = useWindowDimensions().fontScale
const theme = useTheme()
const screenReaderEnabled = useIsScreenReaderEnabled(true)
const screenReaderEnabled = useIsScreenReaderEnabled()

const [scrollOffset, setScrollOffset] = useState(0)
const [trackScrollOffset, setTrackScrollOffset] = useState(true)
Expand Down
5 changes: 3 additions & 2 deletions VAMobile/src/components/Templates/HeaderBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { Shadow, ShadowProps } from 'react-native-shadow-2'

import { useFocusEffect } from '@react-navigation/native'

import { useIsScreenReaderEnabled } from '@department-of-veterans-affairs/mobile-component-library'
import { IconProps } from '@department-of-veterans-affairs/mobile-component-library/src/components/Icon/Icon'

import { Box, BoxProps, DescriptiveBackButton, IconWithText, TextView, TextViewProps } from 'components'
import MenuView, { MenuViewActionsType } from 'components/Menu'
import { useAccessibilityFocus, useIsScreenReaderEnabled, useTheme } from 'utils/hooks'
import { useAccessibilityFocus, useTheme } from 'utils/hooks'

export type HeaderLeftButtonProps = {
text: string
Expand Down Expand Up @@ -81,7 +82,7 @@ const HeaderBanner: FC<HeaderBannerProps> = ({
const [focusTitle, setFocusTitle] = useAccessibilityFocus<View>()
const focus = leftButton ? 'Left' : title ? 'Title' : 'Right'
useFocusEffect(focus === 'Title' ? setFocusTitle : setFocus)
const screenReaderEnabled = useIsScreenReaderEnabled(true)
const screenReaderEnabled = useIsScreenReaderEnabled()

const TEXT_CONSTRAINT_THRESHOLD = 30

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { View, ViewStyle } from 'react-native'

import { useIsFocused } from '@react-navigation/native'

import { useIsScreenReaderEnabled } from '@department-of-veterans-affairs/mobile-component-library'

import { useDownloadFileAttachment, useMessage } from 'api/secureMessaging'
import { SecureMessagingAttachment, SecureMessagingMessageAttributes } from 'api/types'
import {
Expand All @@ -20,7 +22,7 @@ import {
import { NAMESPACE } from 'constants/namespaces'
import { bytesToFinalSizeDisplay, bytesToFinalSizeDisplayA11y } from 'utils/common'
import { getFormattedDateAndTimeZone } from 'utils/formattingUtils'
import { useIsScreenReaderEnabled, useOrientation, useTheme } from 'utils/hooks'
import { useOrientation, useTheme } from 'utils/hooks'
import { fixSpecialCharacters } from 'utils/jsonFormatting'
import { getLinkifiedText } from 'utils/secureMessaging'

Expand Down Expand Up @@ -59,7 +61,7 @@ function CollapsibleMessage({ message, isInitialMessage, collapsibleMessageRef }

const messageToUse = messageWithAttachmentData?.data.attributes || message
const { attachment, hasAttachments, senderName, sentDate, body } = messageToUse
const screenReaderEnabled = useIsScreenReaderEnabled(true)
const screenReaderEnabled = useIsScreenReaderEnabled()
const dateTime = getFormattedDateAndTimeZone(sentDate)
const attachmentBoolean = hasAttachments || attachment
const attachLabel = attachmentBoolean ? t('secureMessaging.attachments.hasAttachment').toLowerCase() : ''
Expand Down
42 changes: 1 addition & 41 deletions VAMobile/src/utils/hooks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
AlertButton,
AppState,
Dimensions,
EmitterSubscription,
Keyboard,
Linking,
PixelRatio,
Expand All @@ -23,6 +22,7 @@ import { CommonActions, EventArg, useNavigation } from '@react-navigation/native
import { ParamListBase } from '@react-navigation/routers/lib/typescript/src/types'
import { StackNavigationProp } from '@react-navigation/stack'

import { useIsScreenReaderEnabled } from '@department-of-veterans-affairs/mobile-component-library'
import { useActionSheet } from '@expo/react-native-action-sheet'
import { ActionSheetOptions } from '@expo/react-native-action-sheet/lib/typescript/types'
import { DateTime } from 'luxon'
Expand Down Expand Up @@ -187,46 +187,6 @@ export function useAccessibilityFocus<T>(): [MutableRefObject<T>, () => void] {
return [ref, setFocus]
}

/**
* Hook to check if the screen reader is enabled
*
* withListener - True to add a listener to live update screen reader status, default false
* @returns boolean if the screen reader is on
*/
export function useIsScreenReaderEnabled(withListener = false): boolean {
const [screenReaderEnabled, setScreenReaderEnabled] = useState(false)

useEffect(() => {
let isMounted = true
let screenReaderChangedSubscription: EmitterSubscription

if (withListener) {
screenReaderChangedSubscription = AccessibilityInfo.addEventListener(
'screenReaderChanged',
(isScreenReaderEnabled) => {
if (isMounted) {
setScreenReaderEnabled(isScreenReaderEnabled)
}
},
)
}
AccessibilityInfo.isScreenReaderEnabled().then((isScreenReaderEnabled) => {
if (isMounted) {
setScreenReaderEnabled(isScreenReaderEnabled)
}
})

return () => {
isMounted = false
if (withListener) {
screenReaderChangedSubscription?.remove()
}
}
}, [screenReaderEnabled, withListener])

return screenReaderEnabled
}

/**
* Hook to display a warning that the user is leaving the app when tapping an external link
*
Expand Down
Loading