Skip to content

Commit

Permalink
Merge branch 'main' into net9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamescaper committed Nov 10, 2024
2 parents a1e5a1f + c8dc3ca commit e5e5d6e
Show file tree
Hide file tree
Showing 15 changed files with 507 additions and 172 deletions.
133 changes: 68 additions & 65 deletions samples/ControlGallery/AppShell.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,82 +13,85 @@
@using ControlGallery.Views.Shell
@using ControlGallery.Views.Menus

<Shell BackgroundColor="_backgroundColor"
ForegroundColor="_foregroundColor"
UnselectedColor="_unselectedColor"
TabBarTitleColor="_tabBarTitleColor">
<Window Title="Main Window">
<Shell BackgroundColor="_backgroundColor"
ForegroundColor="_foregroundColor"
UnselectedColor="_unselectedColor"
TabBarTitleColor="_tabBarTitleColor">

@*Present data*@
<BoxViewPage />
<LabelPage />
<Shapes />
@*Present data*@
<BoxViewPage />
<LabelPage />
<Shapes />

@*Initiate commands*@
<ButtonPage />
<RefreshViewPage />
<SearchBarPage />
<SwipeViewPage />
@*Initiate commands*@
<ButtonPage />
<RefreshViewPage />
<SearchBarPage />
<SwipeViewPage />

@*Set values*@
<SliderPage />
<CheckboxPage />
<SwitchPage />
<RadioButtonPage />
<DatePickerPage />
<TimePickerPage />
@*Set values*@
<SliderPage />
<CheckboxPage />
<SwitchPage />
<RadioButtonPage />
<DatePickerPage />
<TimePickerPage />

@*Edit text*@
<EntryPage />
<EditorPage />
@*Edit text*@
<EntryPage />
<EditorPage />

@*Display collections*@
<CarouselViewPage />
<ShellSection Title="CollectionView">
<AddRemovePage />
<GridLayoutPage />
<SelectionPage />
<InfiniteScrollPage />
<DynamicItemsPage />
</ShellSection>
<PickerPage />
<TableViewPage />
<ListViewPage />
@*Display collections*@
<CarouselViewPage />
<ShellSection Title="CollectionView">
<AddRemovePage />
<GridLayoutPage />
<SelectionPage />
<InfiniteScrollPage />
<DynamicItemsPage />
</ShellSection>
<PickerPage />
<TableViewPage />
<ListViewPage />

@*Layouts*@
<AbsoluteLayoutPage />
<GridPage />
<FlexLayoutPage />
@*Layouts*@
<AbsoluteLayoutPage />
<GridPage />
<FlexLayoutPage />

@*Shell*@
<ShellContent Title="Shell Properties">
<ContentTemplate>
<ShellPropertiesPage @bind-ShellBackgroundColor="_backgroundColor"
@bind-ShellForegroundColor="_foregroundColor"
@bind-ShellUnselectedColor="_unselectedColor"
@bind-ShellTabBarTitleColor="_tabBarTitleColor" />
</ContentTemplate>
</ShellContent>
@*Shell*@
<ShellContent Title="Shell Properties">
<ContentTemplate>
<ShellPropertiesPage @bind-ShellBackgroundColor="_backgroundColor"
@bind-ShellForegroundColor="_foregroundColor"
@bind-ShellUnselectedColor="_unselectedColor"
@bind-ShellTabBarTitleColor="_tabBarTitleColor" />
</ContentTemplate>
</ShellContent>

<ShellItemsPage />
<ShellItemsPage />

@*Navigation*@
<ShellSection Title="Navigation">
<NavigationPage />
<UriNavigationPage />
</ShellSection>
@*Navigation*@
<ShellSection Title="Navigation">
<NavigationPage />
<UriNavigationPage />
</ShellSection>

@*Other*@
<ShadowsPage />
<GestureEvents />
<GestureRecognizersPage />
<ErrorBoundariesPage />
@*Other*@
<ShadowsPage />
<GestureEvents />
<GestureRecognizersPage />
<ErrorBoundariesPage />

