Skip to content

Commit 279a2aa

Browse files
committed
WIP
1 parent 29f3c7a commit 279a2aa

18 files changed

+127
-44
lines changed

src/Core/src/Handlers/Element/ElementHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public virtual void SetVirtualView(IElement view)
7676
}
7777
}
7878

79-
_mapper.UpdateProperties(this, VirtualView);
79+
_mapper.UpdateProperties(this, VirtualView, initial: true);
8080
}
8181

8282
public virtual void UpdateValue(string property)

src/Core/src/Handlers/IElementHandler.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,49 @@
66
/// </summary>
77
public interface IElementHandler
88
{
9-
/// <summary>
9+
/// <summary>
1010
/// Sets the .NET MAUI context for the element handler.
11-
/// </summary>
12-
/// <param name="mauiContext">The .NET MAUI context to set.</param>
11+
/// </summary>
12+
/// <param name="mauiContext">The .NET MAUI context to set.</param>
1313
void SetMauiContext(IMauiContext mauiContext);
1414

15-
/// <summary>
15+
/// <summary>
1616
/// Sets the cross-platform virtual view associated with the handler.
17-
/// </summary>
18-
/// <param name="view">The element to handle.</param>
17+
/// </summary>
18+
/// <param name="view">The element to handle.</param>
1919
void SetVirtualView(IElement view);
2020

21-
/// <summary>
22-
/// Updates the value of the specified property on the handler.
23-
/// </summary>
24-
/// <param name="property">The name of the property to update.</param>
21+
/// <summary>
22+
/// Updates the value of the specified property on the handler.
23+
/// </summary>
24+
/// <param name="property">The name of the property to update.</param>
2525
void UpdateValue(string property);
2626

27-
/// <summary>
28-
/// Invokes the specified command on the element with the given arguments.
29-
/// </summary>
30-
/// <param name="command">The name of the command to invoke.</param>
31-
/// <param name="args">Optional arguments to pass to the command.</param>
27+
/// <summary>
28+
/// Invokes the specified command on the element with the given arguments.
29+
/// </summary>
30+
/// <param name="command">The name of the command to invoke.</param>
31+
/// <param name="args">Optional arguments to pass to the command.</param>
3232
void Invoke(string command, object? args = null);
3333

34-
/// <summary>
34+
/// <summary>
3535
/// Disconnects the element handler from the element for clean up.
36-
/// </summary>
36+
/// </summary>
3737
void DisconnectHandler();
3838

39-
/// <summary>
40-
/// Gets the platform-specific view object associated with the handler.
41-
/// </summary>
39+
/// <summary>
40+
/// Gets the platform-specific view object associated with the handler.
41+
/// </summary>
4242
object? PlatformView { get; }
4343

44-
/// <summary>
45-
/// Gets the cross-platform virtual view associated with the handler.
46-
/// </summary>
44+
/// <summary>
45+
/// Gets the cross-platform virtual view associated with the handler.
46+
/// </summary>
4747
IElement? VirtualView { get; }
4848

49-
/// <summary>
50-
/// Gets the .NET MAUI context associated with the element.
51-
/// </summary>
49+
/// <summary>
50+
/// Gets the .NET MAUI context associated with the element.
51+
/// </summary>
5252
IMauiContext? MauiContext { get; }
5353
}
5454
}

