Skip to content

Commit

Permalink
Implement more mac api
Browse files Browse the repository at this point in the history
  • Loading branch information
slluis committed Oct 14, 2021
1 parent fdd606d commit 3f858a8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 35 deletions.
9 changes: 8 additions & 1 deletion src/Controls/samples/Maui.Controls.Sample.Macos/App.cs
Expand Up @@ -10,7 +10,14 @@ public class App: Application
{
public App()
{
MainPage = new ContentPage();
var page = new ContentPage();
page.Title = "Hello!";
var label = new Label
{
Text = "Hi Maui"
};
page.Content = label;
MainPage = page;
}
}
}
26 changes: 12 additions & 14 deletions src/Core/src/Handlers/View/ViewHandlerOfT.Mac.cs
Expand Up @@ -47,24 +47,22 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra
return new Size(widthConstraint, heightConstraint);
}

throw new NotImplementedException();
//var sizeThatFits = nativeView.SizeThatFits(new CoreGraphics.CGSize((float)widthConstraint, (float)heightConstraint));
var sizeThatFits = nativeView is MauiView mauiView ? mauiView.SizeThatFits(new CoreGraphics.CGSize((float)widthConstraint, (float)heightConstraint)) : nativeView.FittingSize;

//var size = new Size(
// sizeThatFits.Width == float.PositiveInfinity ? double.PositiveInfinity : sizeThatFits.Width,
// sizeThatFits.Height == float.PositiveInfinity ? double.PositiveInfinity : sizeThatFits.Height);
var size = new Size(
sizeThatFits.Width == float.PositiveInfinity ? double.PositiveInfinity : sizeThatFits.Width,
sizeThatFits.Height == float.PositiveInfinity ? double.PositiveInfinity : sizeThatFits.Height);

//if (double.IsInfinity(size.Width) || double.IsInfinity(size.Height))
//{
//
// nativeView.SizeToFit();
// size = new Size(nativeView.Frame.Width, nativeView.Frame.Height);
//}
if (double.IsInfinity(size.Width) || double.IsInfinity(size.Height))
{
nativeView.SetFrameSize(nativeView.FittingSize);
size = new Size(nativeView.Frame.Width, nativeView.Frame.Height);
}

//var finalWidth = ResolveConstraints(size.Width, VirtualView.Width, VirtualView.MinimumWidth, VirtualView.MaximumWidth);
//var finalHeight = ResolveConstraints(size.Height, VirtualView.Height, VirtualView.MinimumHeight, VirtualView.MaximumHeight);
var finalWidth = ResolveConstraints(size.Width, VirtualView.Width, VirtualView.MinimumWidth, VirtualView.MaximumWidth);
var finalHeight = ResolveConstraints(size.Height, VirtualView.Height, VirtualView.MinimumHeight, VirtualView.MaximumHeight);

//return new Size(finalWidth, finalHeight);
return new Size(finalWidth, finalHeight);
}

double ResolveConstraints(double measured, double exact, double min, double max)
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/LifecycleEvents/Mac/MacLifecycle.cs
Expand Up @@ -11,7 +11,7 @@ public static class MacLifecycle
public delegate bool FinishedLaunching(NSApplication application, NSDictionary launchOptions);
public delegate void OnActivated(NSApplication application);
public delegate void OnResignActivation(NSApplication application);
public delegate bool OpenUrl(NSApplication app, NSUrl url, NSDictionary options);
public delegate bool OpenUrls(NSApplication app, NSUrl[] url);
//public delegate void PerformActionForShortcutItem(NSApplication application, NSApplicationShortcutItem shortcutItem, UIOperationHandler completionHandler);
public delegate void WillEnterForeground(NSApplication application);
public delegate void WillTerminate(NSApplication application);
Expand Down
Expand Up @@ -8,7 +8,7 @@ public static class MacLifecycleBuilderExtensions
public static IMacLifecycleBuilder FinishedLaunching(this IMacLifecycleBuilder lifecycle, MacLifecycle.FinishedLaunching del) => lifecycle.OnEvent(del);
public static IMacLifecycleBuilder OnActivated(this IMacLifecycleBuilder lifecycle, MacLifecycle.OnActivated del) => lifecycle.OnEvent(del);
public static IMacLifecycleBuilder OnResignActivation(this IMacLifecycleBuilder lifecycle, MacLifecycle.OnResignActivation del) => lifecycle.OnEvent(del);
public static IMacLifecycleBuilder OpenUrl(this IMacLifecycleBuilder lifecycle, MacLifecycle.OpenUrl del) => lifecycle.OnEvent(del);
public static IMacLifecycleBuilder OpenUrls(this IMacLifecycleBuilder lifecycle, MacLifecycle.OpenUrls del) => lifecycle.OnEvent(del);
// public static IMacLifecycleBuilder PerformActionForShortcutItem(this IMacLifecycleBuilder lifecycle, MacLifecycle.PerformActionForShortcutItem del) => lifecycle.OnEvent(del);
public static IMacLifecycleBuilder WillEnterForeground(this IMacLifecycleBuilder lifecycle, MacLifecycle.WillEnterForeground del) => lifecycle.OnEvent(del);
public static IMacLifecycleBuilder WillTerminate(this IMacLifecycleBuilder lifecycle, MacLifecycle.WillTerminate del) => lifecycle.OnEvent(del);
Expand Down
37 changes: 19 additions & 18 deletions src/Core/src/Platform/Mac/MauiUIApplicationDelegate.cs
Expand Up @@ -78,14 +78,15 @@ NSWindow CreateNativeWindow()

public override void OpenUrls(NSApplication application, NSUrl[] urls)
{
//var wasHandled = false;
var wasHandled = false;

//Services?.InvokeLifecycleEvents<MacLifecycle.OpenUrl>(del =>
//{
// wasHandled = del(application, url, options) || wasHandled;
//});
Services?.InvokeLifecycleEvents<MacLifecycle.OpenUrls>(del =>
{
wasHandled = del(application, urls);
});

//return wasHandled || base.OpenUrl(application, url, options);
if (!wasHandled)
base.OpenUrls(application, urls);
}

//public override void PerformActionForShortcutItem(NSApplication application, UIApplicationShortcutItem shortcutItem, UIOperationHandler completionHandler)
Expand All @@ -105,20 +106,20 @@ public override void OpenUrls(NSApplication application, NSUrl[] urls)
// return wasHandled || base.ContinueUserActivity(application, userActivity, completionHandler);
//}

//public override void OnActivated(NSApplication application)
//{
// Services?.InvokeLifecycleEvents<MacLifecycle.OnActivated>(del => del(application));
//}
public override void DidBecomeActive(NSNotification notification)
{
Services?.InvokeLifecycleEvents<MacLifecycle.OnActivated>(del => del(NSApplication.SharedApplication));
}

//public override void OnResignActivation(NSApplication application)
//{
// Services?.InvokeLifecycleEvents<MacLifecycle.OnResignActivation>(del => del(application));
//}
public override void DidResignActive(NSNotification notification)
{
Services?.InvokeLifecycleEvents<MacLifecycle.OnResignActivation>(del => del(NSApplication.SharedApplication));
}

//public override void WillTerminate(NSApplication application)
//{
// Services?.InvokeLifecycleEvents<MacLifecycle.WillTerminate>(del => del(application));
//}
public override void WillTerminate(NSNotification notification)
{
Services?.InvokeLifecycleEvents<MacLifecycle.WillTerminate>(del => del(NSApplication.SharedApplication));
}

//public override void DidEnterBackground(NSApplication application)
//{
Expand Down

0 comments on commit 3f858a8

Please sign in to comment.