| | 1 | | using DCL.Helpers; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | namespace UIComponents.CollapsableSortedList |
| | 6 | | { |
| | 7 | | public class CollapsableListToggleButton : BaseComponentView |
| | 8 | | { |
| | 9 | | [SerializeField] private bool toggleOnAwake; |
| | 10 | | [SerializeField] private Button toggleButton; |
| | 11 | | [SerializeField] private Transform toggleButtonIcon; |
| | 12 | | [SerializeField] private RectTransform containerRectTransform; |
| | 13 | | [SerializeField] private CollapsableListToggleButtonModel model; |
| | 14 | |
|
| | 15 | | public override void Awake() |
| | 16 | | { |
| 36 | 17 | | base.Awake(); |
| | 18 | |
|
| 36 | 19 | | toggleButton.onClick.AddListener(Toggle); |
| | 20 | |
|
| 36 | 21 | | if (toggleOnAwake) |
| 0 | 22 | | Toggle(); |
| 36 | 23 | | } |
| | 24 | |
|
| | 25 | | public override void RefreshControl() |
| | 26 | | { |
| 0 | 27 | | Toggle(model.isToggled); |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | public void Toggle(bool toggled) |
| | 31 | | { |
| 48 | 32 | | containerRectTransform.gameObject.SetActive(toggled); |
| 48 | 33 | | var absScale = Mathf.Abs(toggleButtonIcon.localScale.y); |
| 48 | 34 | | var scale = toggled ? absScale : -absScale; |
| 48 | 35 | | toggleButtonIcon.localScale = new Vector3(toggleButtonIcon.localScale.x, scale, 1f); |
| 48 | 36 | | Utils.ForceRebuildLayoutImmediate(containerRectTransform); |
| 48 | 37 | | model.isToggled = toggled; |
| 48 | 38 | | } |
| | 39 | |
|
| | 40 | | private void Toggle() |
| | 41 | | { |
| 0 | 42 | | Toggle(!containerRectTransform.gameObject.activeSelf); |
| 0 | 43 | | } |
| | 44 | | } |
| | 45 | | } |