This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba943d3
commit 39d1157
Showing
8 changed files
with
227 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
DrasticMaui/Tray/DrasticTrayUIViewController.MacCatalyst.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System; | ||
using CoreGraphics; | ||
using DrasticMaui.Options; | ||
using DrasticMaui.Tools; | ||
using Foundation; | ||
using UIKit; | ||
|
||
namespace DrasticMaui | ||
{ | ||
public class DrasticTrayUIViewController : UIViewController | ||
{ | ||
private UIViewController contentController; | ||
private UIImage? image; | ||
private UIWindow window; | ||
private DrasticTrayWindowOptions options; | ||
private DrasticTrayIcon trayIcon; | ||
|
||
public DrasticTrayUIViewController( | ||
UIWindow window, | ||
UIViewController contentController, | ||
DrasticTrayIcon trayIcon, | ||
DrasticTrayWindowOptions options) | ||
{ | ||
this.trayIcon = trayIcon; | ||
this.options = options; | ||
this.window = window; | ||
this.contentController = contentController; | ||
this.image = UIImage.GetSystemImage("cursorarrow.click.2"); | ||
this.SetupWindow(); | ||
} | ||
|
||
public async void ToggleVisibility() | ||
{ | ||
if (this.contentController?.View is null) | ||
{ | ||
return; | ||
} | ||
|
||
if (this.View is null) | ||
{ | ||
return; | ||
} | ||
|
||
//var frame = this.trayIcon.GetFrame(); | ||
//await this.window.SetFrameForUIWindow(new CGRect(500, 500, 1000, 1000)); | ||
var viewController = this.contentController; | ||
|
||
if (viewController.PresentingViewController is not null) | ||
{ | ||
viewController.DismissViewController(true, null); | ||
} | ||
else | ||
{ | ||
viewController.ModalPresentationStyle = UIModalPresentationStyle.Popover; | ||
viewController.PopoverPresentationController.SourceView = this.View; | ||
viewController.PopoverPresentationController.SourceRect = new CGRect(0, 0, 1, 1); | ||
viewController.PopoverPresentationController.PermittedArrowDirections = UIPopoverArrowDirection.Up; | ||
this.PresentViewController(viewController, true, null); | ||
} | ||
} | ||
|
||
public override void ViewDidAppear(bool animated) | ||
{ | ||
base.ViewDidAppear(animated); | ||
this.PrepareForAppearance(); | ||
this.ForceContentViewLayout(); | ||
} | ||
|
||
private async void PrepareForAppearance() | ||
{ | ||
if (this.window is not null) | ||
{ | ||
await this.window.ToggleTitleBarButtons(true); | ||
} | ||
} | ||
|
||
private void ForceContentViewLayout() | ||
{ | ||
if (this.contentController.View is not null) | ||
{ | ||
this.View?.AddSubview(this.contentController.View); | ||
this.contentController.View.Frame = new CoreGraphics.CGRect(0, 0, this.options.WindowWidth, this.options.WindowHeight); | ||
this.View?.LayoutIfNeeded(); | ||
this.contentController.View.RemoveFromSuperview(); | ||
} | ||
} | ||
|
||
private void SetupWindow() | ||
{ | ||
this.window.RootViewController = this; | ||
if (this.window.WindowScene?.Titlebar is null) | ||
{ | ||
return; | ||
} | ||
|
||
if (this.window.WindowScene?.SizeRestrictions is null) | ||
{ | ||
return; | ||
} | ||
|
||
this.window.WindowScene.Titlebar.TitleVisibility = UITitlebarTitleVisibility.Hidden; | ||
this.window.WindowScene.SizeRestrictions.MinimumSize = new CoreGraphics.CGSize(1, 1); | ||
this.window.WindowScene.SizeRestrictions.MaximumSize = new CoreGraphics.CGSize(1, 1); | ||
} | ||
} | ||
} |