Skip to content

Commit

Permalink
HybridWebView: Invoke .NET methods from JavaScript (#25077)
Browse files Browse the repository at this point in the history
* Juno: check in to lego/hb_7241b85a-f216-4d55-a9fa-d8030c736df5_20240925231640755. (#24935)

* Cleanup

* WIP: HybridWebView: Invoke .NET methods from JavaScript

* Cleanup

* WIP: Make Windows work end-to-end

* Start adding tests

* Improve tests

* Add Android

* iOS/MacCat

* Suppress

* Suppress

* Try un-rooting HybridWebViewHandler

* Use RuntimeFeature.IsDynamicCodeSupported

* Flip if

* Annotate differently

* Make InvokeJavaScriptType not an auto-property

Fixes:

    ILC: IL2114: Microsoft.Maui.Controls.HybridWebView.<Microsoft.Maui.IHybridWebView.InvokeJavaScriptType>k__BackingField: 'DynamicallyAccessedMembersAttribute' on 'Microsoft.Maui.Controls.HybridWebView' or one of its base types

* Revert "Make InvokeJavaScriptType not an auto-property"

This reverts commit d855220.

* Introduce Microsoft.Maui.RuntimeFeature.IsHybridWebViewSupported

* Update FeatureSwitches.md

* Fix [UnconditionalSuppressMessage] on Windows

* Missed a spot on Windows

* Seeing if `!RuntimeFeature` is an issue

* %(Trim) was inverted!

* Move [RUC] and [RDC] to types

* Only check RuntimeFeature.IsHybridWebViewSupported in one place

* Update MauiHybridWebView.cs

* Update HybridWebViewHandler.Windows.cs

* Duplicate `Microsoft.Maui.RuntimeFeature`

* Fix `_invokeJavaScriptType` field

* Expect 1 warning

---------

Co-authored-by: CSIGS@microsoft.com <csigs@users.noreply.github.com>
Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent e2e6f6c commit 14f33bf
Show file tree
Hide file tree
Showing 49 changed files with 3,452 additions and 96 deletions.
7 changes: 6 additions & 1 deletion docs/design/FeatureSwitches.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ The following switches are toggled for applications running on Mono for `TrimMod
| MauiImplicitCastOperatorsUsageViaReflectionSupport | Microsoft.Maui.RuntimeFeature.IsImplicitCastOperatorsUsageViaReflectionSupported | When disabled, MAUI won't look for implicit cast operators when converting values from one type to another. This feature is not trim-compatible. |
| _MauiBindingInterceptorsSupport | Microsoft.Maui.RuntimeFeature.AreBindingInterceptorsSupported | When disabled, MAUI won't intercept any calls to `SetBinding` methods and try to compile them. Enabled by default. |
| MauiEnableXamlCBindingWithSourceCompilation | Microsoft.Maui.RuntimeFeature.XamlCBindingWithSourceCompilationEnabled | When enabled, MAUI will compile all bindings, including those where the `Source` property is used. |
| MauiHybridWebViewSupported | Microsoft.Maui.RuntimeFeature.IsHybridWebViewSupported | Enables HybridWebView, which makes use of dynamic System.Text.Json serialization features |

## MauiEnableIVisualAssemblyScanning

When this feature is not enabled, custom and third party `IVisual` types will not be automatically discovered and registerd.
When this feature is not enabled, custom and third party `IVisual` types will not be automatically discovered and registered.

## MauiShellSearchResultsRendererDisplayMemberNameSupported

Expand Down Expand Up @@ -43,6 +44,10 @@ This feature is a counterpart of [XAML Compiled bindings](https://learn.microsof

It is necessary to use this feature instead of the string-based bindings in NativeAOT apps and in apps with full trimming enabled.

## MauiHybridWebViewSupported

When this feature is disabled, `HybridWebView` will not be available. This is the default for projects using `TrimMode=full` or `PublishAot=true`.

### Example use-case

String-based binding in code:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<?xml version="1.0" encoding="utf-8"?>
<LCX SchemaVersion="6.0" Name="D:\a\_work\1\s\src\Templates\src\templates\maui-blazor-solution\.template.config\localize\templatestrings.json" PsrId="306" SrcCul="en-US" xmlns="http://schemas.microsoft.com/locstudio/2006/6/lcx" TgtCul="cs-CZ">
<OwnedComments>
<Cmt Name="Dev" />
<Cmt Name="LcxAdmin" />
<Cmt Name="Rccx" />
</OwnedComments>
<Item ItemId=";String Table" ItemType="0" PsrId="306" Leaf="false">
<Disp Icon="Expand" Expand="true" Disp="true" LocTbl="false" />
<Item ItemId=";Strings" ItemType="0" PsrId="306" Leaf="false">
<Disp Icon="Str" Disp="true" LocTbl="false" />
<Item ItemId=";author" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Microsoft]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[A multi-project app for creating a .NET MAUI Blazor Hybrid application with a Blazor Web project with a shared user interface.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";name" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[.NET MAUI Blazor Hybrid and Web App]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";postActions/openInEditor/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Opens Shared Pages/Home.razor in the editor.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/AllInteractive/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Configures whether to make every page interactive by applying an interactive render mode at the top level. If false, pages will use static server rendering by default, and can be marked interactive on a per-page or per-component basis.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/AllInteractive/displayName" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[_Enable interactive rendering globally throughout the site]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/Empty/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Configures whether to omit sample pages and styling that demonstrate basic usage patterns.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/ExcludeLaunchSettings/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Whether to exclude launchSettings.json from the generated template.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/Framework/choices/DOTNET_TFM_VALUE/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Target DOTNET_TFM_VALUE]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/Framework/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[The target framework for the project.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/IncludeSampleContent/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Configures whether to add sample pages and styling to demonstrate basic usage patterns.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/IncludeSampleContent/displayName" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[_Include sample pages]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/InteractivityPlatform/choices/Auto/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Uses Server while downloading WebAssembly assets, then uses WebAssembly]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/InteractivityPlatform/choices/Auto/displayName" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Auto (Server and WebAssembly)]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/InteractivityPlatform/choices/None/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[No interactivity (static server rendering only)]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/InteractivityPlatform/choices/None/displayName" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[None]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/InteractivityPlatform/choices/Server/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Runs on the server]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/InteractivityPlatform/choices/Server/displayName" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Server]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/InteractivityPlatform/choices/WebAssembly/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Runs in the browser using WebAssembly]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/InteractivityPlatform/choices/WebAssembly/displayName" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[WebAssembly]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/InteractivityPlatform/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Chooses which interactive render mode to use for interactive components]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/InteractivityPlatform/displayName" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[_Interactive render mode]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/NoHttps/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Whether to turn off HTTPS. This option only applies if Individual isn't used for --auth.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/UseProgramMain/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Whether to generate an explicit Program class and Main method instead of top-level statements.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/UseProgramMain/displayName" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Do not use _top-level statements]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/UserSecretsId/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[The ID to use for secrets (use with Individual auth).]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/applicationId/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Overrides the $(ApplicationId) in the project]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/iisHttpPort/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Port number to use for the IIS Express HTTP endpoint in launchSettings.json.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/iisHttpsPort/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Port number to use for the IIS Express HTTPS endpoint in launchSettings.json. This option is only applicable when the parameter no-https is not used (no-https will be ignored if Individual auth is used).]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/kestrelHttpPort/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Port number to use for the HTTP endpoint in launchSettings.json.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";symbols/kestrelHttpsPort/description" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Port number to use for the HTTPS endpoint in launchSettings.json. This option is only applicable when the parameter no-https is not used (no-https will be ignored if Individual auth is used).]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
</Item>
</Item>
<Settings Name="@vsLocTools@\default.lss" Type="Lss" /></LCX>
Loading

0 comments on commit 14f33bf

Please sign in to comment.