-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
BlazorWebView.cs
73 lines (60 loc) · 2.58 KB
/
BlazorWebView.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
using System;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.FileProviders;
using Microsoft.Maui.Controls;
namespace Microsoft.AspNetCore.Components.WebView.Maui
{
/// <summary>
/// A <see cref="View"/> that can render Blazor content.
/// </summary>
public partial class BlazorWebView : View, IBlazorWebView
{
internal const string AppHostAddress = "0.0.0.0";
private readonly JSComponentConfigurationStore _jSComponents = new();
/// <summary>
/// Initializes a new instance of <see cref="BlazorWebView"/>.
/// </summary>
public BlazorWebView()
{
RootComponents = new RootComponentsCollection(_jSComponents);
}
JSComponentConfigurationStore IBlazorWebView.JSComponents => _jSComponents;
/// <summary>
/// Gets or sets the path to the HTML file to render.
/// <para>This is an app relative path to the file such as <c>wwwroot\index.html</c></para>
/// </summary>
public string? HostPage { get; set; }
/// <inheritdoc />
public RootComponentsCollection RootComponents { get; }
/// <summary>
/// Allows customizing how links are opened.
/// By default, opens internal links in the webview and external links in an external app.
/// </summary>
public event EventHandler<UrlLoadingEventArgs>? UrlLoading;
/// <summary>
/// Raised before the web view is initialized. On some platforms this enables customizing the web view configuration.
/// </summary>
public event EventHandler<BlazorWebViewInitializingEventArgs>? BlazorWebViewInitializing;
/// <summary>
/// Raised after the web view is initialized but before any component has been rendered. The event arguments provide the instance of the platform-specific web view control.
/// </summary>
public event EventHandler<BlazorWebViewInitializedEventArgs>? BlazorWebViewInitialized;
/// <inheritdoc />
#if ANDROID
[System.Runtime.Versioning.SupportedOSPlatform("android21.0")]
#elif IOS
[System.Runtime.Versioning.SupportedOSPlatform("ios11.0")]
#endif
public virtual IFileProvider CreateFileProvider(string contentRootDir)
{
// Call into the platform-specific code to get that platform's asset file provider
return ((BlazorWebViewHandler)(Handler!)).CreateFileProvider(contentRootDir);
}
void IBlazorWebView.UrlLoading(UrlLoadingEventArgs args) =>
UrlLoading?.Invoke(this, args);
void IBlazorWebView.BlazorWebViewInitializing(BlazorWebViewInitializingEventArgs args) =>
BlazorWebViewInitializing?.Invoke(this, args);
void IBlazorWebView.BlazorWebViewInitialized(BlazorWebViewInitializedEventArgs args) =>
BlazorWebViewInitialized?.Invoke(this, args);
}
}