Browse Source

Fix android type exception

Max Katz 3 years ago
parent
commit
4315f4728f

+ 4 - 2
src/Android/Avalonia.Android/Platform/AndroidNativeControlHostImpl.cs

@@ -110,8 +110,10 @@ namespace Avalonia.Android.Platform
             public void HideWithSize(Size size)
             {
                 CheckDisposed();
+
+                size *= _attachedTo?._avaloniaView.TopLevelImpl.RenderScaling ?? 1;
                 _view.Visibility = ViewStates.Gone;
-                _view.LayoutParameters = new ViewGroup.LayoutParams(Math.Max(1, (int)size.Width), Math.Max(1, (int)size.Height));
+                _view.LayoutParameters = new FrameLayout.LayoutParams(Math.Max(1, (int)size.Width), Math.Max(1, (int)size.Height));
                 _view.RequestLayout();
             }
 
@@ -123,7 +125,7 @@ namespace Avalonia.Android.Platform
 
                 bounds *= _attachedTo._avaloniaView.TopLevelImpl.RenderScaling;
                 _view.Visibility = ViewStates.Visible;
-                _view.LayoutParameters = new ViewGroup.MarginLayoutParams(Math.Max(1, (int)bounds.Width), Math.Max(1, (int)bounds.Height))
+                _view.LayoutParameters = new FrameLayout.LayoutParams(Math.Max(1, (int)bounds.Width), Math.Max(1, (int)bounds.Height))
                 {
                     LeftMargin = (int)bounds.X,
                     TopMargin = (int)bounds.Y

+ 2 - 0
src/iOS/Avalonia.iOS/NativeControlHostImpl.cs

@@ -117,6 +117,8 @@ namespace Avalonia.iOS
             public void HideWithSize(Size size)
             {
                 CheckDisposed();
+                if (_attachedTo == null)
+                    return;
 
                 _view.Hidden = true;
                 _view.Frame = new CGRect(0d, 0d, Math.Max(1d, size.Width), Math.Max(1d, size.Height));