@if (DeviceInfo.Platform == DevicePlatform.WinUI || DeviceInfo.Platform == DevicePlatform.MacCatalyst)
{
<ContextMenuPage />
<MenuBarPage />
}
</Shell>
@if (DeviceInfo.Platform == DevicePlatform.WinUI || DeviceInfo.Platform == DevicePlatform.MacCatalyst)
{
<ContextMenuPage />
<MenuBarPage />
<WindowsPage />
}
</Shell>
</Window>

@code {
Color _backgroundColor;
Expand Down
2 changes: 1 addition & 1 deletion samples/ControlGallery/Views/Menus/ContextMenuPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</ContentPage>

@code {
Color? _selectedColor = null;
Color _selectedColor = null;

void SelectColor(Color color) => _selectedColor = color;
}
7 changes: 7 additions & 0 deletions samples/ControlGallery/Views/WindowExample.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Window Title="New window">
<ContentPage>
<VerticalStackLayout>
<Label>Newly opened window.</Label>
</VerticalStackLayout>
</ContentPage>
</Window>
14 changes: 14 additions & 0 deletions samples/ControlGallery/Views/WindowsPage.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ContentPage Title="Windows">
<VerticalStackLayout>
<Button Text="Open Window" OnClick="OpenWindow" />
</VerticalStackLayout>
</ContentPage>

@code {
[Inject] INavigation Navigation { get; set; }

async Task OpenWindow()
{
await Navigation.OpenWindow<WindowExample>();
}
}
21 changes: 16 additions & 5 deletions src/BlazorBindings.Maui/BlazorBindingsApplication.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.Maui.Controls;
using BlazorBindings.Maui.Elements.Handlers;
using Microsoft.Maui.Controls;
using System.Runtime.ExceptionServices;

namespace BlazorBindings.Maui;

Expand Down Expand Up @@ -27,12 +29,21 @@ protected override Window CreateWindow(Microsoft.Maui.IActivationState activatio
}

var (componentType, parameters) = GetComponentToRender();
var window = new Window();
var task = renderer.AddComponent(componentType, window, parameters);
AwaitVoid(task);

return window;

var handler = new ApplicationWindowHandler();
var addComponentTask = renderer.AddComponent(componentType, handler, parameters);

if (addComponentTask.Exception != null)
{
// If exception was thrown during the sync execution - throw it straight away.
ExceptionDispatchInfo.Throw(addComponentTask.Exception.InnerException);
}

AwaitVoid(handler.WaitForWindowAsync());
return handler.TargetElement;

// async void is used here to crash the application if rendering fails.
static async void AwaitVoid(Task task) => await task;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using BlazorBindings.Maui.Extensions;
using MC = Microsoft.Maui.Controls;

namespace BlazorBindings.Maui.Elements.Handlers;

// We allow root component to be either a window, or a page. Therefore, this handler supports both.
internal class ApplicationWindowHandler : IContainerElementHandler
{
private TaskCompletionSource<object> _taskCompletionSource;

public void AddChild(object child, int physicalSiblingIndex)
{
TargetElement = child switch
{
MC.Window window => window,
MC.Page page => new MC.Window(page),
_ => throw new InvalidOperationException($"Element '{child.GetType().FullName}' is not supported as an application root.")
};
}

public void ReplaceChild(int physicalSiblingIndex, object oldChild, object newChild)
{
if (oldChild is MC.Window)
throw new InvalidOperationException("Removing application root window is not supported.");

TargetElement.Page = newChild.Cast<MC.Page>();
}

public void RemoveChild(object child, int physicalSiblingIndex)
{
if (child is MC.Window)
throw new InvalidOperationException("Removing application root window is not supported.");

TargetElement.Page = null;
}

public Task WaitForWindowAsync()
{
if (TargetElement is not null)
{
return Task.CompletedTask;
}

_taskCompletionSource ??= new();
return _taskCompletionSource.Task;
}

public MC.Window TargetElement { get; private set; }

object IElementHandler.TargetElement => TargetElement;
}
25 changes: 0 additions & 25 deletions src/BlazorBindings.Maui/Elements/Handlers/WindowHandler.cs

This file was deleted.

Loading

0 comments on commit e5e5d6e

Please sign in to comment.