Browse Source

alway setContentSize even before show, but preconstrain the size.

Dan Walmsley 2 years ago
parent
commit
c8b868a558

+ 2 - 5
native/Avalonia.Native/src/OSX/AvnView.mm

@@ -127,11 +127,8 @@
         [self updateRenderTarget];
 
         auto reason = [self inLiveResize] ? ResizeUser : _resizeReason;
-        
-        if(_parent->IsShown())
-        {
-            _parent->BaseEvents->Resized(AvnSize{newSize.width, newSize.height}, reason);
-        }
+
+        _parent->BaseEvents->Resized(AvnSize{newSize.width, newSize.height}, reason);
     }
 }
 

+ 10 - 14
native/Avalonia.Native/src/OSX/WindowBaseImpl.mm

@@ -4,6 +4,7 @@
 //
 
 #import <AppKit/AppKit.h>
+#import <Cocoa/Cocoa.h>
 #include "common.h"
 #include "AvnView.h"
 #include "menu.h"
@@ -293,29 +294,24 @@ HRESULT WindowBaseImpl::Resize(double x, double y, AvnPlatformResizeReason reaso
         }
 
         @try {
-            if(x != lastSize.width || y != lastSize.height) {
-                lastSize = NSSize{x, y};
-
+            if(x != lastSize.width || y != lastSize.height)
+            {
                 if (!_shown) {
-                    // Before the window is shown, Cocoa wont give Resized events
-                    // constraining the window to the maximum size available on the monitor.
-                    // we have to emulated this behavior that Avalonia relies on.
                     auto screenSize = [Window screen].visibleFrame.size;
 
-                    if(x > screenSize.width){
+                    if (x > screenSize.width) {
                         x = screenSize.width;
                     }
 
-                    if(y > screenSize.height)
-                    {
+                    if (y > screenSize.height) {
                         y = screenSize.height;
                     }
-
-                    BaseEvents->Resized(AvnSize{x, y}, reason);
-                } else if (Window != nullptr) {
-                    [Window setContentSize:lastSize];
-                    [Window invalidateShadow];
                 }
+
+                lastSize = NSSize{x, y};
+
+                [Window setContentSize:lastSize];
+                [Window invalidateShadow];
             }
         }
         @finally {