Skip to content

Commit b1ada83

Browse files
committed
Revert "chore: Failling trial for Android/iOS. Keeping the commit just for future reference"
This reverts commit 02eada5.
1 parent 02eada5 commit b1ada83

11 files changed

+46
-142
lines changed

src/Uno.UI/Controls/BindableUIView.iOS.cs

-11
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,16 @@ public override void AddSubview(UIView view)
4747
// Instead we have to pre-update the _shadowChildren so handlers of the Loaded event will be able
4848
// to properly walk the tree up and down (cf. EffectiveViewport).
4949
_shadowChildren.Add(view);
50-
TryRegisterName(view);
5150
base.AddSubview(view);
5251
}
5352

5453
public override void InsertSubview(UIView view, nint atIndex)
5554
{
5655
// cf. AddSubview comment!
5756
_shadowChildren.Insert((int)atIndex, view);
58-
TryRegisterName(view);
5957
base.InsertSubview(view, atIndex);
6058
}
6159

62-
private void TryRegisterName(UIView view)
63-
{
64-
if (view is FrameworkElement { Name: { Length: > 0 } name } fe &&
65-
FindNameScope(fe) is { } nameScope)
66-
{
67-
nameScope.RegisterName(name, fe);
68-
}
69-
}
70-
7160
public override void WillRemoveSubview(UIView uiview)
7261
{
7362
// cf. AddSubview comment!

src/Uno.UI/UI/Xaml/EnterParams.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace Uno.UI.Xaml;
1+
#if UNO_HAS_ENHANCED_LIFECYCLE
2+
namespace Uno.UI.Xaml;
23

34
internal struct EnterParams
45
{
@@ -14,3 +15,4 @@ public EnterParams(bool isLive)
1415
IsLive = isLive;
1516
}
1617
}
18+
#endif

src/Uno.UI/UI/Xaml/FrameworkElement.Layout.crossruntime.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,14 @@ private void ArrangeNative(Point offset, Rect? clippedFrame)
902902
#endif
903903
}
904904

