Bubble padding is no longer working in version 2.3.1
Closed this issue · 14 comments
i am hitting it also.
The Release Notes of 2.3.1 are incomplete by only referring to:
Fixes issue in iOS 11 where tooltip would not display when presenting via a UIBarButtonItem.
When I look at the master, 2.3.0 was commit 176, while 2.3.1 is 199. So there are many more changes in 2.3.1.
Commits 185 and 186 refer to a new property for padding.
The change log of commit 186 c9ab6ae shows indeed new property shouldEnforceCustomViewPadding
.
I see it's never initialised, except in initWithCustomView:
which we don't use.
We have reverted back to 2.3.0.
@TingtingAn Can you try with shouldEnforceCustomViewPadding = YES
?
i have never to use initWithCustomView
also
Using sidePadding = 10.0
and shouldEnforceCustomViewPadding = YES
worked for me in 2.3.1
@pventura1976 Thanks for confirming this.
This seems to be a bug.
Why is it required when setting property sidePadding
to explicitly set shouldEnforceCustomViewPadding
?
At least there is a work-around now, but it doesn't make sense.
Hey @FungusHumungus @pventura1976 I'm really sorry for the mistake. Perhaps I should have set shouldEnforceCustomViewPadding
and sidePadding
to be on by default in v2.3.2
. What do you think?
@kleinlieu Thanks for your reaction. Before jumping to a solution; what is the purpose of new property shouldEnforceCustomViewPadding
?
I would say that if a user wants to have padding, he defines sidePadding
.
If he uses property customView
and wants padding, he defines both customView
and sidePadding
.
For me it's not clear what shouldEnforceCustomViewPadding
should control.
It seems to be some unnecessary BOOL introduced for the custom view.
But in my opinion it can be completely deleted.
It is now used as IF condition in - (CGRect)contentFrame
and - (void)presentPointingAtView:(UIView *)targetView inView:(UIView *)containerView animated:(BOOL)animated
.
The IF condition can be replaced by:
if (_sidePadding > 0) {
Do you agree?
UPDATE This probably won't work, as - (CGRect)contentFrame
uses bubblePaddingX
and bubblePaddingY
, see my next comment. But then I don't understand why the padding works properly for @pventura1976 when shouldEnforceCustomViewPadding
is set to YES.
Another over dimension seems to be the parameters bubblePaddingX
and bubblePaddingY
. What is the difference with sidePadding
?
It would really help if all (less obvious) properties could have proper documentation in the header file. I bet that this would have prevented code implementation issues like this one. Because now there is clearly a misunderstanding of the meaning/definition of some properties.
I'm happy to assist with this, but at least someone needs to explain these properties.
BTW, sidePadding
is already set to a default value of 2.0 in - (id)initWithFrame:(CGRect)frame
.
As mentioned before, we need to know the functionality first.
I figured it out by playing around with the DEMO project.
IMPORTANT
I was able to change sidePadding
in the default DEMO project, where shouldEnforceCustomViewPadding
is disabled.
In order to see the proper effect of cornerRadius
, bubblePaddingX
and bubblePaddingY
I had to enable shouldEnforceCustomViewPadding
.
Hence I changed the title if this issue from Property "sidePadding" to Bubble padding.
It's worth noting that I was mistaking sidePadding
with the inner bubble padding, i.e. the offset between the text and the bubble boundary. After playing around with the DEMO project I learned that this bubble padding is controlled by cornerRadius
, bubblePaddingX
and bubblePaddingY
.
There are 5 properties playing a role:
sidePadding
This is the horizontal offset between the bubble and the view boundary:
The default value is 2. In the above screenshot it was set to 10.cornerRadius
This will round the corners:
But it also increases the bubble around the text. See the difference with the previous image when increasing the value:
The default value is 10.bubblePaddingX
This is the horizontal offset between the bubble text and the bubble boundary:
IMPORTANT: WhencornerRadius
>0 it's added tobubblePaddingX
, so the horizontal offset is the total of both properties.
The default value is 0. When this value >0, the horizontal bubble size increases.bubblePaddingY
This is the vertical offset between the bubble text and the bubble boundary:
IMPORTANT: WhencornerRadius
>0 it's added tobubblePaddingY
, so the vertical offset is the total of both properties.
The default value is 0. When this value >0, the vertical bubble size increases.shouldEnforceCustomViewPadding
This seems to be an unnecessary internal property which currently causes this issue that bubble padding is not working.
SOLUTION
Now that the functionality of all involved properties is clear, the solution seems simple:
- Remove property
shouldEnforceCustomViewPadding
- In
- (CGRect)contentFrame
, the complete IF-ELSE can removed, as the IF statement should always be performed, as it contains all the 3 discussed properties:cornerRadius
,bubblePaddingX
andbubblePaddingY
:
- (CGRect)contentFrame {
CGRect bubbleFrame = [self bubbleFrame];
CGRect contentFrame = CGRectMake(bubbleFrame.origin.x + _cornerRadius + _bubblePaddingX,
bubbleFrame.origin.y + _cornerRadius + _bubblePaddingY,
bubbleFrame.size.width - (_bubblePaddingX*2) - (_cornerRadius*2),
bubbleFrame.size.height - (_bubblePaddingY*2) - (_cornerRadius*2));
return contentFrame;
}
- Similar in
- (void)presentPointingAtView:(UIView *)targetView inView:(UIView *)containerView animated:(BOOL)animated
the IF condition should always be performed, so remove IF-ELSE:
_bubbleSize = CGSizeMake(textSize.width + (_bubblePaddingX*2) + (_cornerRadius*2), textSize.height + (_bubblePaddingY*2) + (_cornerRadius*2));
Verification
I have verified the DEMO project after these 3 changes and now the bubble padding does properly work without changing anything to the DEMO code.
Recommendations
- Why does
cornerRadius
automatically apply bubble padding?
This is not common, see for examplecornerRadius
of CALayer.
If for a largercornerRadius
bubble padding is necessary, this can be configured viabubblePaddingX
andbubblePaddingY
. - Properly document each property in the header file.
- Be accurate with the Release Notes.
The Release Notes of 2.3.1 are incomplete by only referring to an iOS 11 fix for the tooltip on a UIBarButtonItem.
When looking at the master, it appears that there are many more changes in 2.3.1. Even new properties such as the erroneousshouldEnforceCustomViewPadding
and it's code that caused this issue.
I have created a pull request with the solution.
Should I make another with more documentation in the header file?
This is resolved as 2.3.2