| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace DCL.Builder |
| | 7 | | { |
| | 8 | | public class SearchLandView : BaseComponentView |
| | 9 | | { |
| | 10 | | public event Action<string> OnValueSearch; |
| | 11 | | public event Action OnSearchCanceled; |
| | 12 | |
|
| | 13 | | [SerializeField] private TMP_InputField inputField; |
| | 14 | | [SerializeField] private Button cancelSearchButton; |
| | 15 | | [SerializeField] private PublishLandListView publishLandListView; |
| | 16 | |
|
| 0 | 17 | | public override void RefreshControl() { } |
| | 18 | |
|
| | 19 | | public override void Start() |
| | 20 | | { |
| 0 | 21 | | base.Start(); |
| 0 | 22 | | inputField.onValueChanged.AddListener(InputChanged); |
| 0 | 23 | | cancelSearchButton.onClick.AddListener(ClearSearch); |
| 0 | 24 | | } |
| | 25 | |
|
| | 26 | | public override void Dispose() |
| | 27 | | { |
| 0 | 28 | | base.Dispose(); |
| 0 | 29 | | inputField.onValueChanged.RemoveAllListeners(); |
| 0 | 30 | | } |
| | 31 | |
|
| | 32 | | public void ClearSearch() |
| | 33 | | { |
| 0 | 34 | | inputField.SetTextWithoutNotify(""); |
| 0 | 35 | | cancelSearchButton.gameObject.SetActive(false); |
| 0 | 36 | | OnSearchCanceled?.Invoke(); |
| 0 | 37 | | } |
| | 38 | |
|
| | 39 | | internal void InputChanged(string newValue) |
| | 40 | | { |
| 0 | 41 | | if (string.IsNullOrEmpty(newValue) || newValue.Length == 0) |
| | 42 | | { |
| 0 | 43 | | cancelSearchButton.gameObject.SetActive(false); |
| 0 | 44 | | publishLandListView.HideEmptyContent(); |
| 0 | 45 | | return; |
| | 46 | | } |
| | 47 | |
|
| 0 | 48 | | if(newValue.Length < 2) |
| 0 | 49 | | return; |
| | 50 | |
|
| 0 | 51 | | cancelSearchButton.gameObject.SetActive(true); |
| 0 | 52 | | OnValueSearch?.Invoke(newValue); |
| 0 | 53 | | } |
| | 54 | | } |
| | 55 | | } |