When using custom icons for left/right buttons, the tappable area is significantly reduced as compared to native iOS icons.
Is there any way to improve the tappable area of custom buttons to extend to the edge of the screen and more vertically?
Example of the tappable area of native iOS icons created using :
rightButtons: [
{
id: "cart",
systemItem: "add"
color: "gray"
}
]
Versus the tappable area of custom icons created using:
rightButtons: [
{
id: "cart",
icon: images.shopping_cart,
color: "gray"
}
]
When using text for the buttons, they also have the full tappable area that native options do:
leftButtons: [
{
id: CLOSE_ID,
enabled: true,
color: "black",
text: "Cart",
},
],
I'm finding that if I make this change in RNNUIBarButtonItem.m
, I get a more tappable area. However, I'm still not able to get the button to be tappable to the edge of the device.
-(instancetype)init:(NSString*)buttonId withIcon:(UIImage*)iconImage {
UIButton* button = [[UIButton alloc] init];
[button addTarget:self action:@selector(onButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[button setImage:iconImage forState:UIControlStateNormal];
// Increase the rectangle to increase tappable area
[button setFrame:CGRectMake(0, 0, iconImage.size.width + 40, iconImage.size.height + 20)];
self = [super initWithCustomView:button];
self.buttonId = buttonId;
// Force the icon to align to the left of the rectangle
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
return self;
}
I went ahead and assigned @yogevbd because this is something we are also running into.
Yeap I'm running into this one too. If you have guys have some suggestions where I can start from I can take a look.
+1 for this!
This issue can be resolved by using the built-in initWithImage
instead of initWithCustomView
. If you use initWithImage
, you will have the tappable area like the built-in system icons so it covers the edge area.
Any reason for using initWithCustomView to set button icon?
Here is the fix:
In RNNUIBarButtonItem.m
-(instancetype)init:(NSString*)buttonId withIcon:(UIImage*)iconImage {
// ORGINAL:
//UIButton* button = [[UIButton alloc] init];
//[button addTarget:self action:@selector(onButtonPressed) forControlEvents:UIControlEventTouchUpInside];
//[button setImage:iconImage forState:UIControlStateNormal];
//[button setFrame:CGRectMake(0, 0, iconImage.size.width, iconImage.size.height)];
//self = [super initWithCustomView:button];
//self.buttonId = buttonId;
// FIX:
self = [super initWithImage:iconImage style:UIBarButtonItemStylePlain target:self action:@selector(onButtonPressed)];
self.buttonId = buttonId;
return self;
}
The same goes for custom components, not just icons. I hope this can be addressed :) Keep up the good work guys!
Same issue here :/
I hope this will be resolved soon.
backButton has a good hitSlop, would be cool to be able to set negative insets or something for left/right buttons
@minhloi your suggestion is really good. Should be changed in the source for sure
The solution from @minhloi worked for me as well.
PR at #6482
Most helpful comment
I went ahead and assigned @yogevbd because this is something we are also running into.