The plugin allows you to open any page as a popup.
Nuget: https://www.nuget.org/packages/Rg.Plugins.Popup/
Support platforms
- OnAppearing
- OnDisappearing
- OnBackButtonPressed
- OnAppearingAnimationEnd
- OnDisappearingAnimationBegin
- OnBackgroundClicked
Events
- BackgroundClicked: Called when clicked on background
Animations
FadeAnimation
- DurationIn (uint)
- DurationOut (uint)
- EasingIn (Easing)
- EasingOut (Easing)
- HasBackgroundAnimation (bool)
MoveAnimation
- PositionIn (MoveAnimationOptions)
- PositionOut (MoveAnimationOptions)
- DurationIn (uint)
- DurationOut (uint)
- EasingIn (Easing)
- EasingOut (Easing)
- HasBackgroundAnimation (bool)
ScaleAnimation
- ScaleIn (double)
- ScaleOut (double)
- PositionIn (MoveAnimationOptions)
- PositionOut (MoveAnimationOptions)
- DurationIn (uint)
- DurationOut (uint)
- EasingIn (Easing)
- EasingOut (Easing)
- HasBackgroundAnimation (bool)
Initialization
To use a PopupPage inside an application, each platform application must initialize the Rg.Plugins.Popup.
This initialization step varies from platform to platform and is discussed in the following sections.
iOS
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Rg.Plugins.Popup.Popup.Init();
global::Xamarin.Forms.Forms.Init ();
LoadApplication (new App ());
return base.FinishedLaunching (app, options);
}
}
Android
namespace HelloXamarinFormsWorld.Android
{
[Activity(Label = "HelloXamarinFormsWorld", MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Rg.Plugins.Popup.Popup.Init(this, bundle);
Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication (new App ());
}
}
}
Universal Windows Platform
In Universal Windows Platform (UWP) applications, the Init method that initializes the Rg.Plugins.Popup is invoked from the App class:
Rg.Plugins.Popup.Popup.Init();
Xamarin.Forms.Forms.Init (e);
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
...
}
UWP Troubleshooting
"Target Invocation Exception" when using "Compile with .NET Native tool chain":
This might occur when using the Compile with .NET Native tool chain which is an option for UWP apps in the Properties > Build > General window for the project.
You can fix this by using a UWP-specific overload of the Forms.Init call in App.xaml.cs as shown in the code below
Xamarin.Forms.Forms.Init(e, Rg.Plugins.Popup.Popup.GetExtraAssemblies());
-
IsAnimating
-
Animation
-
BackgroundColor: Hex #80FF5C5C where #80 opacity Range
-
CloseWhenBackgroundIsClicked: Close pop-up when click on the background
-
HasSystemPadding: Enabled/Disabled system padding offset (Only for Content not for Background)
-
SystemPadding: (ReadOnly) Thickness
How To Use
Task PushAsync(PopupPage page, bool animate = true)
Task PopAsync(bool animate = true)
Task PopAllAsync(bool animate = true)
Task RemovePageAsync(PopupPage page, bool animate = true)
<?xml version="1.0" encoding="utf-8" ?>
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup"
x:Class="Demo.Pages.MyPopupPage">
<pages:PopupPage.Animation>
<animations:ScaleAnimation
PositionIn="Center"
PositionOut="Center"
ScaleIn="1.2"
ScaleOut="0.8"
DurationIn="400"
DurationOut="300"
EasingIn="SinOut"
EasingOut="SinIn"
HasBackgroundAnimation="True"/>
</pages:PopupPage.Animation>
</pages:PopupPage>
public partial class MyPopupPage : PopupPage
{
public MyPopupPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
}
protected override Task OnAppearingAnimationEnd()
{
return Content.FadeTo(0.5);
}
protected override Task OnDisappearingAnimationBegin()
{
return Content.FadeTo(1);
}
protected override bool OnBackButtonPressed()
{
return true;
}
protected override bool OnBackgroundClicked()
{
return base.OnBackgroundClicked();
}
}
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async void OnOpenPupup(object sender, EventArgs e)
{
var page = new MyPopupPage();
await Navigation.PushPopupAsync(page);
await PopupNavigation.PushAsync(page);
}
}
User Animation
class UserAnimation : IPopupAnimation
{
public void Preparing(View content, PopupPage page)
{
content.Opacity = 0;
}
public void Disposing(View content, PopupPage page)
{
}
public async Task Appearing(View content, PopupPage page)
{
await content.FadeTo(1);
}
public async Task Disappearing(View content, PopupPage page)
{
await content.FadeTo(0);
}
}
public partial class UserPopupPage : PopupPage
{
public SecondPopupPage()
{
InitializeComponent();
Animation = new UserAnimation();
}
}
Or in xaml
<?xml version="1.0" encoding="utf-8" ?>
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
xmlns:animations="clr-namespace:Demo.Animations;assembly=Demo"
x:Class="Demo.Pages.UserAnimationPage">
<pages:PopupPage.Animation>
<animations:UserAnimation/>
</pages:PopupPage.Animation>
...
</pages:PopupPage>
Thanks
License
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.