Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tuyen-vuduc/686927fa692155e5d94a4b68de556bc8 to your computer and use it in GitHub Desktop.
Save tuyen-vuduc/686927fa692155e5d94a4b68de556bc8 to your computer and use it in GitHub Desktop.
Prism with PopupPage integration
public partial class App : PrismApplication
{
public App(IPlatformInitializer initializer = null) : base(initializer)
{
}
protected override Prism.Navigation.INavigationService CreateNavigationService()
{
var applicationProvider = Container.Resolve<IApplicationProvider>();
return new PopupEnabledNavigationService(Container, applicationProvider, Logger);
}
protected override async void OnInitialized()
{
InitializeComponent();
}
protected override void OnStart()
{
base.OnStart();
}
protected override void RegisterTypes()
{
}
}
public class PopupEnabledNavigationService : DryIocPageNavigationService
{
IPopupNavigation popupNav;
public PopupEnabledNavigationService(IContainer container, IApplicationProvider applicationProvider, ILoggerFacade logger)
: base(applicationProvider, container, logger)
{
popupNav = container.Resolve<IPopupNavigation>();
}
protected override Task DoPush(Xamarin.Forms.Page currentPage, Xamarin.Forms.Page page, bool? useModalNavigation, bool animated)
{
if (page is PopupPage)
{
popupNav.AddPopup((PopupPage)page);
return Task.Run(() => {});
}
return base.DoPush(currentPage, page, useModalNavigation, animated);
}
public override async Task<bool> GoBackAsync(Prism.Navigation.NavigationParameters parameters = null, bool? useModalNavigation = default(bool?), bool animated = true)
{
var page = GetCurrentPage();
if (page is PopupPage)
{
var segmentParameters = UriParsingHelper.GetSegmentParameters(null, parameters);
segmentParameters.Add(KnownNavigationParameters.NavigationMode, NavigationMode.Back);
var canNavigate = await PageUtilities.CanNavigateAsync(page, segmentParameters);
if (!canNavigate)
return false;
PageUtilities.OnNavigatingTo(page, segmentParameters);
popupNav.RemovePopup((PopupPage)page);
var nav = page.BindingContext as INavigationAware;
PageUtilities.OnNavigatedFrom(page, segmentParameters);
var host = PageUtilities.GetCurrentPage(Application.Current.MainPage);
PageUtilities.OnNavigatedTo(host, segmentParameters);
return true;
}
return await base.GoBackAsync(parameters, useModalNavigation, animated);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment