Skip to content

Commit cb50431

Browse files
Popup V2
1 parent 49da03d commit cb50431

File tree

82 files changed

+613
-3889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+613
-3889
lines changed

samples/CommunityToolkit.Maui.Sample/App.xaml

+13-21
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,34 @@
1010
</ResourceDictionary.MergedDictionaries>
1111

1212
<Style TargetType="{x:Type popups:ImplicitStylePopup}">
13-
<Setter Property="Size" Value="100,100" />
14-
<Setter Property="Color" Value="Red" />
15-
<Setter Property="HorizontalOptions" Value="Start" />
16-
<Setter Property="VerticalOptions" Value="Start" />
17-
<Setter Property="CanBeDismissedByTappingOutsideOfPopup" Value="True" />
13+
<Setter Property="WidthRequest" Value="100" />
14+
<Setter Property="HeightRequest" Value="100" />
15+
<Setter Property="BackgroundColor" Value="Red" />
1816
</Style>
1917

2018
<Style x:Key="ExplicitPopupStyle" TargetType="{x:Type popups:ExplicitStylePopup}">
21-
<Setter Property="Size" Value="200,100" />
22-
<Setter Property="Color" Value="Yellow" />
23-
<Setter Property="HorizontalOptions" Value="End" />
24-
<Setter Property="VerticalOptions" Value="Start" />
25-
<Setter Property="CanBeDismissedByTappingOutsideOfPopup" Value="True" />
19+
<Setter Property="WidthRequest" Value="200" />
20+
<Setter Property="HeightRequest" Value="100" />
21+
<Setter Property="BackgroundColor" Value="Yellow" />
2622
</Style>
2723

2824
<Style x:Key="BasePopupStyle" TargetType="{x:Type popups:StyleInheritancePopup}">
29-
<Setter Property="Size" Value="200,200" />
25+
<Setter Property="WidthRequest" Value="200" />
26+
<Setter Property="HeightRequest" Value="200" />
3027
</Style>
3128
<Style x:Key="InheritancePopupStyle" TargetType="{x:Type popups:StyleInheritancePopup}" BasedOn="{StaticResource BasePopupStyle}">
32-
<Setter Property="Color" Value="SkyBlue" />
33-
<Setter Property="HorizontalOptions" Value="End" />
34-
<Setter Property="VerticalOptions" Value="End" />
35-
<Setter Property="CanBeDismissedByTappingOutsideOfPopup" Value="True" />
29+
<Setter Property="BackgroundColor" Value="SkyBlue" />
3630
</Style>
3731

3832
<Style x:Key="DynamicBasePopupStyle" TargetType="{x:Type popups:DynamicStyleInheritancePopup}">
39-
<Setter Property="Size" Value="150,150" />
33+
<Setter Property="WidthRequest" Value="150" />
34+
<Setter Property="HeightRequest" Value="150" />
4035
</Style>
4136
<Style x:Key="DynamicInheritancePopupStyle1" TargetType="{x:Type popups:DynamicStyleInheritancePopup}" BasedOn="{StaticResource DynamicBasePopupStyle}">
42-
<Setter Property="Color" Value="Purple" />
43-
<Setter Property="VerticalOptions" Value="End" />
37+
<Setter Property="BackgroundColor" Value="Purple" />
4438
</Style>
4539
<Style x:Key="DynamicInheritancePopupStyle2" TargetType="{x:Type popups:DynamicStyleInheritancePopup}" BaseResourceKey="DynamicInheritancePopupStyle1">
46-
<Setter Property="Color" Value="Orange" />
47-
<Setter Property="HorizontalOptions" Value="End" />
48-
<Setter Property="CanBeDismissedByTappingOutsideOfPopup" Value="True" />
40+
<Setter Property="BackgroundColor" Value="Orange" />
4941
</Style>
5042

5143
</ResourceDictionary>

samples/CommunityToolkit.Maui.Sample/MauiProgram.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public static MauiApp CreateMauiApp()
122122
.AddStandardResilienceHandler(static options => options.Retry = new MobileHttpRetryStrategyOptions());
123123

124124
builder.Services.AddSingleton<AppShell>();
125-
builder.Services.AddSingleton<PopupSizeConstants>();
126125

127126
RegisterViewsAndViewModels(builder.Services);
128127
RegisterEssentials(builder.Services);
@@ -267,11 +266,11 @@ static void RegisterViewsAndViewModels(in IServiceCollection services)
267266
services.AddTransientWithShellRoute<PopupSizingIssuesPage, PopupSizingIssuesViewModel>();
268267

