-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip useless handler mappings calls while connecting #27259
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
internal static class InternalElementExtensions | ||
{ | ||
/// <summary> | ||
/// The handler is connecting for the first time to the element and mapping all properties. | ||
/// </summary> | ||
/// <param name="element"></param> | ||
/// <returns></returns> | ||
internal static bool IsMappingProperties(this IElement element) => | ||
(element.Handler as IElementHandlerStateExhibitor)?.State.HasFlag(ElementHandlerState.MappingProperties) ?? false; | ||
|
||
/// <summary> | ||
/// Indicates whether the handler is connecting for the first time to the element and mapping all properties. | ||
/// </summary> | ||
/// <param name="element"></param> | ||
/// <returns></returns> | ||
internal static bool IsConnectingHandler(this IElement element) => | ||
(element.Handler as IElementHandlerStateExhibitor)?.State.HasFlag(ElementHandlerState.Connecting) ?? false; | ||
|
||
/// <summary> | ||
/// Indicates whether the connected handler is now connecting to a new element and updating properties. | ||
/// </summary> | ||
/// <param name="element"></param> | ||
/// <returns></returns> | ||
internal static bool IsReconnectingHandler(this IElement element) => | ||
(element.Handler as IElementHandlerStateExhibitor)?.State.HasFlag(ElementHandlerState.Reconnecting) ?? false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
/// <summary> | ||
/// Exposes the state of an element handler. | ||
/// </summary> | ||
[Flags] | ||
internal enum ElementHandlerState : byte | ||
{ | ||
/// <summary> | ||
/// The handler is not connected to an element. | ||
/// </summary> | ||
Disconnected = 0x0, | ||
/// <summary> | ||
/// The handler is mapping all properties to the element. | ||
/// </summary> | ||
MappingProperties = 0x1, | ||
/// <summary> | ||
/// The handler is connecting for the first time to the element and mapping all properties. | ||
/// </summary> | ||
Connecting = MappingProperties | 0x2, | ||
/// <summary> | ||
/// The connected handler is now connecting to a new element and updating properties. | ||
/// </summary> | ||
Reconnecting = MappingProperties | 0x4, | ||
/// <summary> | ||
/// The handler is connected to an element. | ||
/// </summary> | ||
Connected = 0x8 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Microsoft.Maui | ||
{ | ||
/// <summary> | ||
/// Exposes the state of an element handler. | ||
/// </summary> | ||
/// <remarks> | ||
/// To be migrated to a public API. | ||
/// </remarks> | ||
internal interface IElementHandlerStateExhibitor | ||
{ | ||
/// <summary> | ||
/// Gets the state of the element handler. | ||
/// </summary> | ||
ElementHandlerState State { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
internal static class InternalElementHandlerExtensions | ||
{ | ||
/// <summary> | ||
/// The handler is connecting for the first time to the element and mapping all properties. | ||
/// </summary> | ||
/// <param name="handler"></param> | ||
/// <returns></returns> | ||
internal static bool IsMappingProperties(this IElementHandler handler) => | ||
(handler as IElementHandlerStateExhibitor)?.State.HasFlag(ElementHandlerState.MappingProperties) ?? false; | ||
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method as-is is user-friendly. However, the result is perhaps unexpected when Anyway, feel free to ignore if you feel like it does not add any value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only temporary for .NET9, and the |
||
|
||
/// <summary> | ||
/// Indicates whether the handler is connecting for the first time to the element and mapping all properties. | ||
/// </summary> | ||
/// <param name="handler"></param> | ||
/// <returns></returns> | ||
internal static bool IsConnectingHandler(this IElementHandler handler) => | ||
(handler as IElementHandlerStateExhibitor)?.State.HasFlag(ElementHandlerState.Connecting) ?? false; | ||
|
||
/// <summary> | ||
/// Indicates whether the connected handler is now connecting to a new element and updating properties. | ||
/// </summary> | ||
/// <param name="handler"></param> | ||
/// <returns></returns> | ||
internal static bool IsReconnectingHandler(this IElementHandler handler) => | ||
(handler as IElementHandlerStateExhibitor)?.State.HasFlag(ElementHandlerState.Reconnecting) ?? false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit but this makes putting breakpoints easier: