Skip to content

Commit f7f1012

Browse files
committed
feat: add OnPushed and OnPopped methods with transition handling for MonoView
1 parent 6181569 commit f7f1012

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

Assets/PurrUI/Runtime/MonoView.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ public class MonoView : MonoBehaviour
2020

2121
public Canvas canvas { get; private set; }
2222

23+
/// <summary>
24+
/// Called when this view is pushed onto a ViewStack, before any enter transition plays.
25+
/// </summary>
2326
public virtual void OnPushed() { }
2427

28+
/// <summary>
29+
/// Called when this view is popped from a ViewStack, before any exit transition plays.
30+
/// </summary>
2531
public virtual void OnPopped() { }
2632

27-
2833
public void Initialize(ViewStack parentStack)
2934
{
3035
this.parentStack = parentStack;
@@ -51,29 +56,61 @@ public void MoveToForeground()
5156
OnBecomeForeground();
5257
}
5358

59+
/// <summary>
60+
/// Called when this view becomes the top-most interactive view in the stack.
61+
/// </summary>
5462
protected virtual void OnBecomeForeground() { }
5563

64+
/// <summary>
65+
/// Called when this view is no longer the top-most view due to another view being pushed on top.
66+
/// </summary>
5667
protected virtual void OnBecomeBackground() { }
5768

5869
public IEnumerator EnterTransition() => OnEnterTransition();
5970

6071
public IEnumerator ExitTransition() => OnExitTransition();
6172

73+
/// <summary>
74+
/// Override to provide a transition animation when this view is pushed onto the stack.
75+
/// </summary>
6276
protected virtual IEnumerator OnEnterTransition() => null;
77+
78+
/// <summary>
79+
/// Override to provide a transition animation when this view is popped from the stack.
80+
/// </summary>
6381
protected virtual IEnumerator OnExitTransition() => null;
6482

6583
public IEnumerator CulledTransition() => OnCulledTransition();
6684

6785
public IEnumerator UnculledTransition() => OnUnculledTransition();
6886

87+
/// <summary>
88+
/// Override to provide a transition animation when this view is culled by a view above it.
89+
/// </summary>
6990
protected virtual IEnumerator OnCulledTransition() => null;
91+
92+
/// <summary>
93+
/// Override to provide a transition animation when this view is restored after being culled.
94+
/// </summary>
7095
protected virtual IEnumerator OnUnculledTransition() => null;
7196

7297
internal void DestroyMe()
7398
{
7499
Destroy(gameObject);
75100
}
76101

102+
/// <summary>
103+
/// Pops this view from its parent stack. Can be used as a UnityEvent callback.
104+
/// </summary>
105+
[UsedImplicitly]
106+
public void PopMe()
107+
{
108+
parentStack.Pop(this);
109+
}
110+
111+
/// <summary>
112+
/// Pops this view from its parent stack. Can be used as a UnityEvent callback.
113+
/// </summary>
77114
[UsedImplicitly]
78115
public void CloseMe()
79116
{

0 commit comments

Comments
 (0)