Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Improving the operation of PresentationControllers #1846

Merged
merged 5 commits into from
Jan 13, 2022

Conversation

dimonovdd
Copy link
Contributor

@dimonovdd dimonovdd commented Jul 12, 2021

Description of Change

Using Rg.Plugins.Popup and Essentials together, I noticed some problems:

  • Closing Popups closes pickers and etc., but the tasks remain not finished.
  • We don't have the option to specify a UIViewController before opening pickers

This is due not only to Rg.Plugins.Popup, but also to any projects that use custom controllers for rendering pages.

API Changes

Added:

public static partial class Platform
{
    public static void Init(Func<UIViewController> getCurrentUIViewController)
}

Behavioral Changes

  • All tasks will be finished when the controller is closed
  • Ability to change the parent controller for pickers

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Updated documentation (see walkthrough)


protected override void Dispose(bool disposing)
{
DismissHandler?.Invoke();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Experimentally, I found out that DidDismiss method is not always called when closing parent controllers. And this is probably the only workaround to finish a TaskCompletionSource.

@mattleibow mattleibow added this to the 1.7.0 milestone Jul 13, 2021
Comment on lines +78 to +79
public static void Init(Func<UIViewController> getCurrentUIViewController)
=> getCurrentController = getCurrentUIViewController;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimonovdd What would be a use case for this? Just for reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was such a case in my application:

  1. A popup appears
  2. FilePicker appears
  3. The popup closes and it closes the picker

because the picker was opened from the popup controller, and not from main navigation controller

dimonovdd added a commit to dimonovdd/maui that referenced this pull request Sep 20, 2021
@jamesmontemagno jamesmontemagno removed this from the 1.7.0 milestone Oct 7, 2021
@dimonovdd
Copy link
Contributor Author

dimonovdd commented Nov 22, 2021

Will it be merged? It is a big problem. It has been fixed in many libraries for example in userdialogs:

Nothing is necessary any longer as of v4.x. There is an Init function for iOS but it is OPTIONAL and only required if you want/need to control
the top level viewcontroller for things like iOS extensions. Progress prompts will not use this factory function though!

Usage example:

[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNavigationRenderer))]

public class CustomNavigationRenderer : NavigationRenderer
{
    public static CustomNavigationRenderer LastController { get; private set; }
    
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        LastController = this;
    }
}
static UIViewController? GetTopViewController()
{
    if (!(PopupNavigation.Instance?.PopupStack?.Any() ?? false))
        return Xamarin.Essentials.Platform.GetCurrentUIViewController();

    return CustomNavigationRenderer.LastController?.ViewControllers?.LastOrDefault();
}
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    \\...
    UserDialogs.Init(GetTopViewController);
    \\...
}

@mattleibow mattleibow self-assigned this Jan 12, 2022
mattleibow
mattleibow previously approved these changes Jan 12, 2022
@mattleibow mattleibow merged commit b9ad98b into xamarin:main Jan 13, 2022
@dimonovdd dimonovdd deleted the gettingUIViewController branch January 13, 2022 06:59
mattleibow added a commit to dotnet/maui that referenced this pull request Jan 13, 2022
Co-authored-by: Redth <jondick@gmail.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
@jfversluis jfversluis added this to the 1.7.1 milestone Jan 18, 2022
maxkatz6 pushed a commit to AvaloniaUI/Avalonia.Essentials that referenced this pull request May 15, 2023
Co-authored-by: Redth <jondick@gmail.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants