-
-
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
Mobile: Accessibility: Add checked/unchecked accessibility information to the "sort notes by" dialog #11411
Mobile: Accessibility: Add checked/unchecked accessibility information to the "sort notes by" dialog #11411
Changes from all commits
bd3e974
043c42b
6226ec0
54c388b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import * as React from 'react'; | ||
import { useMemo } from 'react'; | ||
import { StyleSheet, TextStyle, View } from 'react-native'; | ||
import { TouchableRipple, Text } from 'react-native-paper'; | ||
import { PromptButtonSpec } from './types'; | ||
import { ThemeStyle, themeStyle } from '../global-style'; | ||
import Icon from '../Icon'; | ||
|
||
interface Props { | ||
themeId: number; | ||
buttonSpec: PromptButtonSpec; | ||
} | ||
|
||
const useStyles = (theme: ThemeStyle) => { | ||
return useMemo(() => { | ||
const buttonText: TextStyle = { | ||
color: theme.color4, | ||
textAlign: 'center', | ||
}; | ||
|
||
return StyleSheet.create({ | ||
buttonContainer: { | ||
// This applies the borderRadius to the TouchableRipple's parent, which | ||
// seems necessary on Android. | ||
borderRadius: theme.borderRadius, | ||
overflow: 'hidden', | ||
}, | ||
button: { | ||
borderRadius: theme.borderRadius, | ||
padding: 10, | ||
}, | ||
buttonContent: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
justifyContent: 'center', | ||
alignItems: 'baseline', | ||
}, | ||
buttonText, | ||
icon: { | ||
...buttonText, | ||
marginRight: 8, | ||
}, | ||
}); | ||
}, [theme]); | ||
}; | ||
|
||
const PromptButton: React.FC<Props> = props => { | ||
const theme = themeStyle(props.themeId); | ||
const styles = useStyles(theme); | ||
|
||
const { checked, text, iconChecked, onPress } = props.buttonSpec; | ||
|
||
const isCheckbox = (checked ?? null) !== null; | ||
const icon = checked ? ( | ||
<> | ||
<Icon | ||
accessibilityLabel={null} | ||
style={styles.icon} | ||
name={iconChecked ?? 'fas fa-check'} | ||
/> | ||
</> | ||
) : null; | ||
|
||
return ( | ||
<View style={styles.buttonContainer}> | ||
<TouchableRipple | ||
onPress={onPress} | ||
style={styles.button} | ||
rippleColor={theme.backgroundColorHover4} | ||
accessibilityRole={isCheckbox ? 'checkbox' : 'button'} | ||
accessibilityState={isCheckbox ? { checked } : null} | ||
aria-checked={isCheckbox ? checked : undefined} | ||
> | ||
<View style={styles.buttonContent}> | ||
{icon} | ||
<Text style={styles.buttonText}>{text}</Text> | ||
</View> | ||
</TouchableRipple> | ||
</View> | ||
); | ||
}; | ||
|
||
export default PromptButton; |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -3,6 +3,8 @@ import { Platform, TextStyle, ViewStyle } from 'react-native'; | |||
import { themeById } from '@joplin/lib/theme'; | ||||
import { Theme as BaseTheme } from '@joplin/lib/themes/type'; | ||||
|
||||
const Color = require('color'); | ||||
|
||||
const baseStyle = { | ||||
appearance: 'light', | ||||
fontSize: 16, | ||||
|
@@ -16,12 +18,15 @@ const baseStyle = { | |||
}; | ||||
|
||||
export type ThemeStyle = BaseTheme & typeof baseStyle & { | ||||
backgroundColorHover4: string; | ||||
|
||||
fontSize: number; | ||||
fontSizeSmaller: number; | ||||
marginRight: number; | ||||
marginLeft: number; | ||||
marginTop: number; | ||||
marginBottom: number; | ||||
borderRadius: number; | ||||
icon: TextStyle; | ||||
lineInput: ViewStyle; | ||||
buttonRow: ViewStyle; | ||||
|
@@ -112,6 +117,9 @@ function extraStyles(theme: BaseTheme) { | |||
keyboardAppearance: theme.appearance, | ||||
color5: theme.color5 ?? theme.backgroundColor4, | ||||
backgroundColor5: theme.backgroundColor5 ?? theme.color4, | ||||
|
||||
backgroundColorHover4: Color(theme.color4).alpha(0.12).rgb().string(), | ||||
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.
Line 111 in d7b3ef8
Additionally, |
||||
borderRadius: 24, | ||||
}; | ||||
} | ||||
|
||||
|
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 React Native Paper
Button
to aTouchableRipple
. Unlike<Button>
,TouchableRipple
allows providing a customaccessibilityState
. This allows communicating whether the button represents a checked/unchecked menu item.On web,
aria-checked
seems necessary —react-native-web
seems to ignore theaccessibilityState
'schecked
option.