Lifecycle

Concepts

  • The actual entry point to the screen.

  • It acts as the Presenter in the MVP.

  • Create it on a per-screen basis.

  • We call it Lifecycle because it's associated with the lifetime of the screen.

  • Create only one on a screen. (no exceptions).

Implementation policy

  • The constructor is only responsible for getting a reference to each class imported from the LifetimeScope (it doesn't do any other complicated processing)

  • Before switching screens WillPushEnterAsync we do the following

    • Create a Model.

    • Initialize the View (pass the created model to the View).

  • After switching screens DidPushEnter Subscribe to handling the View button in *. If you enable button handling after screen transitions, button input events will not be fired during transitions (button presses during transitions can be frustrating in many ways).

  • Specify AssetName (the name of the prep) in an attribute of the class.

Example code

[AssetName("TestPage")]
public class TestPageLifecycle : LifecyclePageBase
{
    // ์ƒ์„ฑ์ž์—์„œ ๋ฐ›๋Š” ๊ฒƒ์„ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค.
    private readonly TestPageView _view;
    private readonly PageEventPublisher _publisher;
    private readonly ModalManager _modalManager;

    // ์ƒ์„ฑ์ž ์ธ์ ์…˜
    [Inject]
    public TestPageLifecycle(TestPageView view, PageEventPublisher publisher, ModalManager modalManager) : base(view)
    {
        _view = view;
        _publisher = publisher;
        _modalManager = modalManager;
    }

    // ํ™”๋ฉด ์ „ํ™˜ ์ „ ํƒ€์ด๋ฐ์— View ์ดˆ๊ธฐํ™”ํ•˜๊ธฐ
    protected override UniTask WillPushEnterAsync(CancellationToken cancellationToken)
    {
        var testModel = new TestPageModel();
        _view.SetView(testModel);
        return UniTask.CompletedTask;
    }

    // ํ™”๋ฉด ์ „ํ™˜ ํ›„ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ๋“ฑ๋กํ•˜๊ธฐ
    public override void DidPushEnter()
    {
        base.DidPushEnter();
        // ํŽ˜์ด์ง€ ํ‘œ์‹œ
        _view.OnClickPage.Subscribe(_ => {
          _publisher.SendPushEvent(new NextPageBuilder());
        });
        // Modal ํ‘œ์‹œ
        _view.OnClickModal.Subscribe(_ => {
          _modalManager.Push(new NextModalBuilder()).Forget();
        });
    }
}

Last updated