/
WindowHandlerStub.iOS.cs
77 lines (66 loc) · 1.84 KB
/
WindowHandlerStub.iOS.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using UIKit;
namespace Microsoft.Maui.DeviceTests
{
public class WindowHandlerStub : ElementHandler<IWindow, UIWindow>, IWindowHandler
{
TaskCompletionSource<bool> _finishedDisconnecting = new TaskCompletionSource<bool>();
public Task FinishedDisconnecting => _finishedDisconnecting.Task;
public static IPropertyMapper<IWindow, WindowHandlerStub> WindowMapper = new PropertyMapper<IWindow, WindowHandlerStub>(WindowHandler.Mapper)
{
[nameof(IWindow.Content)] = MapContent
};
private static void MapContent(WindowHandlerStub handler, IWindow window)
{
var view = window.Content.ToPlatform(handler.MauiContext);
if (window.Content is Shell)
{
var vc =
(window.Content.Handler as IPlatformViewHandler)
.ViewController;
handler.PlatformView.RootViewController.PresentViewController(vc, false, null);
}
else
{
handler.PlatformView.RootViewController.View.AddSubview(view);
}
}
protected override void DisconnectHandler(UIWindow platformView)
{
var vc = (VirtualView.Content.Handler as IPlatformViewHandler)
.ViewController;
if (VirtualView.Content is Shell)
{
platformView.RootViewController
.PresentedViewController.
DismissViewController(false,
() =>
{
_finishedDisconnecting.SetResult(true);
});
}
else
{
VirtualView
.Content
.ToPlatform()
.RemoveFromSuperview();
_finishedDisconnecting.SetResult(true);
}
base.DisconnectHandler(platformView);
}
public WindowHandlerStub()
: base(WindowMapper)
{
}
protected override UIWindow CreatePlatformElement()
{
return MauiContext.Services.GetService<UIWindow>();
}
}
}