< Summary

Class:BaseComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/BaseComponentView.cs
Covered lines:26
Uncovered lines:6
Coverable lines:32
Total lines:138
Line coverage:81.2% (26 of 32)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
OnEnable()0%110100%
Start()0%110100%
Show(...)0%2.032080%
Hide(...)0%2.032080%
OnFocus()0%110100%
OnLoseFocus()0%110100%
OnScreenSizeChanged()0%110100%
Dispose()0%110100%
OnPointerEnter(...)0%110100%
OnPointerExit(...)0%110100%
OnDestroy()0%110100%
OnScreenSizeModified(...)0%2.062075%
RaiseOnScreenSizeChangedAfterDelay()0%5.673033.33%
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;
 5using UnityEngine.EventSystems;
 6
 7public interface IBaseComponentView : IPointerEnterHandler, IPointerExitHandler, IDisposable
 8{
 9    bool isVisible { get; }
 10
 11    /// <summary>
 12    /// It is called at the beginning of the UI component lifecycle.
 13    /// </summary>
 14    void Awake();
 15
 16    /// <summary>
 17    /// It is called each time the component is enabled.
 18    /// </summary>
 19    void OnEnable();
 20
 21    /// <summary>
 22    /// It is called just after the UI component has been initialized.
 23    /// </summary>
 24    void Start();
 25
 26    /// <summary>
 27    /// Updates the UI component with the current model configuration.
 28    /// </summary>
 29    void RefreshControl();
 30
 31    /// <summary>
 32    /// Shows the UI component.
 33    /// </summary>
 34    /// <param name="instant">True for not apply progressive animation.</param>
 35    void Show(bool instant = false);
 36
 37    /// <summary>
 38    /// Hides the UI component.
 39    /// </summary>
 40    /// <param name="instant">True for not apply progressive animation.</param>
 41    void Hide(bool instant = false);
 42
 43    /// <summary>
 44    /// It is called when the focus is set into the component.
 45    /// </summary>
 46    void OnFocus();
 47
 48    /// <summary>
 49    /// It is called when the focus is lost from the component.
 50    /// </summary>
 51    void OnLoseFocus();
 52
 53    /// <summary>
 54    /// It is called just after the screen size has changed.
 55    /// </summary>
 56    void OnScreenSizeChanged();
 57}
 58
 59public interface IComponentModelConfig
 60{
 61    /// <summary>
 62    /// Fill the model and updates the component with this data.
 63    /// </summary>
 64    /// <param name="newModel">Data to configure the component.</param>
 65    void Configure(BaseComponentModel newModel);
 66}
 67
 68public abstract class BaseComponentView : MonoBehaviour, IBaseComponentView
 69{
 70    internal BaseComponentModel baseModel;
 71    internal ShowHideAnimator showHideAnimator;
 72
 073    public bool isVisible { get; private set; }
 74
 75    public virtual void Awake()
 76    {
 181677        showHideAnimator = GetComponent<ShowHideAnimator>();
 181678        DataStore.i.screen.size.OnChange += OnScreenSizeModified;
 181679    }
 80
 385281    public virtual void OnEnable() { OnScreenSizeChanged(); }
 82
 79283    public virtual void Start() { }
 84
 85    public abstract void RefreshControl();
 86
 87    public virtual void Show(bool instant = false)
 88    {
 889        if (showHideAnimator == null)
 090            return;
 91
 892        showHideAnimator.Show(instant);
 893        isVisible = true;
 894    }
 95
 96    public virtual void Hide(bool instant = false)
 97    {
 4798        if (showHideAnimator == null)
 099            return;
 100
 47101        showHideAnimator.Hide(instant);
 47102        isVisible = false;
 47103    }
 104
 2105    public virtual void OnFocus() { }
 106
 2107    public virtual void OnLoseFocus() { }
 108
 1720109    public virtual void OnScreenSizeChanged() { }
 110
 5744111    public virtual void Dispose() { DataStore.i.screen.size.OnChange -= OnScreenSizeModified; }
 112
 4113    public void OnPointerEnter(PointerEventData eventData) { OnFocus(); }
 114
 4115    public void OnPointerExit(PointerEventData eventData) { OnLoseFocus(); }
 116
 3632117    private void OnDestroy() { Dispose(); }
 118
 119    internal void OnScreenSizeModified(Vector2Int current, Vector2Int previous)
 120    {
 1121        if (!gameObject.activeInHierarchy)
 0122            return;
 123
 1124        StartCoroutine(RaiseOnScreenSizeChangedAfterDelay());
 1125    }
 126
 127    internal IEnumerator RaiseOnScreenSizeChangedAfterDelay()
 128    {
 1129        yield return null;
 0130        OnScreenSizeChanged();
 0131    }
 132
 133    internal static T Create<T>(string resourceName) where T : BaseComponentView
 134    {
 236135        T buttonComponentView = Instantiate(Resources.Load<GameObject>(resourceName)).GetComponent<T>();
 236136        return buttonComponentView;
 137    }
 138}