-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58fb075
commit 844b484
Showing
19 changed files
with
823 additions
and
7 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
76 changes: 76 additions & 0 deletions
76
src/Controls/samples/Controls.Sample.Embedding/Shared/EmbeddingScenarios.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,76 @@ | ||
using Microsoft.Maui.Platform; | ||
using Microsoft.Maui.Controls.Embedding; | ||
|
||
#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 Maui.Controls.Sample; | ||
|
||
class EmbeddingScenarios | ||
{ | ||
public interface IScenario | ||
{ | ||
(MyMauiContent, PlatformView) Embed(PlatformWindow window); | ||
} | ||
|
||
public class Scenario1_Basic : IScenario | ||
{ | ||
public (MyMauiContent, PlatformView) Embed(PlatformWindow window) | ||
{ | ||
var mauiApp = MauiProgram.CreateMauiApp(); | ||
#if ANDROID | ||
var mauiContext = new MauiContext(mauiApp.Services, window); | ||
#else | ||
var mauiContext = new MauiContext(mauiApp.Services); | ||
#endif | ||
var mauiView = new MyMauiContent(); | ||
var nativeView = mauiView.ToPlatform(mauiContext); | ||
return (mauiView, nativeView); | ||
} | ||
} | ||
|
||
public class Scenario2_Scoped : IScenario | ||
{ | ||
public (MyMauiContent, PlatformView) Embed(PlatformWindow window) | ||
{ | ||
var mauiApp = MauiProgram.CreateMauiApp(); | ||
var mauiView = new MyMauiContent(); | ||
var nativeView = mauiView.ToPlatformEmbedded(mauiApp, window); | ||
return (mauiView, nativeView); | ||
} | ||
} | ||
|
||
public class Scenario3_Correct : IScenario | ||
{ | ||
public static class MyEmbeddedMauiApp | ||
{ | ||
static MauiApp? _shared; | ||
|
||
public static MauiApp Shared => _shared ??= MauiProgram.CreateMauiApp(); | ||
} | ||
|
||
PlatformWindow? _window; | ||
IMauiContext? _windowContext; | ||
|
||
public IMauiContext WindowContext => | ||
_windowContext ??= MyEmbeddedMauiApp.Shared.CreateEmbeddedWindowContext(_window ?? throw new InvalidOperationException()); | ||
|
||
public (MyMauiContent, PlatformView) Embed(PlatformWindow window) | ||
{ | ||
_window ??= window; | ||
|
||
var context = WindowContext; | ||
var mauiView = new MyMauiContent(); | ||
var nativeView = mauiView.ToPlatformEmbedded(context); | ||
return (mauiView, nativeView); | ||
} | ||
} | ||
} |
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.