Skip to content

Getting started

Kirill edited this page Jan 25, 2019 · 9 revisions

Getting Started with Rg.Plugins.Popup

One version of the plugin must be installed to each native project and PCL/Net.Standard before to be used.

Initialization

The plugin requires to be initialized. 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 ());
        }
    }
}

Also, you need to override OnBackPressed for MainActivity. For more information see Android Back Button chapter

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, Rg.Plugins.Popup.Popup.GetExtraAssemblies());

if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
  ...
}

You can read more information about "why do I need to use GetExtraAssemblies" in the troubleshooting documentation page.

Android Back Button

For Android back button to work with the plugin, you should invoke Rg.Plugins.Popup.Popup.SendBackPressed in your MainActivity in override method OnBackPressed

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    ...

    public override void OnBackPressed()
    {
        if (Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed))
        {
            // Do something if there are some pages in the `PopupStack`
        }
        else
        {
            // Do something if there are not any pages in the `PopupStack`
        }
    }

    ...
}
Clone this wiki locally