< Summary

Class:BaseComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/BaseComponentView.cs
Covered lines:23
Uncovered lines:2
Coverable lines:25
Total lines:108
Line coverage:92% (23 of 25)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize()0%110100%
Show(...)0%110100%
Hide(...)0%110100%
PostScreenSizeChanged()0%110100%
Dispose()0%110100%
OnEnable()0%110100%
Awake()0%110100%
Start()0%220100%
OnDestroy()0%110100%
OnScreenSizeChange(...)0%2.062075%
RefreshControlAfterScreenSize()0%330100%
Create[T](...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/BaseComponentView.cs

#LineLine coverage
 1using DCL;
 2using System;
 3using System.Collections;
 4using UnityEngine;
 5
 6public interface IBaseComponentView : IDisposable
 7{
 8    /// <summary>
 9    /// It will be triggered after the UI component is fully initialized (PostInitialization included).
 10    /// </summary>
 11    event Action OnFullyInitialized;
 12
 13    /// <summary>
 14    /// Returns true if the UI component is already fully initialized (PostInitialization included).
 15    /// </summary>
 16    bool isFullyInitialized { get; }
 17
 18    /// <summary>
 19    /// It is called just after the UI component has been initialized.
 20    /// </summary>
 21    void PostInitialization();
 22
 23    /// <summary>
 24    /// Shows the UI component.
 25    /// </summary>
 26    /// <param name="instant">True for not apply progressive animation.</param>
 27    void Show(bool instant = false);
 28
 29    /// <summary>
 30    /// Hides the UI component.
 31    /// </summary>
 32    /// <param name="instant">True for not apply progressive animation.</param>
 33    void Hide(bool instant = false);
 34
 35    /// <summary>
 36    /// Updates the UI component with the current model.
 37    /// </summary>
 38    void RefreshControl();
 39
 40    /// <summary>
 41    /// It is called just after the screen size has changed.
 42    /// </summary>
 43    void PostScreenSizeChanged();
 44}
 45
 46[RequireComponent(typeof(ShowHideAnimator))]
 47[RequireComponent(typeof(CanvasGroup))]
 48public abstract class BaseComponentView : MonoBehaviour, IBaseComponentView
 49{
 50    public event Action OnFullyInitialized;
 051    public bool isFullyInitialized { get; private set; }
 52
 53    internal ShowHideAnimator showHideAnimator;
 54
 55    internal void Initialize()
 56    {
 41857        isFullyInitialized = false;
 41858        showHideAnimator = GetComponent<ShowHideAnimator>();
 59
 41860        DataStore.i.screen.size.OnChange += OnScreenSizeChange;
 41861    }
 62
 63    public abstract void PostInitialization();
 64
 265    public virtual void Show(bool instant = false) { showHideAnimator.Show(instant); }
 66
 267    public virtual void Hide(bool instant = false) { showHideAnimator.Hide(instant); }
 68
 69    public abstract void RefreshControl();
 70
 1271    public virtual void PostScreenSizeChanged() { }
 72
 96073    public virtual void Dispose() { DataStore.i.screen.size.OnChange -= OnScreenSizeChange; }
 74
 84675    private void OnEnable() { OnScreenSizeChange(Vector2Int.zero, Vector2Int.zero); }
 76
 83477    private void Awake() { Initialize(); }
 78
 79    private void Start()
 80    {
 22581        PostInitialization();
 82
 22583        isFullyInitialized = true;
 22584        OnFullyInitialized?.Invoke();
 885    }
 86
 83487    private void OnDestroy() { Dispose(); }
 88
 89    internal void OnScreenSizeChange(Vector2Int current, Vector2Int previous)
 90    {
 42391        if (!gameObject.activeInHierarchy)
 092            return;
 93
 42394        StartCoroutine(RefreshControlAfterScreenSize());
 42395    }
 96
 97    internal IEnumerator RefreshControlAfterScreenSize()
 98    {
 42399        yield return null;
 13100        PostScreenSizeChanged();
 13101    }
 102
 103    internal static T Create<T>(string resourceName) where T : BaseComponentView
 104    {
 72105        T buttonComponentView = Instantiate(Resources.Load<GameObject>(resourceName)).GetComponent<T>();
 72106        return buttonComponentView;
 107    }
 108}