@@ -16,7 +16,7 @@ import {
16
16
DEFAULT_PROPS ,
17
17
ButtonSizeProp
18
18
} from './types' ;
19
- import { PADDINGS , HORIZONTAL_PADDINGS , MIN_WIDTH , DEFAULT_SIZE } from './ButtonConstants' ;
19
+ import { PADDINGS , HORIZONTAL_PADDINGS , MIN_WIDTH , DEFAULT_SIZE , SIZE_TO_VERTICAL_HITSLOP } from './ButtonConstants' ;
20
20
21
21
export { ButtonSize , ButtonAnimationDirection , ButtonProps } ;
22
22
@@ -35,7 +35,7 @@ class Button extends PureComponent<Props, ButtonState> {
35
35
super ( props ) ;
36
36
}
37
37
38
- state = {
38
+ state : Record < 'size' , undefined | number > = {
39
39
size : undefined
40
40
} ;
41
41
styles = createStyles ( ) ;
@@ -152,7 +152,17 @@ class Button extends PureComponent<Props, ButtonState> {
152
152
const { avoidMinWidth, avoidInnerPadding, round, size : propsSize } = this . props ;
153
153
const size = propsSize || DEFAULT_SIZE ;
154
154
155
- const CONTAINER_STYLE_BY_SIZE : Dictionary < any > = { } ;
155
+ const CONTAINER_STYLE_BY_SIZE : Record <
156
+ string ,
157
+ Partial < {
158
+ height : number ;
159
+ width : number ;
160
+ padding : number ;
161
+ paddingVertical : number ;
162
+ paddingHorizontal : number ;
163
+ minWidth : number ;
164
+ } >
165
+ > = { } ;
156
166
CONTAINER_STYLE_BY_SIZE [ Button . sizes . xSmall ] = round
157
167
? { height : this . state . size , width : this . state . size , padding : PADDINGS . XSMALL }
158
168
: {
@@ -339,6 +349,21 @@ class Button extends PureComponent<Props, ButtonState> {
339
349
return null ;
340
350
}
341
351
352
+ getAccessibleHitSlop ( ) {
353
+ const containerStyle = this . getContainerSizeStyle ( ) ;
354
+ const width = ( containerStyle . width || containerStyle . minWidth || 0 ) ;
355
+ const widthWithPadding = width + ( containerStyle . paddingHorizontal || containerStyle . padding || 0 ) * 2 ;
356
+ const horizontalHitslop = Math . max ( 0 , ( 48 - widthWithPadding ) / 2 ) ;
357
+ const verticalHitslop = SIZE_TO_VERTICAL_HITSLOP [ this . props . size || DEFAULT_SIZE ] / 2 ;
358
+
359
+ return {
360
+ top : verticalHitslop ,
361
+ bottom : verticalHitslop ,
362
+ left : horizontalHitslop ,
363
+ right : horizontalHitslop
364
+ } ;
365
+ }
366
+
342
367
render ( ) {
343
368
const { onPress, disabled, style, testID, animateLayout, modifiers, forwardedRef, ...others } = this . props ;
344
369
const shadowStyle = this . getShadowStyle ( ) ;
@@ -373,6 +398,7 @@ class Button extends PureComponent<Props, ButtonState> {
373
398
testID = { testID }
374
399
{ ...others }
375
400
ref = { forwardedRef }
401
+ hitSlop = { this . getAccessibleHitSlop ( ) }
376
402
>
377
403
{ this . props . children }
378
404
{ this . props . iconOnRight ? this . renderLabel ( ) : this . renderIcon ( ) }
0 commit comments