-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Android: Accessibility: Improve voice typing dialog screen reader accessibility #11428
Merged
laurent22
merged 2 commits into
laurent22:dev
from
personalizedrefrigerator:pr/accessibility/mobile/better-voice-typing-dialog-accessibility
Nov 22, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as React from 'react'; | ||
import { useState, useEffect, useCallback, useRef, useMemo } from 'react'; | ||
import { Banner, ActivityIndicator, Text } from 'react-native-paper'; | ||
import { Icon, ActivityIndicator, Text, Surface, Button } from 'react-native-paper'; | ||
import { _, languageName } from '@joplin/lib/locale'; | ||
import useAsyncEffect, { AsyncEffectEvent } from '@joplin/lib/hooks/useAsyncEffect'; | ||
import { IconSource } from 'react-native-paper/lib/typescript/components/Icon'; | ||
|
@@ -9,6 +9,8 @@ import whisper from '../../services/voiceTyping/whisper'; | |
import vosk from '../../services/voiceTyping/vosk'; | ||
import { AppState } from '../../utils/types'; | ||
import { connect } from 'react-redux'; | ||
import { View, StyleSheet } from 'react-native'; | ||
import AccessibleView from '../accessibility/AccessibleView'; | ||
|
||
interface Props { | ||
locale: string; | ||
|
@@ -79,6 +81,30 @@ const useWhisper = ({ locale, provider, onSetPreview, onText }: UseVoiceTypingPr | |
return [error, mustDownloadModel, voiceTyping]; | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
marginHorizontal: 1, | ||
width: '100%', | ||
maxWidth: 680, | ||
alignSelf: 'center', | ||
}, | ||
contentWrapper: { | ||
flexDirection: 'row', | ||
}, | ||
iconWrapper: { | ||
margin: 8, | ||
marginTop: 16, | ||
}, | ||
content: { | ||
marginTop: 16, | ||
marginHorizontal: 8, | ||
}, | ||
actionContainer: { | ||
flexDirection: 'row', | ||
justifyContent: 'flex-end', | ||
}, | ||
}); | ||
|
||
const VoiceTypingDialog: React.FC<Props> = props => { | ||
const [recorderState, setRecorderState] = useState<RecorderState>(RecorderState.Loading); | ||
const [preview, setPreview] = useState<string>(''); | ||
|
@@ -142,22 +168,44 @@ const VoiceTypingDialog: React.FC<Props> = props => { | |
return <Text variant='labelSmall'>{preview}</Text>; | ||
}; | ||
|
||
const headerAndStatus = <Text variant='bodyMedium'>{`${_('Voice typing...')}\n${renderContent()}`}</Text>; | ||
return ( | ||
<Banner | ||
visible={true} | ||
icon={renderIcon()} | ||
actions={[ | ||
{ | ||
label: _('Done'), | ||
onPress: onDismiss, | ||
}, | ||
]} | ||
> | ||
{headerAndStatus} | ||
<Text>{'\n'}</Text> | ||
{renderPreview()} | ||
</Banner> | ||
<Surface> | ||
<View style={styles.container}> | ||
<View style={styles.contentWrapper}> | ||
<View style={styles.iconWrapper}> | ||
<Icon source={renderIcon()} size={40}/> | ||
</View> | ||
<View style={styles.content}> | ||
<AccessibleView | ||
// Auto-focus | ||
refocusCounter={1} | ||
aria-live='polite' | ||
role='heading' | ||
> | ||
<Text variant='bodyMedium'> | ||
{_('Voice typing...')} | ||
</Text> | ||
</AccessibleView> | ||
<Text | ||
variant='bodyMedium' | ||
// role="status" might fit better here. However, react-native | ||
// doesn't seem to support it. | ||
role='alert' | ||
Comment on lines
+191
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the list of supported |
||
// Although on web, role=alert should imply aria-live=polite, | ||
// this does not seem to be the case for React Native: | ||
accessibilityLiveRegion='polite' | ||
>{renderContent()}</Text> | ||
{renderPreview()} | ||
</View> | ||
</View> | ||
<View style={styles.actionContainer}> | ||
<Button | ||
onPress={onDismiss} | ||
accessibilityHint={_('Ends voice typing')} | ||
>{_('Done')}</Button> | ||
</View> | ||
</View> | ||
</Surface> | ||
); | ||
}; | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request switches from a
<Banner>
to a<Surface>
. React Native Paper setsrole=alert
andaccessibilityLiveRegion=polite
on the content of<Banner>
s. This caused TalkBack to re-read "Voice typing... Please record your voice... [[recognised text here]]" when new text was recognised.