From 90579f75462fc8472b484752808d9a0714077f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E5=9D=A4?= Date: Tue, 1 Mar 2022 18:24:15 +0800 Subject: [PATCH] feat: support Accessibility --- components/activity-indicator/index.tsx | 5 +-- components/button/ButtonWave.tsx | 14 ++++++-- components/button/index.tsx | 2 ++ components/checkbox/Checkbox.tsx | 24 +++++++------ components/radio/Radio.tsx | 5 +++ components/radio/RadioGroup.tsx | 6 +++- components/switch/PropsType.tsx | 5 ++- components/switch/Switch.tsx | 45 +++++++++++++++++++------ components/switch/style/index.tsx | 8 ++--- 9 files changed, 84 insertions(+), 30 deletions(-) diff --git a/components/activity-indicator/index.tsx b/components/activity-indicator/index.tsx index 8e3344b0..5fab8209 100644 --- a/components/activity-indicator/index.tsx +++ b/components/activity-indicator/index.tsx @@ -1,9 +1,10 @@ import React from 'react' import { ActivityIndicator, + ColorValue, + StyleProp, Text, View, - StyleProp, ViewStyle, } from 'react-native' import { WithTheme, WithThemeStyles } from '../style' @@ -12,7 +13,7 @@ import ActivityIndicatorStyles, { ActivityIndicatorStyle } from './style/index' export interface ActivityIndicatorNativeProps extends WithThemeStyles { styles?: { [key: string]: StyleProp } - color?: string + color?: ColorValue animating?: boolean toast?: boolean size?: number | 'large' | 'small' diff --git a/components/button/ButtonWave.tsx b/components/button/ButtonWave.tsx index 9384f86f..11813e25 100644 --- a/components/button/ButtonWave.tsx +++ b/components/button/ButtonWave.tsx @@ -16,8 +16,13 @@ interface ButtonWaveProps extends TouchableNativeFeedbackProps { export default (props: ButtonWaveProps) => { const { Color, ...restProps } = props + const accessibilityState = { + disabled: !!props.disabled, + } return IS_ANDROID ? ( = 21 ? TouchableNativeFeedback.Ripple(Color || '', true, 13) @@ -25,9 +30,14 @@ export default (props: ButtonWaveProps) => { } useForeground={true} {...restProps}> - {props.children} + <>{props.children} ) : ( - {props.children} + + {props.children} + ) } diff --git a/components/button/index.tsx b/components/button/index.tsx index e8528f8e..c41aff8d 100644 --- a/components/button/index.tsx +++ b/components/button/index.tsx @@ -117,6 +117,8 @@ export default class Button extends React.Component { return ( { + WithThemeStyles, + AccessibilityProps { style?: StyleProp } //TODO: ref interface @@ -139,20 +141,22 @@ const InternalCheckbox = ( ? _styles.checkbox_checked?.borderColor : _styles.checkbox?.borderColor return ( - + - - - - + + diff --git a/components/radio/Radio.tsx b/components/radio/Radio.tsx index 998228f7..3f13ae92 100644 --- a/components/radio/Radio.tsx +++ b/components/radio/Radio.tsx @@ -44,6 +44,11 @@ const InternalRadio = ( {(_styles) => ( ( } return ( - + void export type SwitchClickEventHandler = SwitchChangeEventHandler @@ -9,6 +9,9 @@ export interface SwitchPropsType { checked?: boolean defaultChecked?: boolean color?: string + trackColor?: { false?: ColorValue; true?: ColorValue } + thumbColor?: ColorValue + thumbTintColor?: ColorValue disabled?: boolean loading?: boolean styles?: { [key: string]: StyleProp } diff --git a/components/switch/Switch.tsx b/components/switch/Switch.tsx index b9f1743f..37967488 100644 --- a/components/switch/Switch.tsx +++ b/components/switch/Switch.tsx @@ -23,6 +23,9 @@ const AntmSwitch = ({ unCheckedChildren, onPress, onChange, + trackColor, + thumbColor, + thumbTintColor, ...restProps }: SwitchPropsType) => { devWarning( @@ -61,7 +64,7 @@ const AntmSwitch = ({ const transitionWidth = { width: animatedValue2.interpolate({ inputRange: [0, 1], - outputRange: [18, 24], + outputRange: [22, 28], }), left: !innerChecked ? animatedValue.interpolate({ @@ -143,16 +146,33 @@ const AntmSwitch = ({ .map((a) => styles[a]) // color props - const SwitchCheckedColor = { - backgroundColor: color, - borderColor: color, - } const Color = innerChecked - ? color || theme.switch_fill - : theme.switch_unchecked + ? color || trackColor?.true || theme.switch_fill + : trackColor?.false || theme.switch_unchecked + + const SwitchTrackColor = { + backgroundColor: Color, + borderColor: Color, + opacity: Color ? (disabled ? 0.6 : 1) : 1, + } + + const SwitchThumbColor = JSON.parse( + JSON.stringify({ + backgroundColor: innerChecked ? thumbTintColor : thumbColor, + }), + ) + + const accessibilityState = { + checked: innerChecked, + disabled, + busy: loading, + } return ( - + - + {loading && ( StyleSheet.create({ switch: { position: 'relative', - minWidth: 44, - minHeight: 22, + minWidth: 50, + minHeight: 25, display: 'flex', flexDirection: 'row', alignItems: 'center', @@ -34,8 +34,8 @@ export default (theme: Theme) => // handle switch_handle: { position: 'absolute', - width: 18, - height: 18, + width: 22, + height: 22, borderRadius: 999, backgroundColor: '#ffffff', },