905+
private void AdjustNameScope(ref INameScope? nameScope)
906+
{
907+
if (NameScope.GetNameScope(this) is { } currentNameScope)
908+
{
909+
nameScope = currentNameScope;
910+
}
911+
}
912+
905913
internal override void Enter(INameScope? nameScope, EnterParams @params, int depth)
906914
{
907915
// This should happen regardless of whether Name is null or not.
@@ -914,9 +922,11 @@ internal override void Enter(INameScope? nameScope, EnterParams @params, int dep
914922
{
915923
var name = this.Name;
916924

917-
if (!string.IsNullOrEmpty(name))
925+
if (!string.IsNullOrEmpty(name) && nameScope.FindName(name) is null)
918926
{
919-
// NOTE: Multiple RegisterName calls can happen.
927+
// Ideally, we shouldn't be checking for null FindName.
928+
// But it's currently needed due to the way we
929+
// register names in namescopes which don't yet match WinUI completely.
920930
// Right now, XAML generator will do RegisterName calls, then, when we
921931
// enter the visual tree, we will be trying to register the name again.
922932
// However, registering in Enter is also very necessary in case C# is used
@@ -925,7 +935,7 @@ internal override void Enter(INameScope? nameScope, EnterParams @params, int dep
925935
// The RegisterName calls in XAML generator should probably happen via something
926936
// similar to WinUI's PostParseRegisterNames which will basically just do an "Enter" with
927937
// isLive being false. Then, the Enter happening in VisualTree.AddRoot should skip name registration.
928-
((NameScope)nameScope).RegisterNameNoWarn(name, this);
938+
nameScope.RegisterName(name, this);
929939
}
930940
}
931941

src/Uno.UI/UI/Xaml/FrameworkElement.cs

-63
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
using Uno.UI.Xaml.Controls;
2929
using Uno.UI.Xaml.Core;
3030
using Uno.UI.Xaml.Media;
31-
using Microsoft.UI.Xaml.Markup;
32-
3331

3432
#if __ANDROID__
3533
using View = Android.Views.View;
@@ -943,67 +941,6 @@ internal virtual void UpdateThemeBindings(ResourceUpdateReason updateReason)
943941
}
944942
}
945943

946-
private void AdjustNameScope(ref INameScope nameScope)
947-
{
948-
if (NameScope.GetNameScope(this) is { } currentNameScope)
949-
{
950-
nameScope = currentNameScope;
951-
}
952-
}
953-
954-
#if !UNO_HAS_ENHANCED_LIFECYCLE
955-
internal override void Enter(INameScope nameScope, EnterParams @params, int depth)
956-
{
957-
// This should happen regardless of whether Name is null or not.
958-
// What we need here is that once we find an element being entered that
959-
// has its own NameScope, then we start using this namescope and use it for entering its children.
960-
// For example, elements in a template where the template root will have its own NameScope.
961-
AdjustNameScope(ref nameScope);
962-
963-
if (nameScope is not null)
964-
{
965-
var name = this.Name;
966-
967-
if (!string.IsNullOrEmpty(name))
968-
{
969-
// NOTE: Multiple RegisterName calls can happen.
970-
// Right now, XAML generator will do RegisterName calls, then, when we
971-
// enter the visual tree, we will be trying to register the name again.
972-
// However, registering in Enter is also very necessary in case C# is used
973-
// instead of XAML (be it "regular" C# code or C# Markup).
974-
// So, we need to have RegisterName here.
975-
// The RegisterName calls in XAML generator should probably happen via something
976-
// similar to WinUI's PostParseRegisterNames which will basically just do an "Enter" with
977-
// isLive being false. Then, the Enter happening in VisualTree.AddRoot should skip name registration.
978-
((NameScope)nameScope).RegisterNameNoWarn(name, this);
979-
}
980-
}
981-
982-
base.Enter(nameScope, @params, depth);
983-
}
984-
985-
internal override void Leave(INameScope nameScope, LeaveParams @params)
986-
{
987-
// This should happen regardless of whether Name is null or not.
988-
// What we need here is that once we find an element leaving that
989-
// has its own NameScope, then we start using this namescope and use it for leaving its children.
990-
// For example, elements in a template where the template root will have its own NameScope.
991-
AdjustNameScope(ref nameScope);
992-
993-
if (nameScope is not null)
994-
{
995-
var name = this.Name;
996-
997-
if (!string.IsNullOrEmpty(name))
998-
{
999-
nameScope.UnregisterName(name);
1000-
}
1001-
}
1002-
1003-
base.Leave(nameScope, @params);
1004-
}
1005-
#endif
1006-
1007944
#region AutomationPeer
1008945
#if !__IOS__ && !__ANDROID__ && !__MACOS__ // This code is generated in FrameworkElementMixins
1009946
private AutomationPeer _automationPeer;

src/Uno.UI/UI/Xaml/Internal/VisualTree.cs

+2
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,15 @@ private void AddRoot(UIElement? root)
457457
MUX_ASSERT(RootElement != null);
458458
RootElement!.AddChild(root);
459459

460+
#if UNO_HAS_ENHANCED_LIFECYCLE
460461
EnterParams enterParams = new(
461462
isLive: true
462463
);
463464

464465
// In WinUI, this is called only under IsMainVisualTree condition.
465466
// This might be needed for now in Uno because RootVisual does not *yet* have XamlIslandRootCollection
466467
root.Enter(NameScope.GetNameScope(root), enterParams, 0);
468+
#endif
467469
}
468470
}
469471

src/Uno.UI/UI/Xaml/LeaveParams.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace Uno.UI.Xaml;
1+
#if UNO_HAS_ENHANCED_LIFECYCLE
2+
namespace Uno.UI.Xaml;
23

