Skip to content

Commit

Permalink
fix: Disallow ComboBox popup under translucent status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Feb 6, 2023
1 parent 9a89af7 commit 391ae8e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/Uno.UI/FeatureConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public static class ComboBox
/// referencing the ** type ** ComboBox in any way.
/// </remarks>
public static Uno.UI.Xaml.Controls.DropDownPlacement DefaultDropDownPreferredPlacement { get; set; } = Uno.UI.Xaml.Controls.DropDownPlacement.Auto;

/// <summary>
/// Gets or sets a value indicating whether the combobox popup should be allowed
/// to be displayed under translucent status bar on Android. Defaults to false.
/// </summary>
public static bool AllowPopupUnderTranslucentStatusBar { get; set; }
}

public static class CompositionTarget
Expand Down
13 changes: 9 additions & 4 deletions src/Uno.UI/UI/Xaml/Controls/ComboBox/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public Size Measure(Size available, Size visibleSize)
private const int _itemsToShow = 9;

/// <inheritdoc />
public void Arrange(Size finalSize, Rect visibleBounds, Size desiredSize, Point? upperLeftLocation)
public void Arrange(Size finalSize, Rect visibleBounds, Size desiredSize)
{
var popup = Popup;
var combo = Combo;
Expand Down Expand Up @@ -852,13 +852,18 @@ Point getChildLocation()
this.Log().Debug($"Layout the combo's dropdown at {frame} (desired: {desiredSize} / available: {finalSize} / visible: {visibleBounds} / selected: {selectedIndex} of {itemsCount})");
}

if (upperLeftLocation is Point offset)
#if __ANDROID__
// Check whether the status bar is translucent
// If so, we may need to compensate for the origin location
var isTranslucent = Window.Current.IsStatusBarTranslucent();
var allowUnderStatusBar = FeatureConfiguration.ComboBox.AllowPopupUnderTranslucentStatusBar;
if (isTranslucent && allowUnderStatusBar)
{
// Compensate for origin location is some popup providers (Android
// is one, particularly when the status bar is translucent)
var offset = visibleBounds.Location;
frame.X -= offset.X;
frame.Y -= offset.Y;
}
#endif

child.Arrange(frame);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/Popup/Popup.Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ internal interface IDynamicPopupLayouter
/// <param name="visibleBounds">The frame of the visible bounds of the window. This is expected to be AtMost the finalSize.</param>
/// <param name="desiredSize">The size at which the content expect to be rendered. This is the result of the last <see cref="Measure"/>.</param>
/// <param name="upperLeftOffset">Coordinate system adjustment, applied to the resulting frame computed from the popup content</param>
void Arrange(Size finalSize, Rect visibleBounds, Size desiredSize, Point? upperLeftOffset = null);
void Arrange(Size finalSize, Rect visibleBounds, Size desiredSize);
}

partial void OnIsLightDismissEnabledChangedPartial(bool oldIsLightDismissEnabled, bool newIsLightDismissEnabled)
Expand Down
3 changes: 0 additions & 3 deletions src/Uno.UI/UI/Xaml/Controls/Popup/PopupPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,6 @@ Popup.PlacementTarget is not null
finalSize,
visibleBounds,
_lastMeasuredSize
#if __ANDROID__
, visibleBounds.Location
#endif
);

if (this.Log().IsEnabled(LogLevel.Debug))
Expand Down

0 comments on commit 391ae8e

Please sign in to comment.