-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for JS root components in BlazorWebView (#2293)
* Works in .NET MAUI, WPF, and WinForms
- Loading branch information
Showing
23 changed files
with
300 additions
and
82 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
30 changes: 30 additions & 0 deletions
30
src/BlazorWebView/samples/WebViewAppShared/MyDynamicComponent.razor
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,30 @@ | ||
@implements IAsyncDisposable | ||
|
||
<div class="my-dynamic-root-component"> | ||
<p> | ||
This is a Blazor component. | ||
</p> | ||
<p> | ||
Click count: <strong class="click-count">@clicks</strong> | ||
(will increment in steps of <strong class="increment-amount-value">@IncrementAmount</strong>) | ||
</p> | ||
|
||
<button class="increment" @onclick="Increment">Increment</button> | ||
|
||
</div> | ||
|
||
@code { | ||
[Parameter] public int IncrementAmount { get; set; } = 7; | ||
|
||
int clicks; | ||
|
||
void Increment() | ||
{ | ||
clicks += IncrementAmount; | ||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
await Task.Delay(1000); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/BlazorWebView/samples/WebViewAppShared/MyDynamicComponent.razor.css
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,5 @@ | ||
.my-dynamic-root-component { | ||
border: 2px dashed blue; | ||
padding: 1em; | ||
margin: 1em 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using Microsoft.AspNetCore.Components.Web; | ||
|
||
namespace Microsoft.AspNetCore.Components.WebView.Maui | ||
{ | ||
public class BlazorWebView : Microsoft.Maui.Controls.View, IBlazorWebView | ||
{ | ||
private readonly JSComponentConfigurationStore _jSComponents = new(); | ||
|
||
public BlazorWebView() | ||
{ | ||
RootComponents = new RootComponentsCollection(_jSComponents); | ||
} | ||
|
||
JSComponentConfigurationStore IBlazorWebView.JSComponents => _jSComponents; | ||
|
||
public string? HostPage { get; set; } | ||
|
||
public ObservableCollection<RootComponent> RootComponents { get; } = new(); | ||
public RootComponentsCollection RootComponents { get; } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using Microsoft.AspNetCore.Components.Web; | ||
using Microsoft.Maui; | ||
|
||
namespace Microsoft.AspNetCore.Components.WebView.Maui | ||
{ | ||
public interface IBlazorWebView : IView | ||
{ | ||
string? HostPage { get; set; } | ||
ObservableCollection<RootComponent> RootComponents { get; } | ||
RootComponentsCollection RootComponents { get; } | ||
JSComponentConfigurationStore JSComponents { get; } | ||
} | ||
} |
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,17 @@ | ||
using System.Collections.ObjectModel; | ||
using Microsoft.AspNetCore.Components.Web; | ||
|
||
namespace Microsoft.AspNetCore.Components.WebView.Maui | ||
{ | ||
public class RootComponentsCollection : ObservableCollection<RootComponent>, IJSComponentConfiguration | ||
{ | ||
private readonly JSComponentConfigurationStore _jSComponents; | ||
|
||
public RootComponentsCollection(JSComponentConfigurationStore jSComponents) | ||
{ | ||
_jSComponents = jSComponents; | ||
} | ||
|
||
public JSComponentConfigurationStore JSComponents => _jSComponents; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/BlazorWebView/src/Maui/WebViewManagerCreatedEventArgs.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,12 @@ | ||
namespace Microsoft.AspNetCore.Components.WebView.Maui | ||
{ | ||
public class WebViewManagerCreatedEventArgs | ||
{ | ||
public WebViewManagerCreatedEventArgs(WebViewManager webViewManager) | ||
{ | ||
WebViewManager = webViewManager; | ||
} | ||
|
||
public WebViewManager WebViewManager { get; } | ||
} | ||
} |
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
Oops, something went wrong.