src/Core/src/Handlers/Label/LabelHandler.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#nullable enable
2+
using System;
3+
using System.Collections.Generic;
24
#if __IOS__ || MACCATALYST
35
using PlatformView = Microsoft.Maui.Platform.MauiLabel;
46
#elif MONOANDROID
@@ -15,7 +17,19 @@ namespace Microsoft.Maui.Handlers
1517
{
1618
public partial class LabelHandler : ILabelHandler
1719
{
18-
public static IPropertyMapper<ILabel, ILabelHandler> Mapper = new PropertyMapper<ILabel, ILabelHandler>(ViewHandler.ViewMapper)
20+
private static Dictionary<string, Func<IElement, bool>> initSkipChecks = new(StringComparer.Ordinal)
21+
{
22+
{ nameof(ILabel.Height), SkipCheckHeight },
23+
{ nameof(ILabel.Opacity), SkipCheckOpacity },
24+
25+
{ nameof(ILabel.CharacterSpacing), SkipCheckCharacterSpacing },
26+
{ nameof(ILabel.HorizontalTextAlignment), SkipCheckHorizontalTextAlignment },
27+
{ nameof(ILabel.VerticalTextAlignment), SkipCheckVerticalTextAlignment },
28+
{ nameof(ILabel.Padding), SkipCheckPadding },
29+
{ nameof(ILabel.TextDecorations), SkipCheckTextDecorations },
30+
};
31+
32+
public static IPropertyMapper<ILabel, ILabelHandler> Mapper = new PropertyMapper<ILabel, ILabelHandler>(initSkipChecks, ViewHandler.ViewMapper)
1933
{
2034
#if IOS || TIZEN
2135
[nameof(ILabel.Background)] = MapBackground,
@@ -63,5 +77,40 @@ public LabelHandler(IPropertyMapper? mapper, CommandMapper? commandMapper)
6377
ILabel ILabelHandler.VirtualView => VirtualView;
6478

6579
PlatformView ILabelHandler.PlatformView => PlatformView;
80+
81+
internal static bool SkipCheckHeight(IElement label)
82+
{
83+
return double.IsNaN(((ILabel)label).Height);
84+
}
85+
86+
internal static bool SkipCheckOpacity(IElement label)
87+
{
88+
return ((ILabel)label).Opacity == 1;
89+
}
90+
91+
internal static bool SkipCheckTextDecorations(IElement label)
92+
{
93+
return ((ILabel)label).TextDecorations == TextDecorations.None;
94+
}
95+
96+
internal static bool SkipCheckCharacterSpacing(IElement label)
97+
{
98+
return ((ILabel)label).CharacterSpacing == 0;
99+
}
100+
101+
internal static bool SkipCheckPadding(IElement label)
102+
{
103+
return ((ILabel)label).Padding.IsEmpty;
104+
}
105+
106+
internal static bool SkipCheckHorizontalTextAlignment(IElement label)
107+
{
108+
return ((ILabel)label).HorizontalTextAlignment == TextAlignment.Start;
109+
}
110+
111+
internal static bool SkipCheckVerticalTextAlignment(IElement label)
112+
{
113+
return ((ILabel)label).VerticalTextAlignment == TextAlignment.Start;
114+
}
66115
}
67116
}

src/Core/src/PropertyMapper.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34

45
#if IOS || MACCATALYST
56
using PlatformView = UIKit.UIView;
@@ -17,6 +18,10 @@ public abstract class PropertyMapper : IPropertyMapper
1718
{
1819
protected readonly Dictionary<string, Action<IElementHandler, IElement>> _mapper = new(StringComparer.Ordinal);
1920

21+
#pragma warning disable RS0016 // Add public types and members to the declared API
22+
protected internal readonly Dictionary<string, Func<IElement, bool>> _initSkipChecks = new(StringComparer.Ordinal);
23+
#pragma warning restore RS0016 // Add public types and members to the declared API
24+
2025
IPropertyMapper[]? _chained;
2126

2227
// Keep a distinct list of the keys so we don't run any duplicate (overridden) updates more than once
@@ -32,6 +37,14 @@ public PropertyMapper(params IPropertyMapper[]? chained)
3237
Chained = chained;
3338
}
3439

40+
#pragma warning disable RS0016 // Add public types and members to the declared API
41+
public PropertyMapper(Dictionary<string, Func<IElement, bool>> initSkipChecks, params IPropertyMapper[]? chained)
42+
{
43+
_initSkipChecks = initSkipChecks;
44+
Chained = chained;
45+
}
46+
#pragma warning restore RS0016 // Add public types and members to the declared API
47+
3548
protected virtual void SetPropertyCore(string key, Action<IElementHandler, IElement> action)
3649
{
3750
_mapper[key] = action;
@@ -50,14 +63,19 @@ protected virtual void UpdatePropertyCore(string key, IElementHandler viewHandle
5063
public virtual Action<IElementHandler, IElement>? GetProperty(string key)
5164
{
5265
if (_mapper.TryGetValue(key, out var action))
66+
{
5367
return action;
68+
}
5469
else if (Chained is not null)
5570
{
5671
foreach (var ch in Chained)
5772
{
5873
var returnValue = ch.GetProperty(key);
74+
5975
if (returnValue != null)
76+
{
6077
return returnValue;
78+
}
6179
}
6280
}
6381

@@ -67,21 +85,35 @@ protected virtual void UpdatePropertyCore(string key, IElementHandler viewHandle
6785
public void UpdateProperty(IElementHandler viewHandler, IElement? virtualView, string property)
6886
{
6987
if (virtualView == null)
88+
{
7089
return;
90+
}
7191

7292
UpdatePropertyCore(property, viewHandler, virtualView);
7393
}
7494

75-
public void UpdateProperties(IElementHandler viewHandler, IElement? virtualView)
95+
#pragma warning disable RS0016 // Add public types and members to the declared API
96+
public void UpdateProperties(IElementHandler viewHandler, IElement? virtualView, bool initial = false)
7697
{
7798
if (virtualView == null)
99+
{
78100
return;
101+
}
79102

80103
foreach (var key in UpdateKeys)
81104
{
105+
if (initial)
106+
{
107+
if (_initSkipChecks.TryGetValue(key, out Func<IElement, bool>? skipCheck) && skipCheck(virtualView))
108+
{
109+
continue;
110+
}
111+
}
112+
82113
UpdatePropertyCore(key, viewHandler, virtualView);
83114
}
84115
}
116+
#pragma warning restore RS0016 // Add public types and members to the declared API
85117

86118
public IPropertyMapper[]? Chained
87119
{
@@ -130,7 +162,7 @@ public interface IPropertyMapper
130162

131163
IEnumerable<string> GetKeys();
132164

133-
void UpdateProperties(IElementHandler elementHandler, IElement virtualView);
165+
void UpdateProperties(IElementHandler elementHandler, IElement virtualView, bool initial = false);
134166

135167
void UpdateProperty(IElementHandler elementHandler, IElement virtualView, string property);
136168
}
@@ -155,6 +187,13 @@ public PropertyMapper(params IPropertyMapper[] chained)
155187
{
156188
}
157189

190+
#pragma warning disable RS0016 // Add public types and members to the declared API
191+
public PropertyMapper(Dictionary<string, Func<IElement, bool>> initSkipChecks, params IPropertyMapper[] chained)
192+
: base(initSkipChecks: initSkipChecks, chained: chained)
193+
{
194+
}
195+
#pragma warning restore RS0016 // Add public types and members to the declared API
196+
158197
public Action<TViewHandler, TVirtualView> this[string key]
159198
{
160199
get
@@ -169,7 +208,9 @@ public void Add(string key, Action<TViewHandler, TVirtualView> action) =>
169208
SetPropertyCore(key, (h, v) =>
170209
{
171210
if (v is TVirtualView vv)
211+
{
172212
action?.Invoke((TViewHandler)h, vv);
213+
}
173214
else if (Chained != null)
174215
{
175216
foreach (var chain in Chained)

src/Core/src/PublicAPI/net-android/PublicAPI.Shipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ Microsoft.Maui.IProgress.ProgressColor.get -> Microsoft.Maui.Graphics.Color!
11101110
Microsoft.Maui.IPropertyMapper
11111111
Microsoft.Maui.IPropertyMapper.GetKeys() -> System.Collections.Generic.IEnumerable<string!>!
11121112
Microsoft.Maui.IPropertyMapper.GetProperty(string! key) -> System.Action<Microsoft.Maui.IElementHandler!, Microsoft.Maui.IElement!>?
1113-
Microsoft.Maui.IPropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler! elementHandler, Microsoft.Maui.IElement! virtualView) -> void
11141113
Microsoft.Maui.IPropertyMapper.UpdateProperty(Microsoft.Maui.IElementHandler! elementHandler, Microsoft.Maui.IElement! virtualView, string! property) -> void
11151114
Microsoft.Maui.IPropertyMapper<TVirtualView, TViewHandler>
11161115
Microsoft.Maui.IPropertyMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void
@@ -1876,7 +1875,6 @@ Microsoft.Maui.PropertyMapper.Chained.get -> Microsoft.Maui.IPropertyMapper![]?
18761875
Microsoft.Maui.PropertyMapper.Chained.set -> void
18771876
Microsoft.Maui.PropertyMapper.PropertyMapper() -> void
18781877
Microsoft.Maui.PropertyMapper.PropertyMapper(params Microsoft.Maui.IPropertyMapper![]? chained) -> void
1879-
Microsoft.Maui.PropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler! viewHandler, Microsoft.Maui.IElement? virtualView) -> void
18801878
Microsoft.Maui.PropertyMapper.UpdateProperty(Microsoft.Maui.IElementHandler! viewHandler, Microsoft.Maui.IElement? virtualView, string! property) -> void
18811879
Microsoft.Maui.PropertyMapper<TVirtualView, TViewHandler>
18821880
Microsoft.Maui.PropertyMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void

src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Microsoft.Maui.IHybridWebView.InvokeJavaScriptType.set -> void
3535
Microsoft.Maui.IHybridWebView.RawMessageReceived(string! rawMessage) -> void
3636
Microsoft.Maui.IHybridWebView.SendRawMessage(string! rawMessage) -> void
3737
Microsoft.Maui.IHybridWebView.SetInvokeJavaScriptTarget<T>(T! target) -> void
38+
Microsoft.Maui.IPropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler! elementHandler, Microsoft.Maui.IElement! virtualView, bool initial = false) -> void
3839
Microsoft.Maui.ITitleBar
3940
Microsoft.Maui.ITitleBar.PassthroughElements.get -> System.Collections.Generic.IList<Microsoft.Maui.IView!>!
4041
Microsoft.Maui.ITitleBar.Subtitle.get -> string?

src/Core/src/PublicAPI/net-ios/PublicAPI.Shipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,6 @@ Microsoft.Maui.IProgress.ProgressColor.get -> Microsoft.Maui.Graphics.Color!
10741074
Microsoft.Maui.IPropertyMapper
10751075
Microsoft.Maui.IPropertyMapper.GetKeys() -> System.Collections.Generic.IEnumerable<string!>!
10761076
Microsoft.Maui.IPropertyMapper.GetProperty(string! key) -> System.Action<Microsoft.Maui.IElementHandler!, Microsoft.Maui.IElement!>?
1077-
Microsoft.Maui.IPropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler! elementHandler, Microsoft.Maui.IElement! virtualView) -> void
10781077
Microsoft.Maui.IPropertyMapper.UpdateProperty(Microsoft.Maui.IElementHandler! elementHandler, Microsoft.Maui.IElement! virtualView, string! property) -> void
10791078
Microsoft.Maui.IPropertyMapper<TVirtualView, TViewHandler>
10801079
Microsoft.Maui.IPropertyMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void
@@ -1793,7 +1792,6 @@ Microsoft.Maui.PropertyMapper.Chained.get -> Microsoft.Maui.IPropertyMapper![]?
17931792
Microsoft.Maui.PropertyMapper.Chained.set -> void
17941793
Microsoft.Maui.PropertyMapper.PropertyMapper() -> void
17951794
Microsoft.Maui.PropertyMapper.PropertyMapper(params Microsoft.Maui.IPropertyMapper![]? chained) -> void
1796-
Microsoft.Maui.PropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler! viewHandler, Microsoft.Maui.IElement? virtualView) -> void
17971795
Microsoft.Maui.PropertyMapper.UpdateProperty(Microsoft.Maui.IElementHandler! viewHandler, Microsoft.Maui.IElement? virtualView, string! property) -> void
17981796
Microsoft.Maui.PropertyMapper<TVirtualView, TViewHandler>
17991797
Microsoft.Maui.PropertyMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void

src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Microsoft.Maui.IHybridWebView.InvokeJavaScriptType.set -> void
3535
Microsoft.Maui.IHybridWebView.RawMessageReceived(string! rawMessage) -> void
3636
Microsoft.Maui.IHybridWebView.SendRawMessage(string! rawMessage) -> void
3737
Microsoft.Maui.IHybridWebView.SetInvokeJavaScriptTarget<T>(T! target) -> void
38+
Microsoft.Maui.IPropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler! elementHandler, Microsoft.Maui.IElement! virtualView, bool initial = false) -> void
3839
Microsoft.Maui.ITitleBar
3940
Microsoft.Maui.ITitleBar.PassthroughElements.get -> System.Collections.Generic.IList<Microsoft.Maui.IView!>!
4041
Microsoft.Maui.ITitleBar.Subtitle.get -> string?

src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Shipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,6 @@ Microsoft.Maui.IProgress.ProgressColor.get -> Microsoft.Maui.Graphics.Color!
10741074
Microsoft.Maui.IPropertyMapper
10751075
Microsoft.Maui.IPropertyMapper.GetKeys() -> System.Collections.Generic.IEnumerable<string!>!
10761076
Microsoft.Maui.IPropertyMapper.GetProperty(string! key) -> System.Action<Microsoft.Maui.IElementHandler!, Microsoft.Maui.IElement!>?
1077-
Microsoft.Maui.IPropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler! elementHandler, Microsoft.Maui.IElement! virtualView) -> void
10781077
Microsoft.Maui.IPropertyMapper.UpdateProperty(Microsoft.Maui.IElementHandler! elementHandler, Microsoft.Maui.IElement! virtualView, string! property) -> void
10791078
Microsoft.Maui.IPropertyMapper<TVirtualView, TViewHandler>
10801079
Microsoft.Maui.IPropertyMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void
@@ -1792,7 +1791,6 @@ Microsoft.Maui.PropertyMapper.Chained.get -> Microsoft.Maui.IPropertyMapper![]?
17921791
Microsoft.Maui.PropertyMapper.Chained.set -> void
17931792
Microsoft.Maui.PropertyMapper.PropertyMapper() -> void
17941793
Microsoft.Maui.PropertyMapper.PropertyMapper(params Microsoft.Maui.IPropertyMapper![]? chained) -> void
1795-
Microsoft.Maui.PropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler! viewHandler, Microsoft.Maui.IElement? virtualView) -> void
17961794
Microsoft.Maui.PropertyMapper.UpdateProperty(Microsoft.Maui.IElementHandler! viewHandler, Microsoft.Maui.IElement? virtualView, string! property) -> void
17971795
Microsoft.Maui.PropertyMapper<TVirtualView, TViewHandler>
17981796
Microsoft.Maui.PropertyMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void

src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Microsoft.Maui.IHybridWebView.InvokeJavaScriptType.set -> void
3535
Microsoft.Maui.IHybridWebView.RawMessageReceived(string! rawMessage) -> void
3636
Microsoft.Maui.IHybridWebView.SendRawMessage(string! rawMessage) -> void
3737
Microsoft.Maui.IHybridWebView.SetInvokeJavaScriptTarget<T>(T! target) -> void
38+
Microsoft.Maui.IPropertyMapper.UpdateProperties(Microsoft.Maui.IElementHandler! elementHandler, Microsoft.Maui.IElement! virtualView, bool initial = false) -> void
3839
Microsoft.Maui.ITitleBar
3940
Microsoft.Maui.ITitleBar.PassthroughElements.get -> System.Collections.Generic.IList<Microsoft.Maui.IView!>!
4041
Microsoft.Maui.ITitleBar.Subtitle.get -> string?

0 commit comments

Comments
 (0)