Skip to content

Commit 13c2236

Browse files
committed
Ported Popup Control from xamarin/Xamarin.Forms#9616 to Xamarin Community Toolkit
1 parent e4e978a commit 13c2236

Some content is hidden

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

45 files changed

+2358
-7
lines changed

samples/XCT.Sample.Android/MainActivity.cs

Lines changed: 3 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,15 @@ 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);
20+
ToolkitPlatform.Init(this);
2121
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
2222
LoadApplication(new App());
2323
}
2424

2525
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
2626
{
27-
Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
27+
Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
2828

2929
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
3030
}

samples/XCT.Sample.Android/Xamarin.CommunityToolkit.Sample.Android.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
128128
<ProjectExtensions>
129129
<VisualStudio>
130-
<UserProperties XamarinHotReloadXFormsNugetUpgradeInfoBarXamarinCommunityToolkitSampleAndroidHideInfoBar="True" />
130+
<UserProperties XamarinHotReloadXFormsNugetUpgradeInfoBarXamarinCommunityToolkitSampleAndroidHideInfoBar="True" TriggeredFromHotReload="False" />
131131
</VisualStudio>
132132
</ProjectExtensions>
133133
</Project>

samples/XCT.Sample/ViewModels/Views/ViewsGalleryViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ public class ViewsGalleryViewModel : BaseGalleryViewModel
4848
"A control to display a set of tabs and their respective content."),
4949

5050
new SectionModel(typeof(UniformGridPage), "UniformGrid",
51-
"The UniformGrid is just like the Grid, with all rows and columns will have the same size.")
51+
"The UniformGrid is just like the Grid, with all rows and columns will have the same size."),
52+
53+
new SectionModel(typeof(PopupGalleryPage), "Popup",
54+
"The popup control renders native popups from the shared code. This page demonstrates a variety of different techniques for displaying native popups.")
5255
};
5356
}
5457
}

samples/XCT.Sample/Xamarin.CommunityToolkit.Sample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<EmbeddedResource Include="Images\**" />
1313
<EmbeddedResource Include="Fonts\**" />
1414
</ItemGroup>
15+
1516
<ItemGroup>
1617
<PackageReference Include="Xamarin.Forms" Version="5.0.0.1874" />
1718
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
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:PopupControlViewModel />
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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
5+
Size="{OnPlatform Android='800, 700', UWP='300, 250', iOS='250, 400'}"
6+
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.Popups.ButtonPopup">
7+
8+
<xct:Popup.Resources>
9+
<ResourceDictionary>
10+
<Style x:Key="Title" TargetType="Label">
11+
<Setter Property="FontSize" Value="26" />
12+
<Setter Property="FontAttributes" Value="Bold" />
13+
<Setter Property="TextColor" Value="#000" />
14+
<Setter Property="VerticalTextAlignment" Value="Center" />
15+
<Setter Property="HorizontalTextAlignment" Value="Center" />
16+
</Style>
17+
<Style x:Key="Divider" TargetType="BoxView">
18+
<Setter Property="HeightRequest" Value="1" />
19+
<Setter Property="Margin" Value="50, 25" />
20+
<Setter Property="Color" Value="#c3c3c3" />
21+
</Style>
22+
<Style x:Key="Content" TargetType="Label">
23+
<Setter Property="HorizontalTextAlignment" Value="Start" />
24+
<Setter Property="VerticalTextAlignment" Value="Center" />
25+
</Style>
26+
<Style x:Key="PopupLayout" TargetType="StackLayout">
27+
<Setter Property="Padding" Value="{OnPlatform Android=20, UWP=20, iOS=5}" />
28+
</Style>
29+
<Style x:Key="ConfirmButton" TargetType="Button">
30+
<Setter Property="VerticalOptions" Value="EndAndExpand" />
31+
</Style>
32+
</ResourceDictionary>
33+
</xct:Popup.Resources>
34+
35+
<xct:Popup.View>
36+
<StackLayout Style="{StaticResource PopupLayout}">
37+
<Label Style="{StaticResource Title}"
38+
Text="Button Popup" />
39+
<BoxView Style="{StaticResource Divider}" />
40+
<Label Style="{StaticResource Content}"
41+
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." />
42+
<Button Text="OKAY"
43+
Style="{StaticResource ConfirmButton}"
44+
Clicked="Button_Clicked" />
45+
</StackLayout>
46+
</xct:Popup.View>
47+
48+
</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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
5+
Size="{OnPlatform Android='800, 700', UWP='300, 250', iOS='250, 400'}"
6+
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.Popups.MultipleButtonPopup">
7+
8+
<xct:Popup.Resources>
9+
<ResourceDictionary>
10+
<Style x:Key="Title" TargetType="Label">
11+
<Setter Property="FontSize" Value="26" />
12+
<Setter Property="FontAttributes" Value="Bold" />
13+
<Setter Property="TextColor" Value="#000" />
14+
<Setter Property="VerticalTextAlignment" Value="Center" />
15+
<Setter Property="HorizontalTextAlignment" Value="Center" />
16+
</Style>
17+
<Style x:Key="Divider" TargetType="BoxView">
18+
<Setter Property="HeightRequest" Value="1" />
19+
<Setter Property="Margin" Value="50, 25" />
20+
<Setter Property="Color" Value="#c3c3c3" />
21+
</Style>
22+
<Style x:Key="Content" TargetType="Label">
23+
<Setter Property="HorizontalTextAlignment" Value="Start" />
24+
<Setter Property="VerticalTextAlignment" Value="Center" />
25+
</Style>
26+
<Style x:Key="PopupLayout" TargetType="StackLayout">
27+
<Setter Property="Padding" Value="{OnPlatform Android=20, UWP=20, iOS=5}" />
28+
</Style>
29+
<Style x:Key="CancelButton" TargetType="Button">
30+
<Setter Property="Background" Value="#FFF" />
31+
<Setter Property="BorderWidth" Value="1" />
32+
<Setter Property="BorderColor" Value="Blue" />
33+
<Setter Property="TextColor" Value="Blue" />
34+
</Style>
35+
<Style x:Key="ButtonGroup" TargetType="StackLayout">
36+
<Setter Property="VerticalOptions" Value="EndAndExpand" />
37+
<Setter Property="HorizontalOptions" Value="CenterAndExpand" />
38+
<Setter Property="Spacing" Value="20" />
39+
<Setter Property="Orientation" Value="Horizontal" />
40+
</Style>
41+
</ResourceDictionary>
42+
</xct:Popup.Resources>
43+
44+
<xct:Popup.View>
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+
<StackLayout Style="{StaticResource ButtonGroup}">
52+
<Button Text="Cancel"
53+
Style="{StaticResource CancelButton}"
54+
Clicked="Cancel_Clicked" />
55+
<Button Text="OKAY"
56+
Clicked="Okay_Clicked" />
57+
</StackLayout>
58+
59+
</StackLayout>
60+
</xct:Popup.View>
61+
62+
</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+
}

0 commit comments

Comments
 (0)