34
internal struct LeaveParams
45
{
@@ -14,3 +15,4 @@ public LeaveParams(bool isLive)
1415
IsLive = isLive;
1516
}
1617
}
18+
#endif

src/Uno.UI/UI/Xaml/NameScope.cs

+1-10
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,14 @@ public object FindName(string name)
4242

4343
public void RegisterName(string name, object scopedElement)
4444
{
45-
if (this.Log().IsEnabled(LogLevel.Warning) && _names.ContainsKey(name))
45+
if (_names.ContainsKey(name))
4646
{
4747
this.Log().Warn($"The name [{name}] already exists in the current XAML scope");
4848
}
4949

5050
_names[name] = WeakReferencePool.RentWeakReference(this, scopedElement);
5151
}
5252

53-
internal void RegisterNameNoWarn(string name, object scopedElement)
54-
{
55-
if (name == "textBox")
56-
{
57-
58-
}
59-
_names[name] = WeakReferencePool.RentWeakReference(this, scopedElement);
60-
}
61-
6253
public void UnregisterName(string name)
6354
{
6455
_names.Remove(name);

src/Uno.UI/UI/Xaml/UIElement.Android.cs

-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using Rect = Windows.Foundation.Rect;
1919
using Java.Interop;
2020
using Microsoft.UI.Xaml.Markup;
21-
using Uno.UI.Xaml;
2221

2322
namespace Microsoft.UI.Xaml
2423
{
@@ -66,7 +65,6 @@ protected override void OnChildViewAdded(View view)
6665
if (view is UIElement uiElement)
6766
{
6867
OnChildManagedViewAddedOrRemoved(uiElement);
69-
uiElement.Enter(FindNameScope(uiElement), default, default);
7068
}
7169
else
7270
{
@@ -82,7 +80,6 @@ protected override void OnChildViewRemoved(View view)
8280
if (view is UIElement uiElement)
8381
{
8482
OnChildManagedViewAddedOrRemoved(uiElement);
85-
uiElement.Leave(FindNameScope(uiElement), default);
8683
}
8784
else
8885
{

src/Uno.UI/UI/Xaml/UIElement.crossruntime.cs

+19
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,25 @@ internal Point GetPosition(Point position, UIElement relativeTo)
118118
=> TransformToVisual(relativeTo).TransformPoint(position);
119119

120120
#if UNO_HAS_ENHANCED_LIFECYCLE
121+
internal static INameScope FindNameScope(DependencyObject dependencyObject)
122+
{
123+
// In many cases, this will not traverse the entire visual tree, as the NameScope is often
124+
// present on each element as the DP is inherited. However, it can happen that the DP inheritance
125+
// didn't yet happen, in which case we'll traverse the tree up.
126+
var current = dependencyObject;
127+
while (current is not null)
128+
{
129+
if (NameScope.GetNameScope(current) is { } nameScope)
130+
{
131+
return nameScope;
132+
}
133+
134+
current = VisualTreeHelper.GetParent(current);
135+
}
136+
137+
return null;
138+
}
139+
121140
private void ChildEnter(UIElement child, EnterParams @params)
122141
{
123142
// Uno TODO: WinUI has much more complex logic than this.

src/Uno.UI/UI/Xaml/UIElement.cs

-19
Original file line numberDiff line numberDiff line change
@@ -1434,25 +1434,6 @@ internal void SetProtectedCursor(Microsoft /* UWP don't rename */.UI.Input.Input
14341434
ProtectedCursor = cursor;
14351435
}
14361436

1437-
internal static INameScope FindNameScope(DependencyObject dependencyObject)
1438-
{
1439-
// In many cases, this will not traverse the entire visual tree, as the NameScope is often
1440-
// present on each element as the DP is inherited. However, it can happen that the DP inheritance
1441-
// didn't yet happen, in which case we'll traverse the tree up.
1442-
var current = dependencyObject;
1443-
while (current is not null)
1444-
{
1445-
if (NameScope.GetNameScope(current) is { } nameScope)
1446-
{
1447-
return nameScope;
1448-
}
1449-
1450-
current = VisualTreeHelper.GetParent(current);
1451-
}
1452-
1453-
return null;
1454-
}
1455-
14561437
/// <summary>
14571438
/// This event is not yet implemented in Uno Platform.
14581439
/// </summary>

src/Uno.UI/UI/Xaml/UIElement.mux.cs

+5-31
Original file line numberDiff line numberDiff line change
@@ -616,27 +616,18 @@ internal Rect GetGlobalBoundsWithOptions(bool ignoreClipping, bool ignoreClippin
616616
return new Rect();
617617
}
618618

619+
#if UNO_HAS_ENHANCED_LIFECYCLE
619620
// Doesn't exactly match WinUI code.
620621
internal virtual void Enter(INameScope? nameScope, EnterParams @params, int depth)
621622
{
622-
// Enter does nothing on platforms with non-enhanced lifecycle.
623-
// Its only purpose is to register names via the FrameworkElement override.
624-
#if UNO_HAS_ENHANCED_LIFECYCLE
625623
Depth = depth;
626624

627625
if (@params.IsLive)
628626
{
629627
IsActiveInVisualTree = true;
630628
}
631-
#endif
632-
633-
#if UNO_HAS_ENHANCED_LIFECYCLE
634-
var children = _children;
635-
#else
636-
var children = this.GetChildren();
637-
#endif
638629

639-
foreach (var child in children)
630+
foreach (var child in _children)
640631
{
641632
if (child == this)
642633
{
@@ -648,14 +639,9 @@ internal virtual void Enter(INameScope? nameScope, EnterParams @params, int dept
648639
continue;
649640
}
650641

651-
#if UNO_HAS_ENHANCED_LIFECYCLE
652642
child.Enter(nameScope, @params, depth + 1);
653-
#else
654-
(child as UIElement)?.Enter(nameScope, @params, depth + 1);
655-
#endif
656643
}
657644

658-
#if UNO_HAS_ENHANCED_LIFECYCLE
659645
if (@params.IsLive)
660646
{
661647
var core = this.GetContext();
@@ -664,19 +650,11 @@ internal virtual void Enter(INameScope? nameScope, EnterParams @params, int dept
664650

665651
// Make sure that we propagate OnDirtyPath bits to the new parent.
666652
SetLayoutFlags(LayoutFlag.MeasureDirty | LayoutFlag.ArrangeDirty);
667-
#endif
668653
}
669654

670655
internal virtual void Leave(INameScope? nameScope, LeaveParams @params)
671656
{
672-
var children =
673-
#if UNO_HAS_ENHANCED_LIFECYCLE
674-
_children;
675-
#else
676-
this.GetChildren();
677-
#endif
678-
679-
foreach (var child in children)
657+
foreach (var child in _children)
680658
{
681659
if (child == this)
682660
{
@@ -688,14 +666,9 @@ internal virtual void Leave(INameScope? nameScope, LeaveParams @params)
688666
continue;
689667
}
690668

691-
#if UNO_HAS_ENHANCED_LIFECYCLE
692669
child.Leave(nameScope, @params);
693-
#else
694-
(child as UIElement)?.Leave(nameScope, @params);
695-
#endif
696670
}
697671

698-
#if UNO_HAS_ENHANCED_LIFECYCLE
699672
if (IsActiveInVisualTree)
700673
{
701674
if (IsLoaded)
@@ -716,7 +689,8 @@ internal virtual void Leave(INameScope? nameScope, LeaveParams @params)
716689

717690
var eventManager = this.GetContext().EventManager;
718691
eventManager.RemoveRequest(this);
719-
#endif
692+
}
720693
}
694+
#endif
721695
}
722696
}

0 commit comments

Comments
 (0)