Skip to content

Commit

Permalink
Merge pull request #18457 from unoplatform/mergify/bp/release/stable/…
Browse files Browse the repository at this point in the history
…5.5/pr-18443

chore: ITemplatedParentProvider removal (backport #18443)
  • Loading branch information
jeromelaban authored Oct 13, 2024
2 parents 27b82a9 + 98b86ef commit e0a3158
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ internal partial class Inner : DependencyObject
partial class OuterClass
{
[global::Microsoft.UI.Xaml.Data.Bindable]
partial class Inner : IDependencyObjectStoreProvider, ITemplatedParentProvider, IWeakReferenceProvider
partial class Inner : IDependencyObjectStoreProvider, IWeakReferenceProvider
{
private DependencyObjectStore __storeBackingField;
public global::Windows.UI.Core.CoreDispatcher Dispatcher => global::Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher;
Expand All @@ -185,28 +185,6 @@ private DependencyObjectStore __Store
public object GetAnimationBaseValue(DependencyProperty dp) => __Store.GetAnimationBaseValue(dp);
public long RegisterPropertyChangedCallback(DependencyProperty dp, DependencyPropertyChangedCallback callback) => __Store.RegisterPropertyChangedCallback(dp, callback);
public void UnregisterPropertyChangedCallback(DependencyProperty dp, long token) => __Store.UnregisterPropertyChangedCallback(dp, token);

[EditorBrowsable(EditorBrowsableState.Never)]private ManagedWeakReference _templatedParentWeakRef;
[EditorBrowsable(EditorBrowsableState.Never)]public ManagedWeakReference GetTemplatedParentWeakRef() => _templatedParentWeakRef;

[EditorBrowsable(EditorBrowsableState.Never)]public DependencyObject GetTemplatedParent() => _templatedParentWeakRef?.Target as DependencyObject;
[EditorBrowsable(EditorBrowsableState.Never)]public void SetTemplatedParent(DependencyObject parent)
{
//if (parent != null)
//{
// global::System.Diagnostics.Debug.Assert(parent
// is global::Windows.UI.Xaml.Controls.Control
// or global::Windows.UI.Xaml.Controls.ContentPresenter
// or global::Windows.UI.Xaml.Controls.ItemsPresenter);
// global::System.Diagnostics.Debug.Assert(GetTemplatedParent() == null);
//}

SetTemplatedParentImpl(parent);
}
[EditorBrowsable(EditorBrowsableState.Never)]private protected virtual void SetTemplatedParentImpl(DependencyObject parent)
{
_templatedParentWeakRef = (parent as IWeakReferenceProvider)?.WeakReference;
}

private readonly static IEventProvider _binderTrace = Tracing.Get(DependencyObjectStore.TraceProvider.Id);
private BinderReferenceHolder _refHolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,15 @@ private void ProcessType(INamedTypeSymbol typeSymbol)
}
};

var canBeTpProvider = !typeSymbol.Interfaces.Any(x => x.Name == "INotTemplatedParentProvider");

var implementations = new string?[]
{
"IDependencyObjectStoreProvider",
_isUnoSolution && !typeSymbol.IsSealed ? "IDependencyObjectInternal" : null,
canBeTpProvider ? "ITemplatedParentProvider" : null,
"IWeakReferenceProvider",
}.Where(x => x is not null);
using (typeSymbol.AddToIndentedStringBuilder(builder, beforeClassHeaderAction, afterClassHeader: " : " + string.Join(", ", implementations)))
{
GenerateDependencyObjectImplementation(typeSymbol, builder, hasDispatcherQueue: _dependencyObjectSymbol!.GetMembers("DispatcherQueue").Any(), canBeTpProvider);
GenerateDependencyObjectImplementation(typeSymbol, builder, hasDispatcherQueue: _dependencyObjectSymbol!.GetMembers("DispatcherQueue").Any());
GenerateIBinderImplementation(typeSymbol, builder);
}

Expand Down Expand Up @@ -768,7 +765,7 @@ public override bool Equals(object other)
}
}

private void GenerateDependencyObjectImplementation(INamedTypeSymbol typeSymbol, IndentedStringBuilder builder, bool hasDispatcherQueue, bool implTpProvider)
private void GenerateDependencyObjectImplementation(INamedTypeSymbol typeSymbol, IndentedStringBuilder builder, bool hasDispatcherQueue)
{
builder.AppendLineIndented(@"private DependencyObjectStore __storeBackingField;");
builder.AppendLineIndented(@"public global::Windows.UI.Core.CoreDispatcher Dispatcher => global::Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher;");
Expand Down Expand Up @@ -818,37 +815,6 @@ private void GenerateDependencyObjectImplementation(INamedTypeSymbol typeSymbol,
builder.AppendLineIndented("internal virtual void OnPropertyChanged2(global::Microsoft.UI.Xaml.DependencyPropertyChangedEventArgs args) { }");
}
}

if (implTpProvider)
{
var unoBrowsableOnly = _isUnoSolution ? null : "[EditorBrowsable(EditorBrowsableState.Never)]";

builder.AppendLine();
builder.AppendMultiLineIndented($$"""
{{unoBrowsableOnly}}private ManagedWeakReference _templatedParentWeakRef;
{{unoBrowsableOnly}}public ManagedWeakReference GetTemplatedParentWeakRef() => _templatedParentWeakRef;

{{unoBrowsableOnly}}public DependencyObject GetTemplatedParent() => _templatedParentWeakRef?.Target as DependencyObject;
{{unoBrowsableOnly}}public void SetTemplatedParent(DependencyObject parent)
{
//if (parent != null)
//{
// global::System.Diagnostics.Debug.Assert(parent
// is global::Windows.UI.Xaml.Controls.Control
// or global::Windows.UI.Xaml.Controls.ContentPresenter
// or global::Windows.UI.Xaml.Controls.ItemsPresenter);
// global::System.Diagnostics.Debug.Assert(GetTemplatedParent() == null);
//}

SetTemplatedParentImpl(parent);
}
{{unoBrowsableOnly}}{{(typeSymbol.IsSealed ? "private" : "private protected virtual")}} void SetTemplatedParentImpl(DependencyObject parent)
{
_templatedParentWeakRef = (parent as IWeakReferenceProvider)?.WeakReference;
}
"""
);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI.Maps/MapPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void UpdateOwnerSubscriptions()
{
_ownerSubscription.Disposable = null;

_owner = GetTemplatedParent() as MapControl;
_owner = this.GetTemplatedParent() as MapControl;

if (_owner != null)
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -289,27 +289,6 @@ public async Task VisualStateGroup_TP_Inheritance()
""";
VerifyTree(expectations, setup, checkVSG: true);
}

#if HAS_UNO
[TestMethod]
public async Task LegacyDO_StillSupports_TP_Injection()
{
var setup = new BehaviorSetup();
await UITestHelper.Load(setup, x => x.IsLoaded);

var button = setup.Content as Button ?? throw new Exception("button not found");
var grid = button.GetTemplateRoot() ?? throw new Exception("template root not found");
var collection = Interaction.GetBehaviors(grid) ?? throw new Exception("behavior collection not found");

var sut0 = collection.ElementAtOrDefault(0) as LegacyDOBehavior;

// Verify that "legacy DepObj"(DO from library built before templated-parent rework)
// 1. is simulated correctly via the "INotTemplatedParentProvider" blocker
Assert.IsNotInstanceOfType<ITemplatedParentProvider>(sut0, "sut0 shouldnt impl ITemplatedParentProvider");
// 2. still supports tp-injection.
Assert.AreEqual(button.Tag, sut0.TestValue, "sut0.TestValue template-binding failed");
}
#endif
}
public partial class TemplatedParentTests // helper methods
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Shapes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MUXControlsTestApp.Utilities;
using Uno.Extensions;
using Uno.UI.Extensions;
using Uno.UI.RuntimeTests.Helpers;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml;

Expand Down Expand Up @@ -30,4 +38,45 @@ public async Task When_Transition_Modifies_SubProperty_Of_Property_Set_By_Previo
await Task.Delay(1000);
Assert.AreEqual(Microsoft.UI.Colors.Red, ((SolidColorBrush)border.Background).Color);
}

[TestMethod]
public async Task SelectorItem_SelectedState()
{
var items = Enumerable.Range(0, 3).ToArray();
var setup = new GridView
{
ItemsSource = items,
SelectedItem = items.Last(),
};
await UITestHelper.Load(setup);

var container2 = setup.ContainerFromIndex(2) as GridViewItem ?? throw new Exception("Failed to retrieve container at index 2");

// check if the visual-state is set
var states = VisualStateHelper.GetCurrentVisualStateName(container2).ToArray();
Assert.IsTrue(states.Contains("Selected"), $"container2 is not in 'Selected' state: states={states.JoinBy(",")}");
}

[TestMethod]
public Task SelectorItem_MultiSelectState_GV() => SelectorItem_MultiSelectState_Impl<GridView>();

[TestMethod]
public Task SelectorItem_MultiSelectState_LV() => SelectorItem_MultiSelectState_Impl<ListView>();

public async Task SelectorItem_MultiSelectState_Impl<T>() where T : ListViewBase, new()
{
var items = Enumerable.Range(0, 3).ToArray();
var setup = new T
{
ItemsSource = items,
SelectionMode = ListViewSelectionMode.Multiple,
};
await UITestHelper.Load(setup);

var container2 = setup.ContainerFromIndex(2) as SelectorItem ?? throw new Exception("Failed to retrieve container at index 2");

// check if the visual-state is set
var states = VisualStateHelper.GetCurrentVisualStateName(container2).ToArray();
Assert.IsTrue(states.Contains("MultiSelectEnabled"), $"container2 is not in 'MultiSelectEnabled' state: states={states.JoinBy(",")}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using static Private.Infrastructure.TestServices;
using Uno.UI.Extensions;
using Microsoft.UI.Xaml.Controls.Primitives;
using Uno.UI.RuntimeTests.Helpers;

namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
{
Expand Down Expand Up @@ -126,6 +127,24 @@ public async Task Check_Changing_SelectedItem_Affects_SelectedIndex()
SUT.SelectedItem.Should().Be(pivotItem2);
}

[TestMethod]
[RunsOnUIThread]
public async Task Pivot_Single_ItemContent_Visible()
{
var items = Enumerable.Range(0, 3).ToArray();
var setup = new Pivot
{
ItemsSource = items,
SelectedItem = items.Last(),
};
await UITestHelper.Load(setup);

var containers = items.Select((x, i) => setup.ContainerFromIndex(i)).OfType<PivotItem>().ToArray();

Assert.AreEqual(3, containers.Length, "Should have 3 containers");
Assert.AreEqual(1, containers.Count(x => x.Visibility == Visibility.Visible), "Only one PivotItem should be visible");
}

private class MyContext
{
public MyContext()
Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
[assembly: InternalsVisibleTo("Uno.UI.Svg")]
[assembly: InternalsVisibleTo("Uno.UI.Svg.Skia")]
[assembly: InternalsVisibleTo("Uno.UI.XamlHost")]
[assembly: InternalsVisibleTo("Uno.UI.Maps")]
[assembly: InternalsVisibleTo("SamplesApp")]
[assembly: InternalsVisibleTo("SamplesApp.Droid")]
[assembly: InternalsVisibleTo("SamplesApp.macOS")]
Expand Down
Loading

0 comments on commit e0a3158

Please sign in to comment.