Skip to content

Commit 6915726

Browse files
Add PopupExtensions.ClosePopup() (#2671)
* Add `Close()` * Update PopupExtensions.shared.cs * Add CancellationToken * Add Unit Tests * Add Support for Shell * Add .NET 10 Compiler Error This ensures we do not forget to remove the Obsolete Popup classes in our .NET 10 release * Rename `Close()` -> `CloseAsync()` * Add `[EditorBrowsable(EditorBrowsableState.Never)]` to Obsolete classes * Update Samples * Fix XML
1 parent e54a8f9 commit 6915726

File tree

20 files changed

+158
-53
lines changed

20 files changed

+158
-53
lines changed

samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/PopupLayoutAlignmentPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
xmlns:viewModels="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Views"
77
x:TypeArguments="viewModels:PopupLayoutAlignmentViewModel"
88
x:DataType="viewModels:PopupLayoutAlignmentViewModel"
9+
Padding="20"
910
Title="Popup Layout Alignment">
1011

1112
<Grid RowDefinitions="64,44,32,44,24,44,*"
@@ -41,7 +42,6 @@
4142

4243
<Entry Grid.Row="1"
4344
Grid.Column="5"
44-
Grid.ColumnSpan="2"
4545
Text="100"
4646
x:Name="heightEntry"
4747
Keyboard="Numeric"

samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/PopupPositionPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<Label Grid.Row="0"
3333
Grid.ColumnSpan="3"
3434
Style="{StaticResource Header}"
35-
Text="Popup's can be positioned anywhere on the screen using VerticalOptions and HorizontalOptions. Tap the arrows below to see how this works."
35+
Text="Popups can be positioned anywhere on the screen using VerticalOptions and HorizontalOptions. Tap the arrows below to see how this works."
3636
HorizontalTextAlignment="Center"/>
3737

3838
<Button Grid.Row="1"

samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/PopupsPage.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<ScrollView>
1212
<VerticalStackLayout Spacing="12">
1313
<Button Text="Simple Popup" Clicked="HandleSimplePopupButtonClicked" />
14+
15+
<Button Text="Self Closing Popup" Clicked="HandleSelfClosingPopupButtonClicked"/>
1416

1517
<Button Text="Button Popup" Clicked="HandleButtonPopupButtonClicked" />
1618

@@ -45,6 +47,7 @@
4547
<Button Text="Popup Style Page" Clicked="HandleStylePopupButtonClicked" />
4648

4749
<Button Text="OnDisappearing Popup" Clicked="HandleOnDisappearingPopupClicked" />
50+
4851
</VerticalStackLayout>
4952
</ScrollView>
5053
</ContentPage.Content>

samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/PopupsPage.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using CommunityToolkit.Maui.Extensions;
2+
using CommunityToolkit.Maui.Markup;
13
using CommunityToolkit.Maui.Sample.Pages.Views.Popup;
24
using CommunityToolkit.Maui.Sample.ViewModels.Views;
35
using CommunityToolkit.Maui.Sample.Views.Popups;
@@ -116,4 +118,16 @@ async void HandleOnDisappearingPopupClicked(object sender, EventArgs e)
116118
{
117119
await Navigation.PushModalAsync(new PopupOnDisappearingPage());
118120
}
121+
122+
async void HandleSelfClosingPopupButtonClicked(object? sender, EventArgs e)
123+
{
124+
this.ShowPopup(new Label().Text("This Popup Will Close Automatically in 2 Seconds"), new PopupOptions
125+
{
126+
CanBeDismissedByTappingOutsideOfPopup = false
127+
});
128+
129+
await Task.Delay(TimeSpan.FromSeconds(2));
130+
131+
await this.ClosePopupAsync();
132+
}
119133
}

samples/CommunityToolkit.Maui.Sample/Resources/Styles/Styles.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<!-- Explicit styles -->
99
<Style x:Key="PopupLayout" TargetType="Layout" ApplyToDerivedTypes="true">
10-
<Setter Property="Padding" Value="{OnPlatform Android=20, WinUI=20, iOS=5, MacCatalyst=5, Tizen=20}" />
10+
<Setter Property="Padding" Value="{OnPlatform Android=5, WinUI=20, iOS=5, MacCatalyst=5, Tizen=20}" />
1111
</Style>
1212

1313
<!-- Implicit styles -->

samples/CommunityToolkit.Maui.Sample/Views/Popups/ButtonPopup.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
66
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
7-
BackgroundColor="Red">
7+
BackgroundColor="LightCoral">
88

99
<VerticalStackLayout Spacing="6">
1010
<VerticalStackLayout.Resources>

samples/CommunityToolkit.Maui.Sample/Views/Popups/ButtonPopup.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public ButtonPopup()
99

1010
void Button_Clicked(object? sender, EventArgs e)
1111
{
12-
Close();
12+
CloseAsync();
1313
}
1414
}

samples/CommunityToolkit.Maui.Sample/Views/Popups/MultipleButtonPopup.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
xmlns:system="clr-namespace:System;assembly=System.Runtime"
99
BackgroundColor="White">
1010

11-
<VerticalStackLayout>
11+
<VerticalStackLayout Spacing="6">
1212
<VerticalStackLayout.Resources>
1313
<ResourceDictionary>
1414
<Style x:Key="Title" TargetType="Label">
@@ -37,6 +37,7 @@
3737
<Setter Property="VerticalOptions" Value="End" />
3838
<Setter Property="HorizontalOptions" Value="Center" />
3939
<Setter Property="Spacing" Value="20" />
40+
<Setter Property="Margin" Value="8" />
4041
</Style>
4142
</ResourceDictionary>
4243
</VerticalStackLayout.Resources>

samples/CommunityToolkit.Maui.Sample/Views/Popups/MultipleButtonPopup.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ public MultipleButtonPopup()
99

1010
async void Cancel_Clicked(object? sender, EventArgs e)
1111
{
12-
await Close(false);
12+
await CloseAsync(false);
1313
}
1414

1515
async void Okay_Clicked(object? sender, EventArgs e)
1616
{
17-
await Close(true);
17+
await CloseAsync(true);
1818
}
1919
}

samples/CommunityToolkit.Maui.Sample/Views/Popups/NoOutsideTapDismissPopup.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public NoOutsideTapDismissPopup()
1111

1212
async void Button_Clicked(object? sender, EventArgs e)
1313
{
14-
await Close();
14+
await CloseAsync();
1515
await Toast.Make("Popup Dismissed By Button").Show();
1616
}
1717
}

0 commit comments

Comments
 (0)