Skip to content

Commit

Permalink
Remove IPlatformInvalidate and Device.Invalidate() (#4479) fixes #…
Browse files Browse the repository at this point in the history
…1965

* Remove IPlatformInvalidate

Removes:
 - `Device.Invalidate(VisualElement visualElement)`
 - `Device.PlatformInvalidator`
 - `IPlatformInvalidate`

* Revert "Remove IPlatformInvalidate"

This reverts commit b5ff83c.

* Use DependencyService when needed instead

* no intellisense

* and this

* forgot to save

* :(

* :)
  • Loading branch information
mattleibow committed Feb 4, 2022
1 parent f54d98a commit 6c4f1f4
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 97 deletions.
15 changes: 1 addition & 14 deletions src/Compatibility/Core/src/Android/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ internal static void RegisterCompatRenderers(IMauiContext context, Initializatio
var androidServices = new AndroidPlatformServices(activity);

Device.PlatformServices = androidServices;
Device.PlatformInvalidator = androidServices;

Profile.FramePartition("RegisterAll");

Expand Down Expand Up @@ -377,7 +376,7 @@ protected override Expression VisitMember(MemberExpression node)
}
}

class AndroidPlatformServices : IPlatformServices, IPlatformInvalidate
class AndroidPlatformServices : IPlatformServices
{
double _buttonDefaultSize;
double _editTextDefaultSize;
Expand Down Expand Up @@ -546,18 +545,6 @@ public SizeRequest GetNativeSize(VisualElement view, double widthConstraint, dou
return Platform.Android.Platform.GetNativeSize(view, widthConstraint, heightConstraint);
}

public void Invalidate(VisualElement visualElement)
{
var renderer = visualElement.GetRenderer();
if (renderer == null || renderer.View.IsDisposed())
{
return;
}

renderer.View.Invalidate();
renderer.View.RequestLayout();
}

public OSAppTheme RequestedTheme
{
get
Expand Down
21 changes: 21 additions & 0 deletions src/Compatibility/Core/src/Android/PlatformInvalidate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.Maui.Controls.Internals;

[assembly: Microsoft.Maui.Controls.Dependency(typeof(Microsoft.Maui.Controls.Compatibility.Platform.Android.PlatformInvalidate))]

namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
{
class PlatformInvalidate : IPlatformInvalidate
{
public void Invalidate(VisualElement visualElement)
{
var renderer = visualElement.GetRenderer();
if (renderer == null || renderer.View.IsDisposed())
{
return;
}

renderer.View.Invalidate();
renderer.View.RequestLayout();
}
}
}
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static MauiAppBuilder SetupDefaults(this MauiAppBuilder builder)
DependencyService.Register<Deserializer>();
DependencyService.Register<ResourcesProvider>();
DependencyService.Register<Xaml.ValueConverterProvider>();
DependencyService.Register<PlatformInvalidate>();
#endif

builder.ConfigureCompatibilityLifecycleEvents();
Expand Down
1 change: 0 additions & 1 deletion src/Compatibility/Core/src/Windows/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public static void Init(IActivationState state, InitializationOptions? options =
var platformServices = new WindowsPlatformServices();

Device.PlatformServices = platformServices;
Device.PlatformInvalidator = platformServices;

if (mainWindow != null)
{
Expand Down
20 changes: 20 additions & 0 deletions src/Compatibility/Core/src/Windows/PlatformInvalidate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Maui.Controls.Internals;

[assembly: Microsoft.Maui.Controls.Dependency(typeof(Microsoft.Maui.Controls.Compatibility.Platform.UWP.PlatformInvalidate))]

namespace Microsoft.Maui.Controls.Compatibility.Platform.UWP
{
class PlatformInvalidate : IPlatformInvalidate
{
public void Invalidate(VisualElement visualElement)
{
var renderer = Platform.GetRenderer(visualElement);
if (renderer == null)
{
return;
}

renderer.ContainerElement.InvalidateMeasure();
}
}
}
13 changes: 1 addition & 12 deletions src/Compatibility/Core/src/Windows/WindowsPlatformServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Microsoft.Maui.Controls.Compatibility.Platform.UWP
{
internal class WindowsPlatformServices : IPlatformServices, IPlatformInvalidate
internal class WindowsPlatformServices : IPlatformServices
{
readonly UISettings _uiSettings = new UISettings();

Expand Down Expand Up @@ -125,17 +125,6 @@ void UISettingsColorValuesChanged(UISettings sender, object args)
Application.Current?.TriggerThemeChanged(new AppThemeChangedEventArgs(Application.Current.RequestedTheme)));
}

public void Invalidate(VisualElement visualElement)
{
var renderer = Platform.GetRenderer(visualElement);
if (renderer == null)
{
return;
}

renderer.ContainerElement.InvalidateMeasure();
}

public OSAppTheme RequestedTheme =>
Microsoft.UI.Xaml.Application.Current.RequestedTheme == ApplicationTheme.Dark
? OSAppTheme.Dark
Expand Down
18 changes: 0 additions & 18 deletions src/Compatibility/Core/src/iOS/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ static void SetupInit(IMauiContext context, InitializationOptions? maybeOptions

Device.PlatformServices = platformServices;

#if __MOBILE__
Device.PlatformInvalidator = platformServices;
#endif
if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true)
RegisterCompatRenderers(context);

Expand Down Expand Up @@ -289,9 +286,6 @@ protected override Expression VisitMember(MemberExpression node)
}

class IOSPlatformServices : IPlatformServices
#if __MOBILE__
, IPlatformInvalidate
#endif
{
readonly double _fontScalingFactor = 1;
public IOSPlatformServices()
Expand Down Expand Up @@ -505,18 +499,6 @@ static UIViewController GetCurrentViewController(bool throwIfNull = true)

return viewController;
}

public void Invalidate(VisualElement visualElement)
{
var renderer = Platform.iOS.Platform.GetRenderer(visualElement);

if (renderer == null)
{
return;
}

renderer.NativeView.SetNeedsLayout();
}
#endif
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/Compatibility/Core/src/iOS/PlatformInvalidate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.Maui.Controls.Internals;

[assembly: Microsoft.Maui.Controls.Dependency(typeof(Microsoft.Maui.Controls.Compatibility.Platform.iOS.PlatformInvalidate))]

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
class PlatformInvalidate : IPlatformInvalidate
{
public void Invalidate(VisualElement visualElement)
{
var renderer = Microsoft.Maui.Controls.Compatibility.Platform.iOS.Platform.GetRenderer(visualElement);

if (renderer == null)
{
return;
}

renderer.NativeView.SetNeedsLayout();
}
}
}
41 changes: 0 additions & 41 deletions src/Controls/docs/Microsoft.Maui.Controls/Device.xml
Original file line number Diff line number Diff line change
Expand Up @@ -337,28 +337,6 @@ Device.BeginInvokeOnMainThread (() => {
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Invalidate">
<MemberSignature Language="C#" Value="public static void Invalidate (Microsoft.Maui.Controls.VisualElement visualElement);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void Invalidate(class Microsoft.Maui.Controls.VisualElement visualElement) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Maui.Controls.Device.Invalidate(Microsoft.Maui.Controls.VisualElement)" />
<MemberSignature Language="F#" Value="static member Invalidate : Microsoft.Maui.Controls.VisualElement -&gt; unit" Usage="Microsoft.Maui.Controls.Device.Invalidate visualElement" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.Maui.Controls.Core</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="visualElement" Type="Microsoft.Maui.Controls.VisualElement" />
</Parameters>
<Docs>
<param name="visualElement">To be added.</param>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="InvokeOnMainThreadAsync">
<MemberSignature Language="C#" Value="public static System.Threading.Tasks.Task InvokeOnMainThreadAsync (Action action);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig class System.Threading.Tasks.Task InvokeOnMainThreadAsync(class System.Action action) cil managed" />
Expand Down Expand Up @@ -695,25 +673,6 @@ button.HeightRequest = Device.OnPlatform (20,30,30);
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="PlatformInvalidator">
<MemberSignature Language="C#" Value="public static Microsoft.Maui.Controls.Internals.IPlatformInvalidate PlatformInvalidator { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property class Microsoft.Maui.Controls.Internals.IPlatformInvalidate PlatformInvalidator" />
<MemberSignature Language="DocId" Value="P:Microsoft.Maui.Controls.Device.PlatformInvalidator" />
<MemberSignature Language="F#" Value="member this.PlatformInvalidator : Microsoft.Maui.Controls.Internals.IPlatformInvalidate with get, set" Usage="Microsoft.Maui.Controls.Device.PlatformInvalidator" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.Maui.Controls.Core</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>Microsoft.Maui.Controls.Internals.IPlatformInvalidate</ReturnType>
</ReturnValue>
<Docs>
<summary>To be added.</summary>
<value>To be added.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="PlatformServices">
<MemberSignature Language="C#" Value="public static Microsoft.Maui.Controls.Internals.IPlatformServices PlatformServices { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property class Microsoft.Maui.Controls.Internals.IPlatformServices PlatformServices" />
Expand Down
9 changes: 0 additions & 9 deletions src/Controls/src/Core/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ public static IPlatformServices PlatformServices
}
}

/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='PlatformInvalidator']/Docs" />
public static IPlatformInvalidate PlatformInvalidator { get; set; }

//[Obsolete("Use BindableObject.Dispatcher instead.")]
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='IsInvokeRequired']/Docs" />
public static bool IsInvokeRequired =>
Expand Down Expand Up @@ -167,11 +164,5 @@ public static class Styles

public static readonly Style CaptionStyle = new Style(typeof(Label)) { BaseResourceKey = CaptionStyleKey };
}

/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='Invalidate']/Docs" />
public static void Invalidate(VisualElement visualElement)
{
PlatformInvalidator?.Invalidate(visualElement);
}
}
}
1 change: 0 additions & 1 deletion src/Controls/src/Core/IPlatformInvalidate.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Microsoft.Maui.Controls.Internals
{
public interface IPlatformInvalidate

{
void Invalidate(VisualElement visualElement);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Core/VisualElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ public void BatchCommit()
if (!Batched)
{
BatchCommitted?.Invoke(this, new EventArg<VisualElement>(this));
Device.Invalidate(this);
DependencyService.Get<IPlatformInvalidate>()?.Invalidate(this);
}
}

Expand Down

0 comments on commit 6c4f1f4

Please sign in to comment.