Skip to content

Commit

Permalink
Merge pull request #18412 from unoplatform/dev/jela/layout-workaround
Browse files Browse the repository at this point in the history
Revert #18381 for layout android issues
  • Loading branch information
jeromelaban authored Oct 9, 2024
2 parents a0d9fa8 + 5556f7d commit ad68653
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 54 deletions.
3 changes: 3 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@
<!-- Workaround for https://github.com/dotnet/runtime/issues/103205 -->
<NoWarn>$(NoWarn);CS0436</NoWarn>

<!-- Disable checks as we're on a release branch -->
<NoWarn>$(NoWarn);NU1903</NoWarn>

<!-- On CI, UWP source is generated in a job running on Windows (CRLF EOLs). -->
<!-- When the artifacts are downloaded in a job running on Linux, IDE0055 will complain (expecting LF EOLs) -->
<!-- For now, we skip formatting in CI UWP builds not running on Windows -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,11 +938,7 @@ public async Task When_InvalidatingMeasureExplicitly()

using var _ = new AssertionScope();

#if __ANDROID__
ctl1.MeasureCount.Should().Be(2);
#else
ctl1.MeasureCount.Should().Be(1);
#endif
ctl2.MeasureCount.Should().Be(2);
ctl3.MeasureCount.Should().Be(1);

Expand Down
5 changes: 0 additions & 5 deletions src/Uno.UI/Extensions/ViewExtensions.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using Android.Views.Animations;
using Microsoft.UI.Xaml.Controls;
using Uno.UI.Controls;
using Microsoft.UI.Xaml.Media;

namespace Uno.UI
{
Expand Down Expand Up @@ -706,10 +705,6 @@ public static string ShowLocalVisualTree(this ViewGroup viewGroup, int fromHeigh
{
root = parent;
}
else if (root is DependencyObject @do && VisualTreeHelper.GetParent(@do) is ViewGroup managedParent)
{
root = managedParent;
}
else
{
break;
Expand Down
13 changes: 12 additions & 1 deletion src/Uno.UI/UI/Xaml/DependencyObjectStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,18 @@ private void CleanupInheritedProperties()
return (localProperty, propertyDetails);
}
}
else if (property.IsAttached && property.IsInherited)
else if (property.IsAttached
&& property.IsInherited

#if __ANDROID__
// This is a workaround related to property inheritance and
// https://github.com/unoplatform/uno/pull/18261.
// Removing this line can randomly produce elements not rendering
// properly, such as TextBlock not measure/arrange properly
// even when invalidated.
&& _properties.FindPropertyDetails(property) is { }
#endif
)
{
return (property, _properties.GetPropertyDetails(property));
}
Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI/UI/Xaml/ILayouterElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ internal static bool DoMeasure(this ILayouterElement element, Size availableSize
// TODO: This is NOT correct.
// We shouldn't return here. Skipping children measure is incorrect but fixing it on Android isn't trivial.
return true;

}

// The measure dirty flag is set on one of the descendents:
Expand Down
25 changes: 0 additions & 25 deletions src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,31 +393,6 @@ internal static void AddChild(UIElement view, UIElement child)
{
#if __ANDROID__
view.AddView(child);

// Reset to original (invalidated) state
child.ResetLayoutFlags();
if (view.IsMeasureDirtyPathDisabled)
{
FrameworkElementHelper.SetUseMeasurePathDisabled(child); // will invalidate too
}
else
{
child.InvalidateMeasure();
}

if (view.IsArrangeDirtyPathDisabled)
{
FrameworkElementHelper.SetUseArrangePathDisabled(child); // will invalidate too
}
else
{
child.InvalidateArrange();
}

// Force a new measure of this element (the parent of the new child)
view.InvalidateMeasure();
view.InvalidateArrange();

#elif __IOS__ || __MACOS__
view.AddSubview(child);
#elif __CROSSRUNTIME__
Expand Down
19 changes: 0 additions & 19 deletions src/Uno.UI/UI/Xaml/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,25 +1155,6 @@ public void InvalidateMeasure()
// Use a non-virtual version of the RequestLayout method, for performance.
base.RequestLayout();
SetLayoutFlags(LayoutFlag.MeasureDirty);

// HACK: Android's implementation of measure/arrange is not accurate. See comments in LayouterElementExtensions.DoMeasure
global::Android.Views.IViewParent parent = this;
parent = parent.Parent;
while (parent is not null)
{
if (parent is UIElement parentAsUIElement)
{
parentAsUIElement.InvalidateMeasure();
break;
}
else
{
parent.RequestLayout();
}

parent = parent.Parent;
}

#elif __IOS__
SetNeedsLayout();
SetLayoutFlags(LayoutFlag.MeasureDirty);
Expand Down

0 comments on commit ad68653

Please sign in to comment.