269268
// Add Popups
270-
services.AddTransientPopup<CsharpBindingPopup, CsharpBindingPopupViewModel>();
271-
services.AddTransientPopup<UpdatingPopup, UpdatingPopupViewModel>();
272-
services.AddTransientPopup<XamlBindingPopup, XamlBindingPopupViewModel>();
269+
services.AddPopup<CsharpBindingPopup, CsharpBindingPopupViewModel>();
270+
services.AddPopup<UpdatingPopup, UpdatingPopupViewModel>();
271+
services.AddPopup<XamlBindingPopup, XamlBindingPopupViewModel>();
273272

274-
services.AddTransientPopupContent<PopupContentView, PopupContentViewModel>();
273+
services.AddPopup<PopupContentView, PopupContentViewModel>();
275274
}
276275

277276
static void RegisterEssentials(in IServiceCollection services)

samples/CommunityToolkit.Maui.Sample/Models/PopupSize.cs

-22
This file was deleted.

samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel;
2+
using CommunityToolkit.Maui.Core;
23
using CommunityToolkit.Maui.Core.Primitives;
34
using CommunityToolkit.Maui.Sample.ViewModels.Views;
45
using CommunityToolkit.Maui.Views;
@@ -243,7 +244,7 @@ async void ChangeAspectClicked(object? sender, EventArgs e)
243244
MediaElement.Aspect = (Aspect)aspectEnum;
244245
}
245246

246-
void DisplayPopup(object sender, EventArgs e)
247+
async void DisplayPopup(object sender, EventArgs e)
247248
{
248249
MediaElement.Pause();
249250
var popupMediaElement = new MediaElement
@@ -256,8 +257,6 @@ void DisplayPopup(object sender, EventArgs e)
256257
};
257258
var popup = new Popup
258259
{
259-
VerticalOptions = LayoutAlignment.Center,
260-
HorizontalOptions = LayoutAlignment.Center,
261260
Content = new StackLayout
262261
{
263262
Children =
@@ -267,11 +266,8 @@ void DisplayPopup(object sender, EventArgs e)
267266
}
268267
};
269268

270-
this.ShowPopup(popup);
271-
popup.Closed += (s, e) =>
272-
{
273-
popupMediaElement.Stop();
274-
popupMediaElement.Handler?.DisconnectHandler();
275-
};
269+
await Navigation.ShowPopup(popup, new PopupOptions());
270+
popupMediaElement.Stop();
271+
popupMediaElement.Handler?.DisconnectHandler();
276272
}
277273
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using CommunityToolkit.Maui.Core;
12
using CommunityToolkit.Maui.Sample.Models;
23
using CommunityToolkit.Maui.Sample.ViewModels.Views;
34
using CommunityToolkit.Maui.Sample.Views.Popups;
@@ -7,70 +8,59 @@ namespace CommunityToolkit.Maui.Sample.Pages.Views;
78

89
public partial class MultiplePopupPage : BasePage<MultiplePopupViewModel>
910
{
10-
readonly PopupSizeConstants popupSizeConstants;
11+
readonly IPopupService popupService;
1112

12-
public MultiplePopupPage(PopupSizeConstants popupSizeConstants,
13-
MultiplePopupViewModel multiplePopupViewModel)
13+
public MultiplePopupPage(MultiplePopupViewModel multiplePopupViewModel, IPopupService popupService)
1414
: base(multiplePopupViewModel)
1515
{
16+
this.popupService = popupService;
1617
InitializeComponent();
17-
18-
this.popupSizeConstants = popupSizeConstants;
1918
}
2019

2120
async void HandleSimplePopupButtonClicked(object sender, EventArgs e)
2221
{
23-
var simplePopup = new SimplePopup(popupSizeConstants);
24-
await this.ShowPopupAsync(simplePopup, CancellationToken.None);
22+
await popupService.ShowPopupAsync<SimplePopup>(new PopupOptions(), CancellationToken.None);
2523
}
2624

2725
async void HandleButtonPopupButtonClicked(object sender, EventArgs e)
2826
{
29-
var buttonPopup = new ButtonPopup(popupSizeConstants);
30-
await this.ShowPopupAsync(buttonPopup, CancellationToken.None);
27+
await popupService.ShowPopupAsync< ButtonPopup>(new PopupOptions(), CancellationToken.None);
3128
}
3229

3330
async void HandleMultipleButtonPopupButtonClicked(object sender, EventArgs e)
3431
{
35-
var multipleButtonPopup = new MultipleButtonPopup(popupSizeConstants);
36-
await this.ShowPopupAsync(multipleButtonPopup, CancellationToken.None);
32+
await popupService.ShowPopupAsync<MultipleButtonPopup>(new PopupOptions(), CancellationToken.None);
3733
}
3834

3935
async void HandleNoOutsideTapDismissPopupClicked(object sender, EventArgs e)
4036
{
41-
var noOutsideTapDismissPopup = new NoOutsideTapDismissPopup(popupSizeConstants);
42-
await this.ShowPopupAsync(noOutsideTapDismissPopup, CancellationToken.None);
37+
await popupService.ShowPopupAsync<NoOutsideTapDismissPopup>(new PopupOptions(){CanBeDismissedByTappingOutsideOfPopup = false}, CancellationToken.None);
4338
}
4439

4540
async void HandleToggleSizePopupButtonClicked(object sender, EventArgs e)
4641
{
47-
var toggleSizePopup = new ToggleSizePopup(popupSizeConstants);
48-
await this.ShowPopupAsync(toggleSizePopup, CancellationToken.None);
42+
await popupService.ShowPopupAsync<ToggleSizePopup>(new PopupOptions(), CancellationToken.None);
4943
}
5044

5145
async void HandleTransparentPopupButtonClicked(object sender, EventArgs e)
5246
{
53-
var transparentPopup = new TransparentPopup();
54-
await this.ShowPopupAsync(transparentPopup, CancellationToken.None);
47+
await popupService.ShowPopupAsync<TransparentPopup>(new PopupOptions(), CancellationToken.None);
5548
}
5649

5750
async void HandleOpenedEventSimplePopupButtonClicked(object sender, EventArgs e)
5851
{
59-
var openedEventSimplePopup = new OpenedEventSimplePopup(popupSizeConstants);
60-
await this.ShowPopupAsync(openedEventSimplePopup, CancellationToken.None);
52+
await popupService.ShowPopupAsync<OpenedEventSimplePopup>(new PopupOptions(), CancellationToken.None);
6153
}
6254

6355
async void HandleReturnResultPopupButtonClicked(object sender, EventArgs e)
6456
{
65-
var returnResultPopup = new ReturnResultPopup(popupSizeConstants);
66-
var result = await this.ShowPopupAsync(returnResultPopup, CancellationToken.None);
57+
var result = await popupService.ShowPopupAsync< ReturnResultPopup, bool>(new PopupOptions(), CancellationToken.None);
6758

68-
await DisplayAlert("Pop Result Returned", $"Result: {result}", "OK");
59+
await DisplayAlert("Pop Result Returned", $"Result: {result.Result}", "OK");
6960
}
7061

7162
async void HandleXamlBindingPopupPopupButtonClicked(object sender, EventArgs e)
7263
{
73-
var xamlBindingPopup = new XamlBindingPopup(popupSizeConstants);
74-
await this.ShowPopupAsync(xamlBindingPopup, CancellationToken.None);
64+
await popupService.ShowPopupAsync<XamlBindingPopup>(new PopupOptions(), CancellationToken.None);
7565
}
7666
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CommunityToolkit.Maui.Sample.ViewModels.Views;
1+
using CommunityToolkit.Maui.Core;
2+
using CommunityToolkit.Maui.Sample.ViewModels.Views;
23
using CommunityToolkit.Maui.Sample.Views.Popups;
34
using CommunityToolkit.Maui.Views;
45

@@ -11,55 +12,14 @@ public PopupLayoutAlignmentPage(PopupLayoutAlignmentViewModel popupLayoutViewMod
1112
InitializeComponent();
1213
}
1314

14-
void ShowPopupButtonClicked(object sender, EventArgs e)
15+
async void ShowPopupButtonClicked(object sender, EventArgs e)
1516
{
1617
var redBlueBoxPopup = new RedBlueBoxPopup
1718
{
18-
Size = new Size(double.Parse(widthEntry.Text), double.Parse(heightEntry.Text)),
19+
WidthRequest = double.Parse(widthEntry.Text),
20+
HeightRequest = double.Parse(heightEntry.Text)
1921
};
2022

21-
if (VerticalOptionsStartRadioButton.IsChecked)
22-
{
23-
redBlueBoxPopup.VerticalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Start;
24-
}
25-
else if (VerticalOptionsCenterRadioButton.IsChecked)
26-
{
27-
redBlueBoxPopup.VerticalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Center;
28-
}
29-
else if (VerticalOptionsEndRadioButton.IsChecked)
30-
{
31-
redBlueBoxPopup.VerticalOptions = Microsoft.Maui.Primitives.LayoutAlignment.End;
32-
}
33-
else if (VerticalOptionsFillRadioButton.IsChecked)
34-
{
35-
redBlueBoxPopup.VerticalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Fill;
36-
}
37-
else
38-
{
39-
throw new InvalidOperationException("VerticalOptions Radio Button Must Be Selected");
40-
}
41-
42-
if (HorizontalOptionsStartRadioButton.IsChecked)
43-
{
44-
redBlueBoxPopup.HorizontalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Start;
45-
}
46-
else if (HorizontalOptionsCenterRadioButton.IsChecked)
47-
{
48-
redBlueBoxPopup.HorizontalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Center;
49-
}
50-
else if (HorizontalOptionsEndRadioButton.IsChecked)
51-
{
52-
redBlueBoxPopup.HorizontalOptions = Microsoft.Maui.Primitives.LayoutAlignment.End;
53-
}
54-
else if (HorizontalOptionsFillRadioButton.IsChecked)
55-
{
56-
redBlueBoxPopup.HorizontalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Fill;
57-
}
58-
else
59-
{
60-
throw new InvalidOperationException("HorizontalOptions Radio Button Must Be Selected");
61-
}
62-
63-
this.ShowPopup(redBlueBoxPopup);
23+
await Navigation.ShowPopup(redBlueBoxPopup, new PopupOptions());
6424
}
6525
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using CommunityToolkit.Maui.Core;
12
using CommunityToolkit.Maui.Sample.Models;
23
using CommunityToolkit.Maui.Sample.ViewModels.Views;
34
using CommunityToolkit.Maui.Sample.Views.Popups;
@@ -7,22 +8,21 @@ namespace CommunityToolkit.Maui.Sample.Pages.Views;
78

89
public partial class ShowPopupInOnAppearingPage : BasePage<ShowPopupInOnAppearingPageViewModel>
910
{
10-
readonly PopupSizeConstants popupSizeConstants;
11+
readonly IPopupService popupService;
1112

1213
public ShowPopupInOnAppearingPage(
13-
PopupSizeConstants popupSizeConstants,
14-
ShowPopupInOnAppearingPageViewModel showPopupInOnAppearingPageViewModel)
14+
ShowPopupInOnAppearingPageViewModel showPopupInOnAppearingPageViewModel,
15+
IPopupService popupService)
1516
: base(showPopupInOnAppearingPageViewModel)
1617
{
18+
this.popupService = popupService;
1719
InitializeComponent();
18-
this.popupSizeConstants = popupSizeConstants;
1920
}
2021

2122
protected override async void OnAppearing()
2223
{
2324
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
24-
2525
// Proves that we now support showing a popup before the platform is even ready.
26-
await this.ShowPopupAsync(new ReturnResultPopup(popupSizeConstants), cts.Token);
26+
await popupService.ShowPopupAsync<ReturnResultPopup>(new PopupOptions(), cts.Token);
2727
}
2828
}

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

-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
<Setter Property="BackgroundColor" Value="{OnPlatform WinUI=Transparent, Default={AppThemeBinding Light={StaticResource AppBackgroundLightColor}, Dark={StaticResource AppBackgroundDarkColor}}}" />
1616
</Style>
1717

18-
<Style TargetType="toolkit:Popup" ApplyToDerivedTypes="true">
19-
<Setter Property="VerticalOptions" Value="Center" />
20-
<Setter Property="HorizontalOptions" Value="Center" />
21-
<Setter Property="Color" Value="{AppThemeBinding Light={StaticResource AppBackgroundLightColor}, Dark={StaticResource AppBackgroundDarkColor}}" />
22-
</Style>
23-
2418
<Style TargetType="NavigationPage">
2519
<Setter Property="BarBackgroundColor" Value="{AppThemeBinding Light={StaticResource PrimaryColor}, Dark={StaticResource Gray950}}" />
2620
<Setter Property="BarTextColor" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource White}}" />

samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/CsharpBindingPopupViewModel.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CommunityToolkit.Mvvm.ComponentModel;
1+
using CommunityToolkit.Maui.Core;
2+
using CommunityToolkit.Mvvm.ComponentModel;
23

34
namespace CommunityToolkit.Maui.Sample.ViewModels.Views;
45

@@ -14,4 +15,6 @@ internal void Load(string updatedMessage)
1415
{
1516
Message = updatedMessage;
1617
}
18+
19+
public TaskCompletionSource<PopupResult>? PopupResultManager { get; set; }
1720
}

samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/CustomSizeAndPositionPopupViewModel.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Runtime.CompilerServices;
2+
using CommunityToolkit.Maui.Core;
23
using CommunityToolkit.Maui.Sample.Views.Popups;
34
using CommunityToolkit.Maui.Views;
45
using CommunityToolkit.Mvvm.ComponentModel;
@@ -93,12 +94,11 @@ public Task ExecuteShowButton(CancellationToken token)
9394

9495
var popup = new FlowDirectionPopup((FlowDirection)FlowDirectionSelectedIndex)
9596
{
96-
Size = new Size(Width, Height),
97-
VerticalOptions = verticalOptions.Value,
98-
HorizontalOptions = horizontalOptions.Value
97+
WidthRequest = Width,
98+
HeightRequest = Height
9999
};
100100

101-
return Shell.Current.ShowPopupAsync(popup, token);
101+
return Shell.Current.Navigation.ShowPopup(popup, new PopupOptions());
102102
}
103103

104104
static bool IsFlowDirectionSelectionValid(int flowDirectionSelection, int flowDirectionOptionsCount)

0 commit comments

Comments
 (0)