Browse Source

OSX impl for HideWithSize

Nikita Tsukanov 5 years ago
parent
commit
cba236d9a3

+ 2 - 2
native/Avalonia.Native/inc/avalonia-native.h

@@ -493,8 +493,8 @@ AVNCOM(IAvnNativeControlHostTopLevelAttachment, 21) : IUnknown
     virtual void* GetParentHandle() = 0;
     virtual HRESULT InitializeWithChildHandle(void* child) = 0;
     virtual HRESULT AttachTo(IAvnNativeControlHost* host) = 0;
-    virtual void MoveTo(float x, float y, float width, float height) = 0;
-    virtual void Hide() = 0;
+    virtual void ShowInBounds(float x, float y, float width, float height) = 0;
+    virtual void HideWithSize(float width, float height) = 0;
     virtual void ReleaseChild() = 0;
 };
 

+ 18 - 3
native/Avalonia.Native/src/OSX/controlhost.mm

@@ -97,7 +97,7 @@ public:
         return S_OK;
     };
     
-    virtual void MoveTo(float x, float y, float width, float height) override
+    virtual void ShowInBounds(float x, float y, float width, float height) override
     {
         if(_child == nil)
             return;
@@ -106,7 +106,7 @@ public:
             IAvnNativeControlHostTopLevelAttachment* slf = this;
             slf->AddRef();
             dispatch_async(dispatch_get_main_queue(), ^{
-                slf->MoveTo(x, y, width, height);
+                slf->ShowInBounds(x, y, width, height);
                 slf->Release();
             });
             return;
@@ -122,9 +122,24 @@ public:
             [[_holder superview] setNeedsDisplay:true];
     }
     
-    virtual void Hide() override
+    virtual void HideWithSize(float width, float height) override
     {
+        if(_child == nil)
+            return;
+        if(AvnInsidePotentialDeadlock::IsInside())
+        {
+            IAvnNativeControlHostTopLevelAttachment* slf = this;
+            slf->AddRef();
+            dispatch_async(dispatch_get_main_queue(), ^{
+                slf->HideWithSize(width, height);
+                slf->Release();
+            });
+            return;
+        }
+        
+        NSRect frame = {0, 0, width, height};
         [_holder setHidden: true];
+        [_child setFrame: frame];
     }
     
     virtual void ReleaseChild() override

+ 2 - 3
src/Avalonia.Native/NativeControlHostImpl.cs

@@ -116,8 +116,7 @@ namespace Avalonia.Native
 
             public void HideWithSize(Size size)
             {
-                //TODO
-                _native?.Hide();
+                _native.HideWithSize(Math.Max(1, (float)size.Width), Math.Max(1, (float)size.Height));
             }
             
             public void ShowInBounds(Rect bounds)
@@ -126,7 +125,7 @@ namespace Avalonia.Native
                     throw new InvalidOperationException("Native control isn't attached to a toplevel");
                 bounds = new Rect(bounds.X, bounds.Y, Math.Max(1, bounds.Width),
                     Math.Max(1, bounds.Height));
-                _native.MoveTo((float) bounds.X, (float) bounds.Y, (float) bounds.Width, (float) bounds.Height);
+                _native.ShowInBounds((float) bounds.X, (float) bounds.Y, (float) bounds.Width, (float) bounds.Height);
             }
 
             public void InitWithChild(IPlatformHandle handle)