fix: scroll back to top issue on Android

optimize: collection invalidated logic
This commit is contained in:
Tsanie Lily 2020-05-16 23:13:45 +08:00
parent e751185207
commit 64223b99af
7 changed files with 27 additions and 20 deletions

View File

@ -80,7 +80,7 @@ namespace Pixiview.Illust
{
return;
}
await scrollView.ScrollToAsync(0, -topOffset, true);
await ScrollToTopAsync(scrollView);
flag = false;
lastUpdated = default;
StartLoad(true);

View File

@ -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(() =>

View File

@ -59,7 +59,7 @@ namespace Pixiview.Illust
{
return;
}
await scrollView.ScrollToAsync(0, -topOffset, true);
await ScrollToTopAsync(scrollView);
StartLoad(true);
}

View File

@ -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;
}
}

View File

@ -343,7 +343,7 @@ namespace Pixiview.Illust
{
return;
}
await scrollView.ScrollToAsync(0, -topOffset, true);
await ScrollToTopAsync(scrollView);
StartLoad(true);
}
}

View File

@ -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;

View File

@ -107,7 +107,7 @@ namespace Pixiview.Illust
{
return;
}
await scrollView.ScrollToAsync(0, -topOffset, true);
await ScrollToTopAsync(scrollView);
// release
var collection = IllustCollection;
if (collection != null)