diff --git a/src/components/checkbox/index.tsx b/src/components/checkbox/index.tsx index c62801558e..a80aac2a14 100644 --- a/src/components/checkbox/index.tsx +++ b/src/components/checkbox/index.tsx @@ -10,6 +10,7 @@ import { ImageStyle } from 'react-native'; import {Colors, Spacings} from '../../style'; +import {StyleUtils} from '../../utils'; //@ts-ignore import Assets from '../../assets'; import {asBaseComponent} from '../../commons/new'; @@ -251,9 +252,7 @@ class Checkbox extends Component { }; }; - getAccessibleHitSlop(size: number) { - return Math.max(0, (48 - size) / 2); - } + renderCheckbox() { const {selectedIcon, label, testID, style, containerStyle, indeterminate, ...others} = this.props; @@ -267,7 +266,7 @@ class Checkbox extends Component { {...others} style={[this.getBorderStyle(), style, !label && containerStyle]} onPress={this.onPress} - hitSlop={this.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)} + hitSlop={StyleUtils.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)} > { { if (Array.isArray(props.size)) { if (props.size[0] >= props.size[1] || props.size[1] >= props.size[2]) { - console.warn( - 'It is recommended that largeSize > mediumSize > smallSize, currently: smallSize=', + console.warn('It is recommended that largeSize > mediumSize > smallSize, currently: smallSize=', props.size[0], 'mediumSize=', props.size[1], 'largeSize=', - props.size[2] - ); + props.size[2]); } } } @@ -190,6 +189,8 @@ class PageControl extends PureComponent { renderIndicator(index: number, size: number, enlargeActive?: boolean) { const {currentPage, color, inactiveColor, onPagePress, spacing = PageControl.DEFAULT_SPACING} = this.props; + const hitSlopValue = StyleUtils.getAccessibleHitSlop(size); + return ( { getColorStyle(index === currentPage, color, inactiveColor), getSizeStyle(size, index, currentPage, enlargeActive) ]} + hitSlop={{ + top: hitSlopValue, + bottom: hitSlopValue + }} /> ); } diff --git a/src/components/radioButton/index.tsx b/src/components/radioButton/index.tsx index 6f0b5e579c..c1301cf418 100644 --- a/src/components/radioButton/index.tsx +++ b/src/components/radioButton/index.tsx @@ -10,6 +10,7 @@ import { ViewStyle } from 'react-native'; import {Colors} from '../../style'; +import {StyleUtils} from '../../utils'; import {asBaseComponent, forwardRef, BaseComponentInjectedProps, ForwardRefInjectedProps} from '../../commons/new'; import TouchableOpacity from '../touchableOpacity'; import View, {ViewProps} from '../view'; @@ -257,18 +258,12 @@ class RadioButton extends PureComponent { ); } - getAccessibleHitSlop(size: number) { - const verticalPadding = Math.max(0, (48 - size) / 2); - - return { - top: verticalPadding, - bottom: verticalPadding - }; - } + render() { const {onPress, onValueChange, containerStyle, contentOnLeft, ...others} = this.props; const Container = onPress || onValueChange ? TouchableOpacity : View; + const hitSlopValue = StyleUtils.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE); return ( // @ts-ignore @@ -280,7 +275,10 @@ class RadioButton extends PureComponent { style={containerStyle} onPress={this.onPress} {...this.getAccessibilityProps()} - hitSlop={this.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)} + hitSlop={{ + top: hitSlopValue, + bottom: hitSlopValue + }} > {!contentOnLeft && this.renderButton()} {this.props.iconOnRight ? this.renderLabel() : this.renderIcon()} diff --git a/src/utils/styleUtils.ts b/src/utils/styleUtils.ts index 1df065a72c..75232cce60 100644 --- a/src/utils/styleUtils.ts +++ b/src/utils/styleUtils.ts @@ -9,3 +9,7 @@ export function unpackStyle(style?: StyleProp, options: UnpackStyleOp return JSON.parse(JSON.stringify(options.flatten ? StyleSheet.flatten(style) : style)); } } + +export function getAccessibleHitSlop(size: number) { + return Math.max(0, (48 - size) / 2); +}