-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathEmbedSample.Browser.cs
46 lines (37 loc) · 1.28 KB
/
EmbedSample.Browser.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
using System;
using System.Runtime.InteropServices.JavaScript;
using Avalonia.Platform;
using Avalonia.Browser;
using ControlCatalog.Pages;
using System.Threading.Tasks;
namespace ControlCatalog.Browser;
public class EmbedSampleWeb : INativeDemoControl
{
public IPlatformHandle CreateControl(bool isSecond, IPlatformHandle parent, Func<IPlatformHandle> createDefault)
{
if (isSecond)
{
var iframe = EmbedInterop.CreateElement("iframe");
iframe.SetProperty("src", "https://www.youtube.com/embed/kZCIporjJ70");
return new JSObjectControlHandle(iframe);
}
else
{
var parentContainer = (JSObjectControlHandle)createDefault();
AddButton(parentContainer.Object);
return parentContainer;
static async void AddButton(JSObject parent)
{
await JSHost.ImportAsync("embed.js", "../embed.js");
EmbedInterop.AddAppButton(parent);
}
}
}
}
internal static partial class EmbedInterop
{
[JSImport("globalThis.document.createElement")]
public static partial JSObject CreateElement(string tagName);
[JSImport("addAppButton", "embed.js")]
public static partial void AddAppButton(JSObject parentObject);
}