Skip to content

Commit

Permalink
fix: Hotfix Tooltip and Popover RTL position error
Browse files Browse the repository at this point in the history
  • Loading branch information
Kypsis committed Mar 11, 2023
1 parent 0d9ccf5 commit 270b4eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
29 changes: 16 additions & 13 deletions lib/src/widgets/popover/popover.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ class MoonPopoverState extends State<MoonPopover> with RouteAware, SingleTickerP
void _handleTap(TapDownDetails details) {
final RenderBox? tooltipRenderBox = _popoverKey.currentContext?.findRenderObject() as RenderBox?;
final RenderBox? overlayRenderBox = Overlay.of(context).context.findRenderObject() as RenderBox?;
final tooltipPosition = tooltipRenderBox?.localToGlobal(Offset.zero, ancestor: overlayRenderBox);
final popoverPosition = tooltipRenderBox?.localToGlobal(Offset.zero, ancestor: overlayRenderBox);

if (tooltipPosition != null && !tooltipRenderBox!.size.contains(details.localPosition - tooltipPosition)) {
if (popoverPosition != null && !tooltipRenderBox!.size.contains(details.localPosition - popoverPosition)) {
_removePopover();
}
}
Expand Down Expand Up @@ -385,7 +385,9 @@ class MoonPopoverState extends State<MoonPopover> with RouteAware, SingleTickerP
final popoverTargetGlobalRight =
targetRenderBox.localToGlobal(targetRenderBox.size.centerRight(Offset.zero), ancestor: overlayRenderBox);

if (Directionality.of(context) == TextDirection.rtl) {
if (Directionality.of(context) == TextDirection.rtl ||
popoverPosition == MoonPopoverPosition.horizontal ||
popoverPosition == MoonPopoverPosition.vertical) {
switch (popoverPosition) {
case MoonPopoverPosition.left:
popoverPosition = MoonPopoverPosition.right;
Expand All @@ -405,18 +407,19 @@ class MoonPopoverState extends State<MoonPopover> with RouteAware, SingleTickerP
case MoonPopoverPosition.bottomRight:
popoverPosition = MoonPopoverPosition.bottomLeft;
break;

default:
}
} else if (popoverPosition == MoonPopoverPosition.horizontal || popoverPosition == MoonPopoverPosition.vertical) {
// Compute real popoverPosition based on target position
popoverPosition = (popoverPosition == MoonPopoverPosition.vertical)
? (popoverTargetGlobalCenter.dy < overlayRenderBox.size.center(Offset.zero).dy
case MoonPopoverPosition.vertical:
popoverPosition = popoverTargetGlobalCenter.dy < overlayRenderBox.size.center(Offset.zero).dy
? MoonPopoverPosition.bottom
: MoonPopoverPosition.top)
: (popoverTargetGlobalCenter.dx < overlayRenderBox.size.center(Offset.zero).dx
: MoonPopoverPosition.top;
break;
case MoonPopoverPosition.horizontal:
popoverPosition = popoverTargetGlobalCenter.dx < overlayRenderBox.size.center(Offset.zero).dx
? MoonPopoverPosition.right
: MoonPopoverPosition.left);
: MoonPopoverPosition.left;
break;
default:
break;
}
}

final popoverPositionParameters = _resolvePopoverPositionParameters(
Expand Down
25 changes: 14 additions & 11 deletions lib/src/widgets/tooltip/tooltip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ class MoonTooltipState extends State<MoonTooltip> with RouteAware, SingleTickerP
final tooltipTargetGlobalRight =
targetRenderBox.localToGlobal(targetRenderBox.size.centerRight(Offset.zero), ancestor: overlayRenderBox);

if (Directionality.of(context) == TextDirection.rtl) {
if (Directionality.of(context) == TextDirection.rtl ||
tooltipPosition == MoonTooltipPosition.horizontal ||
tooltipPosition == MoonTooltipPosition.vertical) {
switch (tooltipPosition) {
case MoonTooltipPosition.left:
tooltipPosition = MoonTooltipPosition.right;
Expand All @@ -446,18 +448,19 @@ class MoonTooltipState extends State<MoonTooltip> with RouteAware, SingleTickerP
case MoonTooltipPosition.bottomRight:
tooltipPosition = MoonTooltipPosition.bottomLeft;
break;

default:
}
} else if (tooltipPosition == MoonTooltipPosition.horizontal || tooltipPosition == MoonTooltipPosition.vertical) {
// Compute real tooltipPosition based on target position
tooltipPosition = (tooltipPosition == MoonTooltipPosition.vertical)
? (tooltipTargetGlobalCenter.dy < overlayRenderBox.size.center(Offset.zero).dy
case MoonTooltipPosition.vertical:
tooltipPosition = tooltipTargetGlobalCenter.dy < overlayRenderBox.size.center(Offset.zero).dy
? MoonTooltipPosition.bottom
: MoonTooltipPosition.top)
: (tooltipTargetGlobalCenter.dx < overlayRenderBox.size.center(Offset.zero).dx
: MoonTooltipPosition.top;
break;
case MoonTooltipPosition.horizontal:
tooltipPosition = tooltipTargetGlobalCenter.dx < overlayRenderBox.size.center(Offset.zero).dx
? MoonTooltipPosition.right
: MoonTooltipPosition.left);
: MoonTooltipPosition.left;
break;
default:
break;
}
}

final tooltipPositionParameters = _resolveTooltipPositionParameters(
Expand Down

0 comments on commit 270b4eb

Please sign in to comment.