< Summary

Class:ModalComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Modal/ModalComponentView.cs
Covered lines:14
Uncovered lines:16
Coverable lines:30
Total lines:93
Line coverage:46.6% (14 of 30)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ModalComponentView()0%110100%
Start()0%2100%
RefreshControl()0%3.073080%
Configure(...)0%110100%
CanBeCancelled(...)0%2100%
CloseButtonClicked()0%3.073080%
Show(...)0%6200%
Hide(...)0%2.52050%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7public interface IModalComponentView
 8{
 9    /// <summary>
 10    /// It will be triggered when the modal is closed.
 11    /// </summary>
 12    event Action OnCloseAction;
 13
 14    /// <summary>
 15    /// Fill the model and updates the modal with this data.
 16    /// </summary>
 17    /// <param name="model">Data to configure the image.</param>
 18    void Configure(ModalComponentModel model);
 19
 20    /// <summary>
 21    /// This will hide the close button of the pop up, forcing the user to take an action
 22    /// </summary>
 23    /// <param name="canBe"></param>
 24    void CanBeCancelled(bool canBe);
 25}
 26
 27public class ModalComponentView : BaseComponentView, IModalComponentView
 28{
 29    public event Action OnCloseAction;
 30
 31    [Header("Prefab References")]
 32    [SerializeField] internal ButtonComponentView closeButton;
 33    [SerializeField] internal Button alphaBackground;
 34    [SerializeField] internal GameObject container;
 35
 36    [Header("Configuration")]
 37    [SerializeField] internal ModalComponentModel model;
 38
 39    internal GameObject content;
 440    internal bool canBeCanceled = true;
 41
 42    public override void Start()
 43    {
 044        base.Start();
 45
 046        closeButton.onClick.AddListener(CloseButtonClicked);
 047        alphaBackground.onClick.AddListener(CloseButtonClicked);
 048        RefreshControl();
 049    }
 50
 51    public override void RefreshControl()
 52    {
 153        if (content != null)
 054            Destroy(content);
 155        if (model.content != null)
 156            content = Instantiate(model.content, container.transform);
 157    }
 58
 59    public void Configure(ModalComponentModel model)
 60    {
 161        this.model = model;
 162        RefreshControl();
 163    }
 64
 65    public void CanBeCancelled(bool canBe)
 66    {
 067        closeButton.gameObject.SetActive(canBe);
 068        canBeCanceled = canBe;
 069    }
 70
 71    internal void CloseButtonClicked()
 72    {
 173        if (!canBeCanceled)
 074            return;
 175        OnCloseAction?.Invoke();
 176        Hide();
 177    }
 78
 79    public override void Show(bool instant = false)
 80    {
 081        if (isVisible)
 082            return;
 83
 084        base.Show(instant);
 085    }
 86    public override void Hide(bool instant = false)
 87    {
 188        if (!isVisible)
 189            return;
 90
 091        base.Hide(instant);
 092    }
 93}