Skip to content

Commit

Permalink
Popup v6 windows (#1086)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Minnick <[email protected]>
Co-authored-by: Pedro Jesus <[email protected]>
Co-authored-by: Shaun Lawrence <[email protected]>
  • Loading branch information
4 people authored Aug 9, 2023
1 parent bc38859 commit f765132
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,21 @@
<ResourceDictionary>
<Style x:Key="Header"
TargetType="Label">
<Setter Property="VerticalOptions" Value="CenterAndExpand" />
<Setter Property="HorizontalOptions" Value="CenterAndExpand" />
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="Margin" Value="15, 10" />
</Style>
<Style TargetType="ScrollView">
<Setter Property="VerticalOptions" Value="FillAndExpand" />
</Style>
<Style x:Key="ItemsLayout"
TargetType="StackLayout">
<Setter Property="Spacing" Value="16" />
<Setter Property="VerticalOptions" Value="Fill" />
</Style>
</ResourceDictionary>
</ContentPage.Resources>

<ScrollView>
<Grid ColumnDefinitions="Auto, Auto, Auto"
HorizontalOptions="CenterAndExpand"
HorizontalOptions="Center"
RowDefinitions="Auto, Auto, Auto, Auto"
VerticalOptions="CenterAndExpand">
VerticalOptions="Center">

<Label Grid.Row="0"
Grid.ColumnSpan="3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public sealed partial class XamlBindingPopupViewModel : BaseViewModel
{
public string Title { get; } = "Xaml Binding Popup";

public string Message { get; } = "This is a platform specific popup with a .NET MAUI View being rendered. The behaviors of the popup will confirm to 100% as each platform implementation look and feel, but still allows you to use your .NET MAUI Controls.";
public string Message { get; } = "This is a platform specific popup with a .NET MAUI View being rendered.\nThe behaviors of the popup will confirm to 100% as each platform implementation look and feel, but still allows you to use your .NET MAUI Controls.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@


<Label x:Name="Title"
Style="{StaticResource Title}" />
Style="{StaticResource Title}"
Text="This Title Is About To Change"/>
<BoxView Style="{StaticResource Divider}" />
<Label x:Name="Message"
Text="This sample changes the title and message in Popup's OnAppearing method"
Style="{StaticResource Content}" />
</VerticalStackLayout>
</mct:Popup>
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ public OpenedEventSimplePopup(PopupSizeConstants popupSizeConstants)
Opened += OnOpened;
}

void OnOpened(object? sender, PopupOpenedEventArgs e)
async void OnOpened(object? sender, PopupOpenedEventArgs e)
{
Opened -= OnOpened;

await Task.Delay(TimeSpan.FromSeconds(1));

Title.Text = "Opened Event Popup";
Message.Text = "The content of this popup was updated after the popup was rendered";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace CommunityToolkit.Maui.Sample.Views.Popups;

public class TransparentPopupCSharp : Popup
public sealed class TransparentPopupCSharp : Popup
{
public TransparentPopupCSharp(Size popupSize) : this()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<vm:XamlBindingPopupViewModel />
</mct:Popup.BindingContext>

<VerticalStackLayout Style="{StaticResource PopupLayout}">
<VerticalStackLayout
Style="{StaticResource PopupLayout}"
HorizontalOptions="Center">
<VerticalStackLayout.Resources>
<ResourceDictionary>
<Style x:Key="Title" TargetType="Label">
Expand Down Expand Up @@ -39,6 +41,9 @@
Text="{Binding Title}" />
<BoxView Style="{StaticResource Divider}" />
<Label Style="{StaticResource Content}"
HorizontalTextAlignment="Center"
MaxLines="5"
LineBreakMode="WordWrap"
Text="{Binding Message}" />
</VerticalStackLayout>
</mct:Popup>
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using CommunityToolkit.Maui.Core.Views;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;

namespace CommunityToolkit.Maui.Core.Handlers;

public partial class PopupHandler : ElementHandler<IPopup, MauiPopup>
public partial class PopupHandler : ElementHandler<IPopup, Popup>
{
/// <summary>
/// Action that's triggered when the Popup is Dismissed.
Expand All @@ -25,7 +28,14 @@ public static void MapOnClosed(PopupHandler handler, IPopup view, object? result
/// <param name="result">We don't need to provide the result parameter here.</param>
public static void MapOnOpened(PopupHandler handler, IPopup view, object? result)
{
handler.PlatformView.Show();
ArgumentNullException.ThrowIfNull(view.Parent);
ArgumentNullException.ThrowIfNull(handler.MauiContext);
var parent = view.Parent.ToPlatform(handler.MauiContext);
parent.IsHitTestVisible = false;
handler.PlatformView.XamlRoot = parent.XamlRoot;
handler.PlatformView.IsHitTestVisible = true;
handler.PlatformView.IsOpen = true;
view.OnOpened();
}

/// <summary>
Expand All @@ -47,7 +57,7 @@ public static void MapOnDismissedByTappingOutsideOfPopup(PopupHandler handler, I
/// <param name="view">An instance of <see cref="IPopup"/>.</param>
public static void MapAnchor(PopupHandler handler, IPopup view)
{
handler.PlatformView.ConfigureControl();
handler.PlatformView.SetAnchor(view, handler.MauiContext);
}

/// <summary>
Expand All @@ -57,7 +67,8 @@ public static void MapAnchor(PopupHandler handler, IPopup view)
/// <param name="view">An instance of <see cref="IPopup"/>.</param>
public static void MapCanBeDismissedByTappingOutsideOfPopup(PopupHandler handler, IPopup view)
{
handler.PlatformView.ConfigureControl();
handler.PlatformView.IsLightDismissEnabled = view.CanBeDismissedByTappingOutsideOfPopup;
handler.PlatformView.LightDismissOverlayMode = view.CanBeDismissedByTappingOutsideOfPopup ? LightDismissOverlayMode.On : LightDismissOverlayMode.Off;
}

/// <summary>
Expand All @@ -68,7 +79,6 @@ public static void MapCanBeDismissedByTappingOutsideOfPopup(PopupHandler handler
public static void MapColor(PopupHandler handler, IPopup view)
{
handler.PlatformView.SetColor(view);
handler.PlatformView.ConfigureControl();
}

/// <summary>
Expand All @@ -78,26 +88,40 @@ public static void MapColor(PopupHandler handler, IPopup view)
/// <param name="view">An instance of <see cref="IPopup"/>.</param>
public static void MapSize(PopupHandler handler, IPopup view)
{
handler.PlatformView.ConfigureControl();
handler.PlatformView.SetSize(view);
}

/// <inheritdoc/>
protected override void DisconnectHandler(MauiPopup platformView)
protected override void DisconnectHandler(Popup platformView)
{
platformView.CleanUp();
ArgumentNullException.ThrowIfNull(VirtualView.Parent);
ArgumentNullException.ThrowIfNull(VirtualView.Handler?.MauiContext);
var parent = VirtualView.Parent.ToPlatform(VirtualView.Handler.MauiContext);
parent.IsHitTestVisible = true;
platformView.IsOpen = false;
platformView.Closed -= OnClosed;
}

/// <inheritdoc/>
protected override MauiPopup CreatePlatformElement()
protected override Popup CreatePlatformElement()
{
ArgumentNullException.ThrowIfNull(MauiContext);
return new MauiPopup(MauiContext);
var popup = new Popup();
return popup;
}

/// <inheritdoc/>
protected override void ConnectHandler(MauiPopup platformView)
protected override void ConnectHandler(Popup platformView)
{
platformView.SetElement(VirtualView);
platformView.Closed += OnClosed;
platformView.ConfigureControl(VirtualView, MauiContext);
base.ConnectHandler(platformView);
}

void OnClosed(object? sender, object e)
{
if (!PlatformView.IsOpen && VirtualView.CanBeDismissedByTappingOutsideOfPopup)
{
VirtualView.Handler?.Invoke(nameof(IPopup.OnDismissedByTappingOutsideOfPopup));
}
}
}
Loading

0 comments on commit f765132

Please sign in to comment.