Skip to content

Commit

Permalink
Shims should use the container view if there is one (#1320)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow authored Jun 15, 2021
1 parent cc7adc4 commit 59d330a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/Compatibility/Core/src/Android/HandlerToRendererShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ public class HandlerToRendererShim : IVisualElementRenderer
{
int? _defaultLabelFor;

public HandlerToRendererShim(IViewHandler vh)
public HandlerToRendererShim(INativeViewHandler vh)
{
ViewHandler = vh;
}

IViewHandler ViewHandler { get; }
INativeViewHandler ViewHandler { get; }

public VisualElement Element { get; private set; }

public VisualElementTracker Tracker { get; private set; }

public ViewGroup ViewGroup => ViewHandler.NativeView as ViewGroup;
public ViewGroup ViewGroup => null;

public global::Android.Views.View View => ViewHandler.NativeView as global::Android.Views.View;
public global::Android.Views.View View => ViewHandler.ContainerView ?? ViewHandler.NativeView;

public event EventHandler<VisualElementChangedEventArgs> ElementChanged;
public event EventHandler<PropertyChangedEventArgs> ElementPropertyChanged;
Expand Down
8 changes: 3 additions & 5 deletions src/Compatibility/Core/src/WinUI/HandlerToRendererShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ namespace Microsoft.Maui.Controls.Compatibility
{
public class HandlerToRendererShim : IVisualElementRenderer
{
public HandlerToRendererShim(IViewHandler vh)
public HandlerToRendererShim(INativeViewHandler vh)
{
ViewHandler = vh;
}

IViewHandler ViewHandler { get; }
INativeViewHandler ViewHandler { get; }

public VisualElement Element { get; private set; }

public FrameworkElement NativeView => (FrameworkElement)ViewHandler.NativeView;

public FrameworkElement ContainerElement => (FrameworkElement)ViewHandler.NativeView;
public FrameworkElement ContainerElement => ViewHandler.ContainerView ?? ViewHandler.NativeView;

public event EventHandler<VisualElementChangedEventArgs> ElementChanged;
public event EventHandler<PropertyChangedEventArgs> ElementPropertyChanged;
Expand Down
8 changes: 4 additions & 4 deletions src/Compatibility/Core/src/iOS/HandlerToRendererShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
public class HandlerToRendererShim : IVisualElementRenderer
{
public HandlerToRendererShim(IViewHandler vh)
public HandlerToRendererShim(INativeViewHandler vh)
{
ViewHandler = vh;
}

IViewHandler ViewHandler { get; }
INativeViewHandler ViewHandler { get; }

public VisualElement Element { get; private set; }

public UIView NativeView => (UIView)ViewHandler.NativeView;
public UIView NativeView => ViewHandler.ContainerView ?? ViewHandler.NativeView;

public UIViewController ViewController => (ViewHandler as INativeViewHandler)?.ViewController;
public UIViewController ViewController => ViewHandler.ViewController;

public event EventHandler<VisualElementChangedEventArgs> ElementChanged;
public event EventHandler<PropertyChangedEventArgs> ElementPropertyChanged;
Expand Down
3 changes: 3 additions & 0 deletions src/Core/src/Platform/Android/WrapperView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ protected override void OnLayout(bool changed, int left, int top, int right, int
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
if (ChildCount == 0 || GetChildAt(0) is not View child)
{
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
return;
}

child.Measure(widthMeasureSpec, heightMeasureSpec);

Expand Down

0 comments on commit 59d330a

Please sign in to comment.