Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Arrow height is included in tooltip height when arrow is not positioned at top or bottom #228

Open
RobinDaugherty opened this issue Jun 27, 2022 · 1 comment

Comments

@RobinDaugherty
Copy link

RobinDaugherty commented Jun 27, 2022

The tooltip is designed to include the arrow within its bounds, and the height of the arrow is included in that calculation

The quick fix is to use the configured arrowPosition to determine which dimension should be included, but arrowPosition is optional (.any is a valid option), and the configured arrow position is not always used.

There's no quick fix, but a workaround hack is to add content padding when using the tooltip:

// Compensate for a bug in EasyTipView which adds the height of the "arrow" to the height of the content bubble, which adds padding below the content
// In addition, and related to this, the arrow is included in the overall size of the tooltip, but not added to the overall size of the tooltip (unless it happens to be at the top or bottom, in which case the hard-coded addition of its height works in our favor).
// This is still tricky because when laying out inside of a specific superview, the arrow direction can be changed when the tooltip doesn't fit. Which means our padding hacking here will result in even worse layout problems.
let defaultPadding: CGFloat = 12
switch position {
case .left:
    tipPreferences.positioning.contentInsets = UIEdgeInsets(top: defaultPadding, left: defaultPadding + 4, bottom: defaultPadding - 4, right: defaultPadding)
case .right:
    tipPreferences.positioning.contentInsets = UIEdgeInsets(top: defaultPadding, left: defaultPadding, bottom: defaultPadding - 4, right: defaultPadding + 4)
case .top:
    tipPreferences.positioning.contentInsets = UIEdgeInsets(top: defaultPadding + 4, left: defaultPadding, bottom: defaultPadding - 4, right: defaultPadding)
case .bottom:
    tipPreferences.positioning.contentInsets = UIEdgeInsets(top: defaultPadding, left: defaultPadding, bottom: defaultPadding - 4, right: defaultPadding + 4)
default:
    fatalError("We can't support 'any' position until that bug is fixed")
}

This workaround is incompatible with .any position and will result in broken layout when the arrow position is changed because it doesn't fit (which seems to only be possible when a superview is specified).

The long-term fix could be:

  • Move the layout logic such as in arrange(withinSuperview:) out to the other places that need to be aware of the actual arrow position
  • Remove the arrow dimension from the tooltip dimensions, so the size of the bubble is the same regardless of the arrow, and then place the arrow outside of those dimensions. That would also allow a tooltip to be displayed without an arrow, which seems like a useful feature.
@dreamguagua
Copy link

because:
image
So you need to calculate the width for the position left and right.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants