From b0c01a1e1b3b1bc6c3c5f04c1a7f8fdeab51beea Mon Sep 17 00:00:00 2001 From: AFRA Date: Sun, 6 Jun 2021 11:15:33 +0430 Subject: [PATCH] Update UIRefreshControl.cs Fix some issues and performance improvement. --- .../PullToRefresh/Scripts/UIRefreshControl.cs | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/Assets/PullToRefresh/Scripts/UIRefreshControl.cs b/Assets/PullToRefresh/Scripts/UIRefreshControl.cs index 2e3ba74..61cf14b 100644 --- a/Assets/PullToRefresh/Scripts/UIRefreshControl.cs +++ b/Assets/PullToRefresh/Scripts/UIRefreshControl.cs @@ -1,4 +1,4 @@ -using System; +using System; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; @@ -30,7 +30,7 @@ namespace PullToRefresh { public class UIRefreshControl : MonoBehaviour { - [Serializable] public class RefreshControlEvent : UnityEvent {} + [Serializable] public class RefreshControlEvent : UnityEvent { } [SerializeField] private ScrollRect m_ScrollRect; [SerializeField] private float m_PullDistanceRequiredRefresh = 150f; @@ -70,11 +70,12 @@ public RefreshControlEvent OnRefresh set { m_OnRefresh = value; } } - /// + /// /// Call When Refresh is End. /// public void EndRefreshing() { + m_ScrollRect.vertical = true; m_IsPulled = false; m_IsRefreshing = false; m_LoadingAnimator.SetBool(_activityIndicatorStartLoadingName, false); @@ -90,21 +91,6 @@ private void Start() m_ScrollRect.onValueChanged.AddListener(OnScroll); } - private void LateUpdate() - { - if (!m_IsPulled) - { - return; - } - - if (!m_IsRefreshing) - { - return; - } - - m_ScrollRect.content.anchoredPosition = m_PositionStop; - } - private void OnScroll(Vector2 normalizedPosition) { var distance = m_InitialPosition - GetContentAnchoredPosition(); @@ -143,11 +129,13 @@ private void OnPull(float distance) m_LoadingAnimator.SetBool(_activityIndicatorStartLoadingName, true); } - // ドラッグした状態で必要距離に達したあとに、指を離したらリフレッシュ開始 if (m_IsPulled && !m_ScrollView.Dragging) { + m_ScrollRect.vertical = false; + m_ScrollRect.content.anchoredPosition = m_PositionStop; m_IsRefreshing = true; m_OnRefresh.Invoke(); + m_IsPulled = false; } m_Progress = 0f;