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; diff --git a/README.md b/README.md index 37052f8..b4a1f4a 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,10 @@ MIT ## Author [kiepng](https://github.com/kiepng) +## Improver +[AFRA](https://github.com/afraism) + +## improvements +1. Remove `LateUpdate()` which optimized performance +2. Replacing `LateUpdate()` with a new approach that has solved the refresh stock problem. +