Class Popup
This is the base class for any UI component that needs to be displayed over the rest of the user interface.
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
public abstract class Popup
Constructors
Popup(VisualElement, VisualElement, VisualElement)
Default constructor.
Declaration
protected Popup(VisualElement referenceView, VisualElement view, VisualElement contentView = null)
Parameters
| Type | Name | Description |
|---|---|---|
| VisualElement | referenceView | The reference view used as context provider for the popup. |
| VisualElement | view | The popup visual element itself. |
| VisualElement | contentView | The content that will appear inside this popup. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | The referenceView can't be null. |
| ArgumentNullException | The view can't be null. |
Fields
m_InvokeShownAction
A pre-allocated Action that calls InvokeShownEventHandlers().
Declaration
protected readonly Action m_InvokeShownAction
Field Value
| Type | Description |
|---|---|
| Action |
Properties
containerView
The parent of the view when the popup will be displayed.
Declaration
public VisualElement containerView { get; protected set; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
contentView
The content of the popup.
Declaration
public VisualElement contentView { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
keyboardDismissEnabled
`True` if the the popup can be dismissed by pressing the escape key or the return button on mobile, `False` otherwise.
The default value is `True`.
Declaration
public bool keyboardDismissEnabled { get; protected set; }
Property Value
| Type | Description |
|---|---|
| bool |
referenceView
The view used as context provider for the popup.
Declaration
public VisualElement referenceView { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
rootView
The root view of the popup. It can be the container view itself or one of its ancestors.
Declaration
public VisualElement rootView { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Remarks
We do not use the panel.visualTree element as root view directly because this element persists in between tabbed windows and can be shared between multiple panels. This would end up with a leak of the popup element.
See Also
view
Returns the popup's VisualElement.
Declaration
public VisualElement view { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Methods
AnimateViewIn()
Start the animation for this popup.
Declaration
protected virtual void AnimateViewIn()
AnimateViewOut(DismissType)
Start the hide animation for this popup.
Declaration
protected virtual void AnimateViewOut(DismissType reason)
Parameters
| Type | Name | Description |
|---|---|---|
| DismissType | reason | The reason why the popup should be dismissed. |
Dismiss()
Dismiss the Popup.
Declaration
public virtual void Dismiss()
Dismiss(DismissType)
Dismiss the Popup.
Declaration
public virtual void Dismiss(DismissType reason)
Parameters
| Type | Name | Description |
|---|---|---|
| DismissType | reason | Why the element has been dismissed. |
FindSuitableParent(VisualElement)
Find the parent VisualElement where the popup will be added.
Declaration
protected virtual VisualElement FindSuitableParent(VisualElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| VisualElement | element | An arbitrary UI element inside the panel. |
Returns
| Type | Description |
|---|---|
| VisualElement | The popup container VisualElement in the current panel. |
Remarks
This is usually one of the layers from the Panel root UI element. If no Panel is found, the method will return the visual tree root of the given element.
GetFocusableElement()
Returns the element that will be focused when the view will become visible.
The default value is `null`.
Declaration
protected virtual VisualElement GetFocusableElement()
Returns
| Type | Description |
|---|---|
| VisualElement | The element that will be focused when the view will become visible. |
HideView(DismissType)
Called when it is time to hide the popup.
Declaration
protected virtual void HideView(DismissType reason)
Parameters
| Type | Name | Description |
|---|---|---|
| DismissType | reason | The reason why the popup should be dismissed. |
InvokeDismissedEventHandlers(DismissType)
Called when the popup has completed its dismiss process.
Declaration
protected virtual void InvokeDismissedEventHandlers(DismissType reason)
Parameters
| Type | Name | Description |
|---|---|---|
| DismissType | reason | The reason why the popup has been dismissed. |
InvokeShownEventHandlers()
Called when the popup has become visible.
Declaration
protected virtual void InvokeShownEventHandlers()
OnLayoutReadyToAnimateIn()
Called when the layout is ready to be animated in.
Declaration
protected virtual void OnLayoutReadyToAnimateIn()
OnViewKeyDown(KeyDownEvent)
Called when the popup has received a KeyDownEvent.
By default this method handles the dismiss of the popup via the Escape key or a Return button.
Declaration
protected virtual void OnViewKeyDown(KeyDownEvent evt)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyDownEvent | evt | The event the popup has received. |
PrepareAnimateViewIn()
Called a frame before AnimateViewIn() to prepare the layout a final time.
Declaration
protected virtual void PrepareAnimateViewIn()
ShouldAnimate()
Implement this method to know if the popup should call AnimateViewIn() and AnimateViewOut(DismissType) methods or not.
Declaration
protected virtual bool ShouldAnimate()
Returns
| Type | Description |
|---|---|
| bool |
|
ShouldDismiss(DismissType)
Check if the popup should be dismissed or not, depending on the reason.
Declaration
protected virtual bool ShouldDismiss(DismissType reason)
Parameters
| Type | Name | Description |
|---|---|---|
| DismissType | reason | Why the element has been dismissed. |
Returns
| Type | Description |
|---|---|
| bool |
|
Show()
Show the Popup.
Declaration
public virtual void Show()
ShowView()
Called when it is time to show the popup.
Declaration
protected virtual void ShowView()
Remarks
In this method the view should become visible at some point (directly or via an animation).
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Unable to find a suitable parent for the popup. |