-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix renderer shim ordering when creating native renderer (#1105)
* Set Renderer before setting virtual view * - fix NET6 targets
- Loading branch information
Showing
10 changed files
with
176 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/Compatibility/Core/src/RendererToHandlerShim.Android.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Android.Views; | ||
using Microsoft.Maui.Controls.Compatibility.Platform.Android; | ||
using Microsoft.Maui.Graphics; | ||
using static Microsoft.Maui.Controls.Compatibility.Platform.Android.AppCompat.Platform; | ||
using NativeView = Android.Views.View; | ||
|
||
namespace Microsoft.Maui.Controls.Compatibility | ||
{ | ||
public partial class RendererToHandlerShim | ||
{ | ||
protected override NativeView CreateNativeView() | ||
{ | ||
return VisualElementRenderer.View; | ||
} | ||
|
||
IVisualElementRenderer CreateRenderer(IView view) | ||
{ | ||
if (Context != null) | ||
{ | ||
var renderer = Internals.Registrar.Registered.GetHandlerForObject<IVisualElementRenderer>(view, Context) | ||
?? new DefaultRenderer(Context); | ||
return renderer; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public override Size GetDesiredSize(double widthConstraint, double heightConstraint) | ||
{ | ||
return GetNativeSize( | ||
VisualElementRenderer, widthConstraint, heightConstraint); | ||
} | ||
|
||
public override void NativeArrange(Rectangle frame) | ||
{ | ||
// This is a hack to force the shimmed control to actually do layout; without this, some controls won't actually | ||
// call OnLayout after SetFrame if their sizes haven't changed (e.g., ScrollView) | ||
// Luckily, measuring with MeasureSpecMode.Exactly is pretty fast, since it just returns the value you give it. | ||
NativeView?.Measure(MeasureSpecMode.Exactly.MakeMeasureSpec((int)frame.Width), | ||
MeasureSpecMode.Exactly.MakeMeasureSpec((int)frame.Height)); | ||
|
||
base.NativeArrange(frame); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Compatibility/Core/src/RendererToHandlerShim.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using NativeView = Microsoft.UI.Xaml.FrameworkElement; | ||
using Microsoft.Maui.Controls.Compatibility.Platform.UWP; | ||
using Microsoft.Maui.Graphics; | ||
|
||
namespace Microsoft.Maui.Controls.Compatibility | ||
{ | ||
public partial class RendererToHandlerShim | ||
{ | ||
protected override NativeView CreateNativeView() | ||
{ | ||
return VisualElementRenderer.ContainerElement; | ||
} | ||
|
||
IVisualElementRenderer CreateRenderer(IView view) | ||
{ | ||
return Internals.Registrar.Registered.GetHandlerForObject<IVisualElementRenderer>(view) | ||
?? new DefaultRenderer(); | ||
} | ||
|
||
public override Size GetDesiredSize(double widthConstraint, double heightConstraint) | ||
{ | ||
if (widthConstraint < 0 || heightConstraint < 0) | ||
return Size.Zero; | ||
|
||
return VisualElementRenderer.GetDesiredSize(widthConstraint, heightConstraint); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.Maui.Controls.Compatibility.Platform.iOS; | ||
using static Microsoft.Maui.Controls.Compatibility.Platform.iOS.Platform; | ||
using NativeView = UIKit.UIView; | ||
|
||
namespace Microsoft.Maui.Controls.Compatibility | ||
{ | ||
public partial class RendererToHandlerShim | ||
{ | ||
protected override NativeView CreateNativeView() | ||
{ | ||
return VisualElementRenderer.NativeView; | ||
} | ||
|
||
IVisualElementRenderer CreateRenderer(IView view) | ||
{ | ||
return Internals.Registrar.Registered.GetHandlerForObject<IVisualElementRenderer>(view) | ||
?? new DefaultRenderer(); | ||
} | ||
|
||
public override void UpdateValue(string property) | ||
{ | ||
base.UpdateValue(property); | ||
if (property == "Frame") | ||
{ | ||
NativeArrange(VisualElementRenderer.Element.Bounds); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.