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

[Enhancement] Popup Control #1778

@hartez

Description

@hartez

Rationale

Forms users would like to have the option of defining and displaying Popup controls. These are controls which are modal, can host arbitrary content, allow for complex user interaction, can return a response from the user, and are expressed (by default) using the appropriate controls on each platform:

  • iOS – UIView presented by a UIPopoverPresentationController
  • UWP – Flyout
  • Android – Dialog

Requirements

Popup display must be asynchronous.

Popups must be effectively modal; i.e., only one may be displayed at any given time.

Popups must be light-dismissable where the platform allows for it (e.g., on iPad, they should be light-dismissable; on iPhone this is not an option on all versions).

Users must be able to define their own custom Popups with arbitrary return value types.

Users must be able to host the following in a Popup:

  • View
  • ContentPage
  • NavigationPage

This will effectively mean that Popups must provide for hosting VisualElement; for VisualElement types which are not View, any type other than ContentPage or NavigationPage will throw a NotSupportedException.

Popups must allow for (optionally) specifying an "anchor" View; behavior regarding the anchor will be platform-specific:

  • On iPad, the arrow of the presented PopOver will point to the anchor View. On iPhone, the anchor view will have no effect.
  • On Android, the Dialog will be presented near the anchor View.
  • On UWP, the anchor View will be the View to which the Flyout will be attached.

Popups must allow for a Size specification. If no Size is specified, the Popup will size to its content.

Forms should define a convenience Popup subclass for returning a 1-bit response (i.e., a yes/no, true/false, ok/cancel). In addition to providing convenience for users dealing with this common requirement, it will also serve as an example for users who need to implement other custom scenarios.

Forms should define a convenience Popup subclass for returning (effectively) a void value (in order to easily support users wanting to display simple content with no user response).

API Changes

The INavigation interface will add the following method:

Task<T> ShowPopupAsync<T>(Popup<T> popup);

The following interface will be added to Core:

public interface IPopup<out T>
{
	VisualElement Element { get; }

	void SetDismissDelegate(Action<T> dismissDelegate);
}

The Dismiss delegate is invoked when the Popup is dismissed.

The following classes will be added to Core:

public abstract class Popup<T>

This will be the base class from which all Popups will be built and will provide the core properties and functionality.

public struct PopupDismissed{}
public class Popup : Popup<PopupDismissed>

This is a convenience implementation for users who simply need to display content without receiving a user response.

public class BinaryResultPopup : Popup<BinaryResult>
public enum BinaryResult
{
	Negative,
	Affirmative
}

This is a convenience implementation for users who simply need a yes/no type of response.

Other Notes

A proof-of-concept implementation of an API very similar to this one (iOS-only) exists at https://github.com/xamarin/Xamarin.Forms/tree/popover

Difficulty: High

The basic implementation on iOS should be relatively easy; most of it can be taken from the PoC branch. UWP should also be fairly simple, as Flyout already provides most of what's required. Android implementation may be a bit trickier because of the requirement to position the Popup near the anchor control.

The most difficult aspect is the requirement to display a NavigationPage as content; the current Navigation model may need to be adjusted to accommodate this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions