Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit e51ca9d

Browse files
SkyeHoeflingTheCodeTravelerpictos
authored
Adds Popup Control (#653)
* Ported Popup Control from xamarin/Xamarin.Forms#9616 to Xamarin Community Toolkit * Added missing async/await api * Added popup result sample and fixed uwp/android implementations * Renamed View->Content * Updated styles of sample popups * Updated BorderColor to be a platform specific property for UWP * Moved Android/iOS/UWP renderers to platform specific folders * Changed PopupDismissedEventArgs so it is immutable * Removed visual studio edits to sample android project * Removed = false for isDisposed as it is default * Normalized accessor properties for ios and uwp * Removed performance apis since they are used internally at Xamarin.Forms * Simplified OnElementChanged to use shared method ConfigureControl * Removed iOS 9 code * Updated NavigationExtensions to follow Xamarin Essentials style by adding netstandard impl that throws exception * Added Control.Cleanup invocation to dispose method * [iOS] Removed async/await from OnDismissed since it is an event the invocation doesn't need to know when it is complete * Fixed comment * Updated iOS to use WeakEventManager * changed instantiation to use default(SizeRequest) * ios - Changed WeakEventManager so it is a protected static object on the popup renderer. This will help create a weak reference to the popup delegate for the GC * Moved sample popup code to new location * Added WeakEventManager for BasePopup events (Opened, Dismissed) * ios - changed popover delegate to use action * Added PopOverDelegate.PopoverDismissed * Updated accessor for LightDismiss to protected internal * Updated comment in LightDismiss * Removed stale iOS code * Updated xml comments * Removed obj dir from compilation in 'netstandard' projects and fixed debugger issues * removed Init method and added code to get the Context * changed accessor of ToolkitPlatform to internal * Added new UI popup tests for Xaml binding vs C# binding * Updated XCT xmlns to use uri instead of fully qualified namespace * Added shared popup size across samples * Fixed popup BindingContext not working when set in XAML * Update Samples - Capitalize x:Name variables - Replace expression-bodied properties with read-only properties where applicable * Add PopupDismissedEventArgs<T> * Add Default Values for Color and Size * Remove Unncessary `base` Keyword, per styling guide * Optimize originX + originX, Add missing `await` * Update PopupAnchorViewModel.cs * Fix orignY Copy/paste error * Update PopupRenderer.ios.cs * Update NavigationExtensions.netstandard.macos.tvos.watchos.tizen.wpf.gtk.cs * Added NavigableElementExtension - This allows rendering popup from ContentPage and other children of NavigableElement Co-authored-by: Brandon Minnick <[email protected]> Co-authored-by: Pedro Jesus <[email protected]>
1 parent f9820f7 commit e51ca9d

File tree

55 files changed

+2670
-6
lines changed

Some content is hidden

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

55 files changed

+2670
-6
lines changed

samples/XCT.Sample.Android/MainActivity.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Android.Content.PM;
33
using Android.OS;
44
using Android.Runtime;
5-
using Xamarin.Essentials;
65

76
namespace Xamarin.CommunityToolkit.Sample.Droid
87
{
@@ -17,14 +16,14 @@ protected override void OnCreate(Bundle savedInstanceState)
1716
base.OnCreate(savedInstanceState);
1817

1918
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
20-
Platform.Init(this, savedInstanceState);
19+
Essentials.Platform.Init(this, savedInstanceState);
2120
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
2221
LoadApplication(new App());
2322
}
2423

2524
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
2625
{
27-
Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
26+
Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
2827

2928
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
3029
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<pages:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
5+
xmlns:viewModels="clr-namespace:Xamarin.CommunityToolkit.Sample.ViewModels.Views"
6+
xmlns:custom="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
7+
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.PopupGalleryPage"
8+
Title="Popup Control"
9+
x:Name="root">
10+
11+
<ContentPage.BindingContext>
12+
<viewModels:PopupGalleryViewModel />
13+
</ContentPage.BindingContext>
14+
15+
<ContentPage.Resources>
16+
<ResourceDictionary>
17+
<Style x:Key="Header" TargetType="Label">
18+
<Setter Property="VerticalOptions" Value="CenterAndExpand" />
19+
<Setter Property="HorizontalOptions" Value="CenterAndExpand" />
20+
<Setter Property="Margin" Value="15, 10" />
21+
</Style>
22+
<Style TargetType="ScrollView">
23+
<Setter Property="VerticalOptions" Value="FillAndExpand" />
24+
</Style>
25+
<Style x:Key="ItemsLayout" TargetType="StackLayout">
26+
<Setter Property="Spacing" Value="16" />
27+
</Style>
28+
</ResourceDictionary>
29+
</ContentPage.Resources>
30+
31+
<ContentPage.Content>
32+
<StackLayout>
33+
<ScrollView>
34+
<StackLayout>
35+
<Label Style="{StaticResource Header}"
36+
Text="The popup control renders native popups from the shared code. This page demonstrates a variety of different techniques for displaying native popups." />
37+
<StackLayout Style="{StaticResource ItemsLayout}"
38+
BindableLayout.ItemsSource="{Binding Examples}">
39+
<BindableLayout.ItemTemplate>
40+
<DataTemplate>
41+
<custom:PancakeView Style="{StaticResource card}"
42+
Margin="{StaticResource ContentPadding}">
43+
<custom:PancakeView.GestureRecognizers>
44+
<TapGestureRecognizer Command="{Binding BindingContext.DisplayPopup, Source={x:Reference root}}"
45+
CommandParameter="{Binding Type}" />
46+
</custom:PancakeView.GestureRecognizers>
47+
<Grid ColumnSpacing="20">
48+
<Grid.ColumnDefinitions>
49+
<ColumnDefinition Width="12" />
50+
<ColumnDefinition Width="*" />
51+
</Grid.ColumnDefinitions>
52+
<BoxView BackgroundColor="{Binding Color}" />
53+
<StackLayout Grid.Column="1" Spacing="8" Padding="0,24,24,24">
54+
<Label Style="{StaticResource label_section_header}" Text="{Binding Title}" />
55+
<Label Text="{Binding Description}" />
56+
</StackLayout>
57+
</Grid>
58+
</custom:PancakeView>
59+
</DataTemplate>
60+
</BindableLayout.ItemTemplate>
61+
</StackLayout>
62+
</StackLayout>
63+
</ScrollView>
64+
</StackLayout>
65+
</ContentPage.Content>
66+
</pages:BasePage>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Xamarin.CommunityToolkit.Sample.Pages.Views
2+
{
3+
public partial class PopupGalleryPage
4+
{
5+
public PopupGalleryPage() => InitializeComponent();
6+
}
7+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
5+
xmlns:local="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages.Views.Popups"
6+
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.Popups.ButtonPopup">
7+
8+
<xct:Popup.Size>
9+
<OnPlatform x:TypeArguments="Size">
10+
<OnPlatform.Platforms>
11+
<On Platform="Android" Value="{x:Static local:PopupSize.Android}" />
12+
<On Platform="UWP" Value="{x:Static local:PopupSize.UWP}" />
13+
<On Platform="iOS" Value="{x:Static local:PopupSize.iOS}" />
14+
</OnPlatform.Platforms>
15+
</OnPlatform>
16+
</xct:Popup.Size>
17+
18+
<xct:Popup.Resources>
19+
<ResourceDictionary>
20+
<Style x:Key="Title" TargetType="Label">
21+
<Setter Property="FontSize" Value="26" />
22+
<Setter Property="FontAttributes" Value="Bold" />
23+
<Setter Property="TextColor" Value="#000" />
24+
<Setter Property="VerticalTextAlignment" Value="Center" />
25+
<Setter Property="HorizontalTextAlignment" Value="Center" />
26+
</Style>
27+
<Style x:Key="Divider" TargetType="BoxView">
28+
<Setter Property="HeightRequest" Value="1" />
29+
<Setter Property="Margin" Value="50, 25" />
30+
<Setter Property="Color" Value="#c3c3c3" />
31+
</Style>
32+
<Style x:Key="Content" TargetType="Label">
33+
<Setter Property="HorizontalTextAlignment" Value="Start" />
34+
<Setter Property="VerticalTextAlignment" Value="Center" />
35+
</Style>
36+
<Style x:Key="PopupLayout" TargetType="StackLayout">
37+
<Setter Property="Padding" Value="{OnPlatform Android=20, UWP=20, iOS=5}" />
38+
</Style>
39+
<Style x:Key="ConfirmButton" TargetType="Button">
40+
<Setter Property="VerticalOptions" Value="EndAndExpand" />
41+
</Style>
42+
</ResourceDictionary>
43+
</xct:Popup.Resources>
44+
45+
<StackLayout Style="{StaticResource PopupLayout}">
46+
<Label Style="{StaticResource Title}"
47+
Text="Button Popup" />
48+
<BoxView Style="{StaticResource Divider}" />
49+
<Label Style="{StaticResource Content}"
50+
Text="This is a native popup with a Xamarin.Forms View being rendered. The behaviors of the popup will confirm to 100% native look and feel, but still allows you to use your Xamarin.Forms controls." />
51+
<Button Text="OKAY"
52+
Style="{StaticResource ConfirmButton}"
53+
Clicked="Button_Clicked" />
54+
</StackLayout>
55+
56+
</xct:Popup>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Xamarin.CommunityToolkit.Sample.Pages.Views.Popups
2+
{
3+
public partial class ButtonPopup
4+
{
5+
public ButtonPopup() => InitializeComponent();
6+
7+
void Button_Clicked(object sender, System.EventArgs e) => Dismiss(null);
8+
}
9+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
5+
xmlns:local="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages.Views.Popups"
6+
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.Popups.CsharpBindingPopup">
7+
8+
<xct:Popup.Size>
9+
<OnPlatform x:TypeArguments="Size">
10+
<OnPlatform.Platforms>
11+
<On Platform="Android" Value="{x:Static local:PopupSize.Android}" />
12+
<On Platform="UWP" Value="{x:Static local:PopupSize.UWP}" />
13+
<On Platform="iOS" Value="{x:Static local:PopupSize.iOS}" />
14+
</OnPlatform.Platforms>
15+
</OnPlatform>
16+
</xct:Popup.Size>
17+
18+
<xct:Popup.Resources>
19+
<ResourceDictionary>
20+
<Style x:Key="Title" TargetType="Label">
21+
<Setter Property="FontSize" Value="26" />
22+
<Setter Property="FontAttributes" Value="Bold" />
23+
<Setter Property="TextColor" Value="#000" />
24+
<Setter Property="VerticalTextAlignment" Value="Center" />
25+
<Setter Property="HorizontalTextAlignment" Value="Center" />
26+
</Style>
27+
<Style x:Key="Divider" TargetType="BoxView">
28+
<Setter Property="HeightRequest" Value="1" />
29+
<Setter Property="Margin" Value="50, 25" />
30+
<Setter Property="Color" Value="#c3c3c3" />
31+
</Style>
32+
<Style x:Key="Content" TargetType="Label">
33+
<Setter Property="HorizontalTextAlignment" Value="Start" />
34+
<Setter Property="VerticalTextAlignment" Value="Center" />
35+
</Style>
36+
<Style x:Key="PopupLayout" TargetType="StackLayout">
37+
<Setter Property="Padding" Value="{OnPlatform Android=20, UWP=20, iOS=5}" />
38+
</Style>
39+
</ResourceDictionary>
40+
</xct:Popup.Resources>
41+
42+
<StackLayout Style="{StaticResource PopupLayout}">
43+
<Label Style="{StaticResource Title}"
44+
Text="{Binding Title}" />
45+
<BoxView Style="{StaticResource Divider}" />
46+
<Label Style="{StaticResource Content}"
47+
Text="{Binding Message}" />
48+
</StackLayout>
49+
50+
</xct:Popup>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Xamarin.CommunityToolkit.Sample.ViewModels.Views.Popups;
2+
3+
namespace Xamarin.CommunityToolkit.Sample.Pages.Views.Popups
4+
{
5+
public partial class CsharpBindingPopup
6+
{
7+
public CsharpBindingPopup()
8+
{
9+
InitializeComponent();
10+
BindingContext = new CsharpBindingPopupViewModel();
11+
}
12+
}
13+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
5+
xmlns:local="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages.Views.Popups"
6+
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.Popups.MultipleButtonPopup">
7+
8+
<xct:Popup.Size>
9+
<OnPlatform x:TypeArguments="Size">
10+
<OnPlatform.Platforms>
11+
<On Platform="Android" Value="{x:Static local:PopupSize.Android}" />
12+
<On Platform="UWP" Value="{x:Static local:PopupSize.UWP}" />
13+
<On Platform="iOS" Value="{x:Static local:PopupSize.iOS}" />
14+
</OnPlatform.Platforms>
15+
</OnPlatform>
16+
</xct:Popup.Size>
17+
18+
<xct:Popup.Resources>
19+
<ResourceDictionary>
20+
<Style x:Key="Title" TargetType="Label">
21+
<Setter Property="FontSize" Value="26" />
22+
<Setter Property="FontAttributes" Value="Bold" />
23+
<Setter Property="TextColor" Value="#000" />
24+
<Setter Property="VerticalTextAlignment" Value="Center" />
25+
<Setter Property="HorizontalTextAlignment" Value="Center" />
26+
</Style>
27+
<Style x:Key="Divider" TargetType="BoxView">
28+
<Setter Property="HeightRequest" Value="1" />
29+
<Setter Property="Margin" Value="50, 25" />
30+
<Setter Property="Color" Value="#c3c3c3" />
31+
</Style>
32+
<Style x:Key="Content" TargetType="Label">
33+
<Setter Property="HorizontalTextAlignment" Value="Start" />
34+
<Setter Property="VerticalTextAlignment" Value="Center" />
35+
</Style>
36+
<Style x:Key="PopupLayout" TargetType="StackLayout">
37+
<Setter Property="Padding" Value="{OnPlatform Android=20, UWP=20, iOS=5}" />
38+
</Style>
39+
<Style x:Key="CancelButton" TargetType="Button">
40+
<Setter Property="Background" Value="#FFF" />
41+
<Setter Property="BorderWidth" Value="1" />
42+
<Setter Property="BorderColor" Value="Blue" />
43+
<Setter Property="TextColor" Value="Blue" />
44+
</Style>
45+
<Style x:Key="ButtonGroup" TargetType="StackLayout">
46+
<Setter Property="VerticalOptions" Value="EndAndExpand" />
47+
<Setter Property="HorizontalOptions" Value="CenterAndExpand" />
48+
<Setter Property="Spacing" Value="20" />
49+
<Setter Property="Orientation" Value="Horizontal" />
50+
</Style>
51+
</ResourceDictionary>
52+
</xct:Popup.Resources>
53+
54+
<StackLayout Style="{StaticResource PopupLayout}">
55+
<Label Style="{StaticResource Title}"
56+
Text="Button Popup" />
57+
<BoxView Style="{StaticResource Divider}" />
58+
<Label Style="{StaticResource Content}"
59+
Text="This is a native popup with a Xamarin.Forms View being rendered. The behaviors of the popup will confirm to 100% native look and feel, but still allows you to use your Xamarin.Forms controls." />
60+
<StackLayout Style="{StaticResource ButtonGroup}">
61+
<Button Text="Cancel"
62+
Style="{StaticResource CancelButton}"
63+
Clicked="Cancel_Clicked" />
64+
<Button Text="OKAY"
65+
Clicked="Okay_Clicked" />
66+
</StackLayout>
67+
68+
</StackLayout>
69+
70+
</xct:Popup>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Xamarin.CommunityToolkit.Sample.Pages.Views.Popups
2+
{
3+
public partial class MultipleButtonPopup
4+
{
5+
public MultipleButtonPopup() => InitializeComponent();
6+
7+
void Cancel_Clicked(object sender, System.EventArgs e) => Dismiss(false);
8+
9+
void Okay_Clicked(object sender, System.EventArgs e) => Dismiss(true);
10+
}
11+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
5+
xmlns:local="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages.Views.Popups"
6+
IsLightDismissEnabled="False"
7+
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.Popups.NoLightDismissPopup">
8+
9+
<xct:Popup.Size>
10+
<OnPlatform x:TypeArguments="Size">
11+
<OnPlatform.Platforms>
12+
<On Platform="Android" Value="{x:Static local:PopupSize.Android}" />
13+
<On Platform="UWP" Value="{x:Static local:PopupSize.UWP}" />
14+
<On Platform="iOS" Value="{x:Static local:PopupSize.iOS}" />
15+
</OnPlatform.Platforms>
16+
</OnPlatform>
17+
</xct:Popup.Size>
18+
19+
<xct:Popup.Resources>
20+
<ResourceDictionary>
21+
<Style x:Key="Title" TargetType="Label">
22+
<Setter Property="FontSize" Value="26" />
23+
<Setter Property="FontAttributes" Value="Bold" />
24+
<Setter Property="TextColor" Value="#000" />
25+
<Setter Property="VerticalTextAlignment" Value="Center" />
26+
<Setter Property="HorizontalTextAlignment" Value="Center" />
27+
</Style>
28+
<Style x:Key="Divider" TargetType="BoxView">
29+
<Setter Property="HeightRequest" Value="1" />
30+
<Setter Property="Margin" Value="50, 25" />
31+
<Setter Property="Color" Value="#c3c3c3" />
32+
</Style>
33+
<Style x:Key="Content" TargetType="Label">
34+
<Setter Property="HorizontalTextAlignment" Value="Start" />
35+
<Setter Property="VerticalTextAlignment" Value="Center" />
36+
</Style>
37+
<Style x:Key="PopupLayout" TargetType="StackLayout">
38+
<Setter Property="Padding" Value="{OnPlatform Android=20, UWP=20, iOS=5}" />
39+
</Style>
40+
</ResourceDictionary>
41+
</xct:Popup.Resources>
42+
43+
<StackLayout Style="{StaticResource PopupLayout}">
44+
<Label
45+
Style="{StaticResource Title}"
46+
Text="Simple Popup" />
47+
<BoxView Style="{StaticResource Divider}" />
48+
<Label
49+
Style="{StaticResource Content}"
50+
Text="{OnPlatform
51+
Android='This is a native popup with a Xamarin.Forms View being rendered. The behaviors of the popup will confirm to 100% native look and feel, but still allows you to use your Xamarin.Forms controls.',
52+
iOS='This is a native popup with a Xamarin.Forms View being rendered. The behaviors of the popup will confirm to 100% native look and feel, but still allows you to use your Xamarin.Forms controls.',
53+
UWP='UWP Flyouts do not support toggling light dismiss mode. On UWP this will always dismiss the flyout if you tap outside of the control'}" />
54+
<Button
55+
Text="Close"
56+
VerticalOptions="EndAndExpand"
57+
Clicked="Button_Clicked" />
58+
</StackLayout>
59+
60+
</xct:Popup>

0 commit comments

Comments
 (0)