Skip to content

Commit

Permalink
Fix ComboBox should not stretch to the full window width
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Mar 4, 2020
1 parent 0c41cbc commit 52b99af
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/ReleaseNotes/_ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
- #2570 [Android/iOS] fixed ObjectDisposedException in BindingPath
- #2107 [iOS] fixed ContentDialog doesn't block touch for background elements
- #2108 [iOS/Android] fixed ContentDialog background doesn't change
- #2680 [Wasm] Fix ComboBox should not stretch to the full window width

## Release 2.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,26 @@ public void ComboBoxTests_VisibleBounds()
// compensates for a possible change of origins with android popups.
Assert.AreEqual(popupLocationDifference - sampleControlResultExtended.Rect.Y, popupLocationDifferenceExtended);
}


[Test]
[AutoRetry]
public void ComboBoxTests_Stretch()
{
Run("UITests.Windows_UI_Xaml_Controls.ComboBox.ComboBox_Stretch");

var combo01 = _app.Marked("combo01");
var sampleControl = _app.Marked("sampleControl");
var changeExtended = _app.Marked("changeExtended");

var resourcesFilterResult = _app.WaitForElement(combo01).First();
var sampleControlResult = _app.WaitForElement(sampleControl).First();

_app.FastTap(combo01);

var popupResult = _app.WaitForElement("PopupBorder").First();

Assert.IsTrue(popupResult.Rect.Width < sampleControlResult.Rect.Width / 2, "The popup should not stretch to the width of the screen");
}
}
}
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ComboBox\ComboBox_Stretch.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ComboBox\ComboBox_VisibleBounds.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -3336,6 +3340,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ComboBox\ComboBox_DropDownPlacement.xaml.cs">
<DependentUpon>ComboBox_DropDownPlacement.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ComboBox\ComboBox_Stretch.xaml.cs">
<DependentUpon>ComboBox_Stretch.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ComboBox\ComboBox_VisibleBounds.xaml.cs">
<DependentUpon>ComboBox_VisibleBounds.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Page x:Class="UITests.Windows_UI_Xaml_Controls.ComboBox.ComboBox_Stretch"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml_Controls.ComboBox"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
Width="100"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<ComboBox x:Name="combo01"
Grid.Row="0"
HorizontalAlignment="Stretch">
<x:String>Item 1</x:String>
<x:String>Item 2 Item 2</x:String>
<x:String>Item 3 Item 3 Item 3</x:String>
<x:String>Item 4 Item 4 Item 4 Item 4</x:String>
</ComboBox>
<ComboBox x:Name="combo02"
Grid.Row="1" />
</Grid>

</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.UI.Samples.Controls;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace UITests.Windows_UI_Xaml_Controls.ComboBox
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
[SampleControlInfo("ComboBox")]
sealed partial class ComboBox_Stretch : Page
{
public ComboBox_Stretch()
{
this.InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ namespace Windows.UI.Xaml.Controls
{
abstract partial class VirtualizingPanelLayout : IScrollSnapPointsInfo
{
/// <summary>
/// Determines if the owner Panel is inside a popup. Used to determine
/// if the computation of the breadth should be using the parent's stretch
/// modes.
/// Related: https://github.com/unoplatform/uno/issues/135
/// </summary>
private bool IsInsidePopup { get; set; }

protected enum RelativeHeaderPlacement { Inline, Adjacent }

/// <summary>
Expand Down Expand Up @@ -124,6 +132,11 @@ public bool ShouldBreadthStretch
return true;
}

if (IsInsidePopup)
{
return false;
}

if (ScrollOrientation == Orientation.Vertical)
{
return XamlParent.HorizontalAlignment == HorizontalAlignment.Stretch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ private void OnLoaded(object sender, RoutedEventArgs e)
}
}

var hasPopupPanelParent = OwnerPanel.FindFirstParent<PopupPanel>() != null;
var hasListViewParent = OwnerPanel.FindFirstParent<ListViewBase>() != null;
IsInsidePopup = hasPopupPanelParent && !hasListViewParent;

if (this.Log().IsEnabled(LogLevel.Debug))
{
this.Log().LogDebug($"Calling {GetMethodTag()} hasPopupPanelParent={hasPopupPanelParent} hasListViewParent={hasListViewParent}");
}

if (
ItemsControl == null
&& OwnerPanel.TemplatedParent is ItemsControl popupItemsControl
Expand Down Expand Up @@ -398,7 +407,7 @@ private Size EstimatePanelSize(bool isMeasure)

if (this.Log().IsEnabled(LogLevel.Debug))
{
this.Log().LogDebug($"{GetMethodTag()} => {extent} -> {ret} {ScrollOrientation} {_availableSize.Height} {double.IsInfinity(_availableSize.Height)} AvailableBreadth:{AvailableBreadth}");
this.Log().LogDebug($"{GetMethodTag()} => {extent} -> {ret} {ScrollOrientation} {_availableSize.Height} {double.IsInfinity(_availableSize.Height)} ShouldBreadthStretch:{ShouldBreadthStretch} XamlParent:{XamlParent} AvailableBreadth:{AvailableBreadth}");
}

return ret;
Expand Down

0 comments on commit 52b99af

Please sign in to comment.