Skip to content

Commit

Permalink
Merge pull request #2892 from unoplatform/dev/cdb/bugs/android-layout…
Browse files Browse the repository at this point in the history
…-cache

fix(android): Fix for bug #2879
  • Loading branch information
carldebilly authored Mar 31, 2020
2 parents 762c64e + 58bc764 commit 2d3598b
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 10 deletions.
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 @@ -421,6 +421,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\UIElementTests\UIElement_Layout_Bug2879.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\UIElementTests\UIElement_Layout_Constrains.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -3334,6 +3338,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\UIElementTests\UIElement_ArrangeOverride_Alignment.xaml.cs">
<DependentUpon>UIElement_ArrangeOverride_Alignment.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\UIElementTests\UIElement_Layout_Bug2879.xaml.cs">
<DependentUpon>UIElement_Layout_Bug2879.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\UIElementTests\UIElement_Layout_Constrains.xaml.cs">
<DependentUpon>UIElement_Layout_Constrains.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace UITests.Windows_UI_Xaml.Clipping
{
[SampleControlInfo]
[Sample("Clipping", "GH Bugs")]
public sealed partial class ButtonClipping652 : Page
{
public ButtonClipping652()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<Page
x:Class="UITests.Windows_UI_Xaml.UIElementTests.UIElement_Layout_Bug2879"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<StackPanel VerticalAlignment="Center" Spacing="8" MaxWidth="350">
<TextBlock>
This is an illustration of
<Hyperlink NavigateUri="https://github.com/unoplatform/uno/issues/2879">Bug #2879</Hyperlink>.
To trigger the bug, press few times on the follow button:
</TextBlock>
<ToggleButton Background="LightGray"
x:Name="toggle"
HorizontalAlignment="Center">Change State</ToggleButton>
<Grid Background="Gray"
Margin="8,3,8,15"
Padding="0,6,0,13"
CornerRadius="13"
MinHeight="80">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<StackPanel Background="Gold"
Padding="20,5">
<TextBlock FontSize="20" Text="qwertyuiopasdfghjklxcvbnmqwertyu" HorizontalAlignment="Left" TextWrapping="Wrap" />
</StackPanel>

<StackPanel Background="Red"
Visibility="{Binding IsChecked, ElementName=toggle}"
Grid.Column="1"
Width="100" />
</Grid>
<TextBlock>State OFF (should be like this when unpressed)</TextBlock>
<Grid Background="Gray"
Margin="8,3,8,15"
Padding="0,6,0,13"
CornerRadius="13"
MinHeight="80">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<StackPanel Background="Gold"
Padding="20,5">
<TextBlock FontSize="20" Text="qwertyuiopasdfghjklxcvbnmqwertyu" HorizontalAlignment="Left" TextWrapping="Wrap" />
</StackPanel>

<StackPanel Background="Red"
Visibility="Collapsed"
Grid.Column="1"
Width="100" />
</Grid>
<TextBlock>State ON (should be like this when pressed)</TextBlock>
<Grid Background="Gray"
Margin="8,3,8,15"
Padding="0,6,0,13"
CornerRadius="13"
MinHeight="80">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<StackPanel Background="Gold"
Padding="20,5">
<TextBlock FontSize="20" Text="qwertyuiopasdfghjklxcvbnmqwertyu" HorizontalAlignment="Left" TextWrapping="Wrap" />
</StackPanel>

<StackPanel Background="Red"
Grid.Column="1"
Width="100" />
</Grid>

</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Uno.UI.Samples.Controls;
using Windows.UI.Xaml.Controls;

namespace UITests.Windows_UI_Xaml.UIElementTests
{
[Sample("UIElement", "GH Bugs")]
public sealed partial class UIElement_Layout_Bug2879 : Page
{
public UIElement_Layout_Bug2879()
{
this.InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace UITests.Shared.Windows_UI_Xaml_Controls.GridTestsControl
{
[SampleControlInfo(category: "GridTestsControl")]
[Sample("GridTestsControl", "GH Bugs")]
public sealed partial class Grid_with_MinWidthColumns : Page
{
public Grid_with_MinWidthColumns()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace UITests.Windows_UI_Xaml_Controls.ImageTests
{
[SampleControlInfo(category: "Image")]
[Sample("Image", "GH Bugs")]
public sealed partial class ImageAlignment2541 : Page
{
public ImageAlignment2541()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace UITests.Windows_UI_Xaml_Shapes
{
[SampleControlInfo("Shapes")]
[Sample("Shapes", "GH Bugs")]
public sealed partial class EllipseAlignment2542_2547 : Page
{
public EllipseAlignment2542_2547()
Expand Down
11 changes: 11 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Layouter/Layouter.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ protected Size MeasureChildOverride(View view, Size slotSize)
var widthSpec = ViewHelper.SpecFromLogicalSize(slotSize.Width);
var heightSpec = ViewHelper.SpecFromLogicalSize(slotSize.Height);

if (double.IsPositiveInfinity(slotSize.Width) || double.IsPositiveInfinity(slotSize.Height))
{
// Bypass Android cache, to ensure the Child's Measure() is actually invoked.
view.ForceLayout();

// This could occur when one of the dimension is _Infinite_: Android will cache the
// value, which is not something we want. Specially when the container is a <StackPanel>.

// Issue: https://github.com/unoplatform/uno/issues/2879
}

MeasureChild(view, widthSpec, heightSpec);

var ret = Uno.UI.Controls.BindableView.GetNativeMeasuredDimensionsFast(view)
Expand Down
4 changes: 0 additions & 4 deletions src/Uno.UI/UI/Xaml/FrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ static class TraceProvider
private bool _styleChanging = false;
private bool _defaultStyleApplied = false;

internal bool RequiresArrange { get; private set; }

internal bool RequiresMeasure { get; private set; }

/// <summary>
/// Sets whether constraint-based optimizations are used to limit redrawing of the entire visual tree on Android. This can be
/// globally set to false if it is causing visual errors (eg views not updating properly). Note: this can still be overridden by
Expand Down
4 changes: 4 additions & 0 deletions src/Uno.UI/UI/Xaml/FrameworkElement.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public partial class FrameworkElement

partial void Initialize();

internal bool RequiresArrange { get; private set; }

internal bool RequiresMeasure { get; private set; }

public override void SetNeedsLayout()
{
if (!_inLayoutSubviews)
Expand Down
4 changes: 4 additions & 0 deletions src/Uno.UI/UI/Xaml/FrameworkElement.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public partial class FrameworkElement

partial void Initialize();

internal bool RequiresArrange { get; private set; }

internal bool RequiresMeasure { get; private set; }

public override bool NeedsLayout
{
set
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Shapes/Polygon.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ protected override Android.Graphics.Path GetPath(Size availableSize)
{
var coords = Points;

if (coords == null)
if (coords == null || coords.Count <= 1)
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Shapes/Polyline.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ protected override Android.Graphics.Path GetPath(Size availableSize)
{
var coords = Points;

if (coords == null)
if (coords == null || coords.Count <= 1)
{
return null;
}
Expand Down

0 comments on commit 2d3598b

Please sign in to comment.