Skip to content

Commit

Permalink
Ported Popup Control from xamarin/Xamarin.Forms#9616 to Xamarin Commu…
Browse files Browse the repository at this point in the history
…nity Toolkit
  • Loading branch information
SkyeHoefling committed Dec 12, 2020
1 parent e26c053 commit 50df8a6
Show file tree
Hide file tree
Showing 45 changed files with 2,358 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using Xamarin.Essentials;

namespace Xamarin.CommunityToolkit.Sample.Droid
{
Expand All @@ -17,14 +16,15 @@ protected override void OnCreate(Bundle savedInstanceState)
base.OnCreate(savedInstanceState);

global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
Platform.Init(this, savedInstanceState);
Essentials.Platform.Init(this, savedInstanceState);
ToolkitPlatform.Init(this);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties XamarinHotReloadXFormsNugetUpgradeInfoBarXamarinCommunityToolkitSampleAndroidHideInfoBar="True" />
<UserProperties XamarinHotReloadXFormsNugetUpgradeInfoBarXamarinCommunityToolkitSampleAndroidHideInfoBar="True" TriggeredFromHotReload="False" />
</VisualStudio>
</ProjectExtensions>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8" ?>
<pages:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
xmlns:viewModels="clr-namespace:Xamarin.CommunityToolkit.Sample.ViewModels.Views"
xmlns:custom="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.PopupGalleryPage"
Title="Popup Control"
x:Name="root">

<ContentPage.BindingContext>
<viewModels:PopupControlViewModel />
</ContentPage.BindingContext>

<ContentPage.Resources>
<ResourceDictionary>
<Style x:Key="Header" TargetType="Label">
<Setter Property="VerticalOptions" Value="CenterAndExpand" />
<Setter Property="HorizontalOptions" Value="CenterAndExpand" />
<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" />
</Style>
</ResourceDictionary>
</ContentPage.Resources>

<ContentPage.Content>
<StackLayout>
<ScrollView>
<StackLayout>
<Label Style="{StaticResource Header}"
Text="The popup control renders native popups from the shared code. This page demonstrates a variety of different techniques for displaying native popups." />
<StackLayout Style="{StaticResource ItemsLayout}"
BindableLayout.ItemsSource="{Binding Examples}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<custom:PancakeView Style="{StaticResource card}"
Margin="{StaticResource ContentPadding}">
<custom:PancakeView.GestureRecognizers>
<TapGestureRecognizer Command="{Binding BindingContext.DisplayPopup, Source={x:Reference root}}"
CommandParameter="{Binding Type}" />
</custom:PancakeView.GestureRecognizers>
<Grid ColumnSpacing="20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="12" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<BoxView BackgroundColor="{Binding Color}" />
<StackLayout Grid.Column="1" Spacing="8" Padding="0,24,24,24">
<Label Style="{StaticResource label_section_header}" Text="{Binding Title}" />
<Label Text="{Binding Description}" />
</StackLayout>
</Grid>
</custom:PancakeView>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</StackLayout>
</ScrollView>
</StackLayout>
</ContentPage.Content>
</pages:BasePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Xamarin.CommunityToolkit.Sample.Pages.Views
{
public partial class PopupGalleryPage
{
public PopupGalleryPage() => InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8" ?>
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
Size="{OnPlatform Android='800, 700', UWP='300, 250', iOS='250, 400'}"
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.Popups.ButtonPopup">

<xct:Popup.Resources>
<ResourceDictionary>
<Style x:Key="Title" TargetType="Label">
<Setter Property="FontSize" Value="26" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="TextColor" Value="#000" />
<Setter Property="VerticalTextAlignment" Value="Center" />
<Setter Property="HorizontalTextAlignment" Value="Center" />
</Style>
<Style x:Key="Divider" TargetType="BoxView">
<Setter Property="HeightRequest" Value="1" />
<Setter Property="Margin" Value="50, 25" />
<Setter Property="Color" Value="#c3c3c3" />
</Style>
<Style x:Key="Content" TargetType="Label">
<Setter Property="HorizontalTextAlignment" Value="Start" />
<Setter Property="VerticalTextAlignment" Value="Center" />
</Style>
<Style x:Key="PopupLayout" TargetType="StackLayout">
<Setter Property="Padding" Value="{OnPlatform Android=20, UWP=20, iOS=5}" />
</Style>
<Style x:Key="ConfirmButton" TargetType="Button">
<Setter Property="VerticalOptions" Value="EndAndExpand" />
</Style>
</ResourceDictionary>
</xct:Popup.Resources>

<xct:Popup.View>
<StackLayout Style="{StaticResource PopupLayout}">
<Label Style="{StaticResource Title}"
Text="Button Popup" />
<BoxView Style="{StaticResource Divider}" />
<Label Style="{StaticResource Content}"
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." />
<Button Text="OKAY"
Style="{StaticResource ConfirmButton}"
Clicked="Button_Clicked" />
</StackLayout>
</xct:Popup.View>

</xct:Popup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Xamarin.CommunityToolkit.Sample.Pages.Views.Popups
{
public partial class ButtonPopup
{
public ButtonPopup() => InitializeComponent();

void Button_Clicked(object sender, System.EventArgs e) => Dismiss(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8" ?>
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
Size="{OnPlatform Android='800, 700', UWP='300, 250', iOS='250, 400'}"
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.Popups.MultipleButtonPopup">

<xct:Popup.Resources>
<ResourceDictionary>
<Style x:Key="Title" TargetType="Label">
<Setter Property="FontSize" Value="26" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="TextColor" Value="#000" />
<Setter Property="VerticalTextAlignment" Value="Center" />
<Setter Property="HorizontalTextAlignment" Value="Center" />
</Style>
<Style x:Key="Divider" TargetType="BoxView">
<Setter Property="HeightRequest" Value="1" />
<Setter Property="Margin" Value="50, 25" />
<Setter Property="Color" Value="#c3c3c3" />
</Style>
<Style x:Key="Content" TargetType="Label">
<Setter Property="HorizontalTextAlignment" Value="Start" />
<Setter Property="VerticalTextAlignment" Value="Center" />
</Style>
<Style x:Key="PopupLayout" TargetType="StackLayout">
<Setter Property="Padding" Value="{OnPlatform Android=20, UWP=20, iOS=5}" />
</Style>
<Style x:Key="CancelButton" TargetType="Button">
<Setter Property="Background" Value="#FFF" />
<Setter Property="BorderWidth" Value="1" />
<Setter Property="BorderColor" Value="Blue" />
<Setter Property="TextColor" Value="Blue" />
</Style>
<Style x:Key="ButtonGroup" TargetType="StackLayout">
<Setter Property="VerticalOptions" Value="EndAndExpand" />
<Setter Property="HorizontalOptions" Value="CenterAndExpand" />
<Setter Property="Spacing" Value="20" />
<Setter Property="Orientation" Value="Horizontal" />
</Style>
</ResourceDictionary>
</xct:Popup.Resources>

<xct:Popup.View>
<StackLayout Style="{StaticResource PopupLayout}">
<Label Style="{StaticResource Title}"
Text="Button Popup" />
<BoxView Style="{StaticResource Divider}" />
<Label Style="{StaticResource Content}"
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." />
<StackLayout Style="{StaticResource ButtonGroup}">
<Button Text="Cancel"
Style="{StaticResource CancelButton}"
Clicked="Cancel_Clicked" />
<Button Text="OKAY"
Clicked="Okay_Clicked" />
</StackLayout>

</StackLayout>
</xct:Popup.View>

</xct:Popup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Xamarin.CommunityToolkit.Sample.Pages.Views.Popups
{
public partial class MultipleButtonPopup
{
public MultipleButtonPopup() => InitializeComponent();

void Cancel_Clicked(object sender, System.EventArgs e) => Dismiss(false);

void Okay_Clicked(object sender, System.EventArgs e) => Dismiss(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8" ?>
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
Size="{OnPlatform Android='800, 700', UWP='300, 250', iOS='250, 400'}"
IsLightDismissEnabled="False"
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.Popups.NoLightDismissPopup">

<xct:Popup.Resources>
<ResourceDictionary>
<Style x:Key="Title" TargetType="Label">
<Setter Property="FontSize" Value="26" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="TextColor" Value="#000" />
<Setter Property="VerticalTextAlignment" Value="Center" />
<Setter Property="HorizontalTextAlignment" Value="Center" />
</Style>
<Style x:Key="Divider" TargetType="BoxView">
<Setter Property="HeightRequest" Value="1" />
<Setter Property="Margin" Value="50, 25" />
<Setter Property="Color" Value="#c3c3c3" />
</Style>
<Style x:Key="Content" TargetType="Label">
<Setter Property="HorizontalTextAlignment" Value="Start" />
<Setter Property="VerticalTextAlignment" Value="Center" />
</Style>
<Style x:Key="PopupLayout" TargetType="StackLayout">
<Setter Property="Padding" Value="{OnPlatform Android=20, UWP=20, iOS=5}" />
</Style>
</ResourceDictionary>
</xct:Popup.Resources>

<xct:Popup.View>
<StackLayout Style="{StaticResource PopupLayout}">
<Label
Style="{StaticResource Title}"
Text="Simple Popup" />
<BoxView Style="{StaticResource Divider}" />
<Label
Style="{StaticResource Content}"
Text="{OnPlatform
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.',
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.',
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'}" />
<Button
Text="Close"
VerticalOptions="EndAndExpand"
Clicked="Button_Clicked" />
</StackLayout>
</xct:Popup.View>

</xct:Popup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Xamarin.CommunityToolkit.Sample.Pages.Views.Popups
{
public partial class NoLightDismissPopup
{
public NoLightDismissPopup() => InitializeComponent();

void Button_Clicked(object sender, System.EventArgs e) => Dismiss(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8" ?>
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
Size="{OnPlatform Android='800, 700', UWP='300, 250', iOS='250, 350'}"
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.Popups.OpenedEventSimplePopup">

<xct:Popup.Resources>
<ResourceDictionary>
<Style x:Key="Title" TargetType="Label">
<Setter Property="FontSize" Value="26" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="TextColor" Value="#000" />
<Setter Property="VerticalTextAlignment" Value="Center" />
<Setter Property="HorizontalTextAlignment" Value="Center" />
</Style>
<Style x:Key="Divider" TargetType="BoxView">
<Setter Property="HeightRequest" Value="1" />
<Setter Property="Margin" Value="50, 25" />
<Setter Property="Color" Value="#c3c3c3" />
</Style>
<Style x:Key="Content" TargetType="Label">
<Setter Property="HorizontalTextAlignment" Value="Start" />
<Setter Property="VerticalTextAlignment" Value="Center" />
</Style>
<Style x:Key="PopupLayout" TargetType="StackLayout">
<Setter Property="Padding" Value="{OnPlatform Android=20, UWP=20, iOS=5}" />
</Style>
</ResourceDictionary>
</xct:Popup.Resources>

<xct:Popup.View>
<StackLayout Style="{StaticResource PopupLayout}">
<Label x:Name="title"
Style="{StaticResource Title}" />
<BoxView Style="{StaticResource Divider}" />
<Label x:Name="message"
Style="{StaticResource Content}" />
</StackLayout>
</xct:Popup.View>

</xct:Popup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Xamarin.CommunityToolkit.UI.Views;

namespace Xamarin.CommunityToolkit.Sample.Pages.Views.Popups
{
public partial class OpenedEventSimplePopup
{
public OpenedEventSimplePopup()
{
InitializeComponent();
Opened += OnOpened;
}

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

title.Text = "Opened Event Popup";
message.Text = "The content of this popup was updated after the popup was rendered";
}
}
}
Loading

0 comments on commit 50df8a6

Please sign in to comment.