-
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 embedding sample and code (#23642)
* Add support for MAUI embedding * Move things around a bit * Make these APIs public to CT.Maui.Embedding * Update EmbeddedWindowHandler.iOS.cs * Update EmbeddedWindowHandler.iOS.cs * Embedding things are platform only * tests use it
- Loading branch information
1 parent
db7dd11
commit a2fdea0
Showing
25 changed files
with
1,271 additions
and
255 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
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
53 changes: 53 additions & 0 deletions
53
src/Controls/samples/Controls.Sample.Embedding/Shared/EmbeddingReflection.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,53 @@ | ||
#if ANDROID | ||
using PlatformView = Android.Views.View; | ||
using PlatformWindow = Android.App.Activity; | ||
#elif IOS || MACCATALYST | ||
using PlatformView = UIKit.UIView; | ||
using PlatformWindow = UIKit.UIWindow; | ||
#elif WINDOWS | ||
using PlatformView = Microsoft.UI.Xaml.FrameworkElement; | ||
using PlatformWindow = Microsoft.UI.Xaml.Window; | ||
#endif | ||
|
||
namespace Microsoft.Maui.Controls.Embedding; | ||
|
||
/// <summary> | ||
/// This class is just here to serve as a reflection-based bridge to the EmbeddingExtensions class. | ||
/// </summary> | ||
static class EmbeddingReflection | ||
{ | ||
public static MauiAppBuilder UseMauiEmbeddedApp<TApp>(this MauiAppBuilder builder) | ||
where TApp : class, IApplication | ||
{ | ||
typeof(DynamicResourceExtension).Assembly // Controls.Xaml | ||
.GetType("Microsoft.Maui.Controls.Embedding.EmbeddingExtensions")! | ||
.GetMethod("UseMauiEmbeddedApp", 1, [ typeof(MauiAppBuilder) ])! | ||
.MakeGenericMethod(typeof(TApp)) | ||
.Invoke(null, [ builder ]); | ||
return builder; | ||
} | ||
|
||
public static IMauiContext CreateEmbeddedWindowContext(this MauiApp mauiApp, PlatformWindow platformWindow) | ||
{ | ||
return (IMauiContext)typeof(Application).Assembly // Controls.Core | ||
.GetType("Microsoft.Maui.Controls.Embedding.EmbeddingExtensions")! | ||
.GetMethod("CreateEmbeddedWindowContext", [ typeof(MauiApp), typeof(PlatformWindow) ])! | ||
.Invoke(null, [ mauiApp, platformWindow ])!; | ||
} | ||
|
||
public static PlatformView ToPlatformEmbedded(this IElement element, IMauiContext context) | ||
{ | ||
return (PlatformView)typeof(Application).Assembly // Controls.Core | ||
.GetType("Microsoft.Maui.Controls.Embedding.EmbeddingExtensions")! | ||
.GetMethod("ToPlatformEmbedded", [ typeof(IElement), typeof(IMauiContext) ])! | ||
.Invoke(null, [ element, context ])!; | ||
} | ||
|
||
public static PlatformView ToPlatformEmbedded(this IElement element, MauiApp mauiApp, PlatformWindow platformWindow) | ||
{ | ||
return (PlatformView)typeof(Application).Assembly // Controls.Core | ||
.GetType("Microsoft.Maui.Controls.Embedding.EmbeddingExtensions")! | ||
.GetMethod("ToPlatformEmbedded", [ typeof(IElement), typeof(MauiApp), typeof(PlatformWindow) ])! | ||
.Invoke(null, [ element, mauiApp, platformWindow ])!; | ||
} | ||
} |
Oops, something went wrong.