Skip to content

Commit

Permalink
Avoid unnecessary allocations on DependencyObjectExtensions.RegisterD…
Browse files Browse the repository at this point in the history
…isposableNestedPropertyChangedCallback (#705)
  • Loading branch information
pictos authored Aug 10, 2023
1 parent 1ce1eb5 commit 90c5144
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public override void SetSuperviewNeedsLayout()
// Even though we set the Navigation as the parent of the TitleView,
// it will change to the native control when the view is added (once MovedToSuperview is called).
// This native control is the visual parent but is not a DependencyObject and will not propagate the DataContext.
// In order to ensure the DataContext is propagated properly, we need to notify the renderer that this change has occured
// In order to ensure the DataContext is propagated properly, we need to notify the renderer that this change has occurred
// so we can restore the NavigationBar parent that can propagate the DataContext
public override void MovedToSuperview()
{
Expand Down
7 changes: 3 additions & 4 deletions src/Uno.Toolkit.UI/Extensions/DependencyObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Uno.Disposables;
Expand Down Expand Up @@ -53,12 +53,11 @@ internal static IDisposable RegisterDisposableNestedPropertyChangedCallback(this
.Select(group =>
{
var property = group.Key;
var subProperties = group.ToArray();
var childDisposable = new SerialDisposable();
if (instance.TryGetValue(property, out var dpValue))
{
var childDisposable = new SerialDisposable();
var subProperties = group.ToArray();
childDisposable.Disposable = dpValue?.RegisterDisposableNestedPropertyChangedCallback(callback, subProperties);
var disposable = instance.RegisterDisposablePropertyChangedCallback(property, (s, e) =>
Expand Down

0 comments on commit 90c5144

Please sign in to comment.