fix: scroll back to top issue on Android
optimize: collection invalidated logic
This commit is contained in:
		@@ -80,7 +80,7 @@ namespace Pixiview.Illust
 | 
			
		||||
            {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            await scrollView.ScrollToAsync(0, -topOffset, true);
 | 
			
		||||
            await ScrollToTopAsync(scrollView);
 | 
			
		||||
            flag = false;
 | 
			
		||||
            lastUpdated = default;
 | 
			
		||||
            StartLoad(true);
 | 
			
		||||
 
 | 
			
		||||
@@ -185,6 +185,16 @@ namespace Pixiview.Illust
 | 
			
		||||
            return collection;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected void InvalidateCollection()
 | 
			
		||||
        {
 | 
			
		||||
            var collection = IllustCollection;
 | 
			
		||||
            if (collection != null)
 | 
			
		||||
            {
 | 
			
		||||
                collection.Running = false;
 | 
			
		||||
                IllustCollection = null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected virtual void StartLoad(bool force = false, bool isBottom = false)
 | 
			
		||||
        {
 | 
			
		||||
            if (force || lastUpdated != LastUpdated)
 | 
			
		||||
@@ -200,6 +210,7 @@ namespace Pixiview.Illust
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        InvalidateCollection();
 | 
			
		||||
                        IsLoading = true;
 | 
			
		||||
                    }
 | 
			
		||||
#if __IOS__
 | 
			
		||||
@@ -222,6 +233,7 @@ namespace Pixiview.Illust
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        InvalidateCollection();
 | 
			
		||||
                        IsLoading = true;
 | 
			
		||||
                    }
 | 
			
		||||
                    indicator.Animate("margin", top =>
 | 
			
		||||
@@ -282,6 +294,14 @@ namespace Pixiview.Illust
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected async Task ScrollToTopAsync(ScrollView scrollView)
 | 
			
		||||
        {
 | 
			
		||||
            if (scrollView.ScrollY > -topOffset)
 | 
			
		||||
            {
 | 
			
		||||
                await scrollView.ScrollToAsync(0, -topOffset, true);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected DataTemplate GetCardViewTemplate(bool hideUser = false)
 | 
			
		||||
        {
 | 
			
		||||
            return new DataTemplate(() =>
 | 
			
		||||
 
 | 
			
		||||
@@ -59,7 +59,7 @@ namespace Pixiview.Illust
 | 
			
		||||
            {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            await scrollView.ScrollToAsync(0, -topOffset, true);
 | 
			
		||||
            await ScrollToTopAsync(scrollView);
 | 
			
		||||
            StartLoad(true);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -355,9 +355,8 @@ namespace Pixiview.Illust
 | 
			
		||||
 | 
			
		||||
        private async void PrepareLoad()
 | 
			
		||||
        {
 | 
			
		||||
            await scrollView.ScrollToAsync(0, -topOffset, true);
 | 
			
		||||
            await ScrollToTopAsync(scrollView);
 | 
			
		||||
            // release
 | 
			
		||||
            ReleaseCollection();
 | 
			
		||||
            previousEnabled = false;
 | 
			
		||||
            dateEnabled = false;
 | 
			
		||||
            nextEnabled = false;
 | 
			
		||||
@@ -367,12 +366,7 @@ namespace Pixiview.Illust
 | 
			
		||||
 | 
			
		||||
        private void ReleaseCollection()
 | 
			
		||||
        {
 | 
			
		||||
            var collection = IllustCollection;
 | 
			
		||||
            if (collection != null)
 | 
			
		||||
            {
 | 
			
		||||
                collection.Running = false;
 | 
			
		||||
                IllustCollection = null;
 | 
			
		||||
            }
 | 
			
		||||
            InvalidateCollection();
 | 
			
		||||
            currentPage = 1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -343,7 +343,7 @@ namespace Pixiview.Illust
 | 
			
		||||
            {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            await scrollView.ScrollToAsync(0, -topOffset, true);
 | 
			
		||||
            await ScrollToTopAsync(scrollView);
 | 
			
		||||
            StartLoad(true);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -97,14 +97,7 @@ namespace Pixiview.Illust
 | 
			
		||||
            {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            await scrollView.ScrollToAsync(0, -topOffset, true);
 | 
			
		||||
            // release
 | 
			
		||||
            var collection = IllustCollection;
 | 
			
		||||
            if (collection != null)
 | 
			
		||||
            {
 | 
			
		||||
                collection.Running = false;
 | 
			
		||||
                IllustCollection = null;
 | 
			
		||||
            }
 | 
			
		||||
            await ScrollToTopAsync(scrollView);
 | 
			
		||||
            startIndex = -1;
 | 
			
		||||
            nextIndex = 0;
 | 
			
		||||
            illustIds = null;
 | 
			
		||||
 
 | 
			
		||||
@@ -107,7 +107,7 @@ namespace Pixiview.Illust
 | 
			
		||||
            {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            await scrollView.ScrollToAsync(0, -topOffset, true);
 | 
			
		||||
            await ScrollToTopAsync(scrollView);
 | 
			
		||||
            // release
 | 
			
		||||
            var collection = IllustCollection;
 | 
			
		||||
            if (collection != null)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user