This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 501
/
Copy pathBrowser.ios.cs
43 lines (36 loc) · 1.76 KB
/
Browser.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
using System;
using System.Threading.Tasks;
using Foundation;
using SafariServices;
using UIKit;
namespace Xamarin.Essentials
{
public static partial class Browser
{
static async Task<bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options)
{
switch (options.LaunchMode)
{
case BrowserLaunchMode.SystemPreferred:
var nativeUrl = new NSUrl(uri.AbsoluteUri);
var sfViewController = new SFSafariViewController(nativeUrl, false);
var vc = Platform.GetCurrentViewController();
if (options.PreferredToolbarColor.HasValue)
sfViewController.PreferredBarTintColor = options.PreferredToolbarColor.Value.ToPlatformColor();
if (options.PreferredControlColor.HasValue)
sfViewController.PreferredControlTintColor = options.PreferredControlColor.Value.ToPlatformColor();
if (sfViewController.PopoverPresentationController != null)
sfViewController.PopoverPresentationController.SourceView = vc.View;
if (options.HasFlag(BrowserLaunchFlags.PresentAsFormSheet))
sfViewController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
else if (options.HasFlag(BrowserLaunchFlags.PresentAsPageSheet))
sfViewController.ModalPresentationStyle = UIModalPresentationStyle.PageSheet;
await vc.PresentViewControllerAsync(sfViewController, true);
break;
case BrowserLaunchMode.External:
return await Launcher.PlatformOpenAsync(uri);
}
return true;
}
}
}