fix: Android/iOS scrolling UI adjustment

This commit is contained in:
Tsanie Lily 2020-05-16 19:04:07 +08:00
parent 7b8a32d600
commit 2cdfe70429
3 changed files with 81 additions and 64 deletions

View File

@ -23,8 +23,7 @@ namespace Pixiview.Illust
} }
public abstract class IllustCollectionPage<T> : AdaptedPage, IIllustCollectionPage public abstract class IllustCollectionPage<T> : AdaptedPage, IIllustCollectionPage
{ {
protected static readonly Thickness normalMargin = new Thickness(16); protected const double loadingOffset = -40;
protected static readonly Thickness loadingMargin = new Thickness(16, 46, 0, 0);
#region - Properties - #region - Properties -
@ -94,7 +93,7 @@ namespace Pixiview.Illust
public override void OnUnload() public override void OnUnload()
{ {
Illusts = IllustCollection.Empty; Illusts = null;
lastUpdated = default; lastUpdated = default;
} }
@ -179,41 +178,10 @@ namespace Pixiview.Illust
var page = new ViewIllustPage(illust, IsFavoriteVisible); var page = new ViewIllustPage(illust, IsFavoriteVisible);
Navigation.PushAsync(page); Navigation.PushAsync(page);
} }
protected virtual void DoIllustsLoaded(IllustCollection collection, bool bottom) protected virtual IllustCollection GetIllustsLoadedCollection(IllustCollection collection, bool bottom)
{ {
IllustCollection = collection; IllustCollection = collection;
var indicator = LoadingIndicator; return collection;
if (indicator == null)
{
Illusts = collection;
IsLoading = false;
IsBottomLoading = false;
}
else
{
var offset = 16 - IndicatorMarginTop;
indicator.Animate("margin", top =>
{
indicator.Margin = new Thickness(0, top, 0, offset);
},
16 - offset, -40 - offset, easing: Easing.CubicIn, finished: (v, r) =>
{
IsLoading = false;
IsBottomLoading = false;
if (IsDelayLoading)
{
Device.StartTimer(TimeSpan.FromMilliseconds(250), () =>
{
Illusts = collection;
return false;
});
}
else
{
Illusts = collection;
}
});
}
} }
protected virtual void StartLoad(bool force = false, bool isBottom = false) protected virtual void StartLoad(bool force = false, bool isBottom = false)
@ -233,16 +201,20 @@ namespace Pixiview.Illust
{ {
IsLoading = true; IsLoading = true;
} }
Device.StartTimer(TimeSpan.FromMilliseconds(250), () => #if __IOS__
Task.Run(() => DoLoadIllusts(force, isBottom));
#else
Device.StartTimer(TimeSpan.FromMilliseconds(150), () =>
{ {
Task.Run(() => DoLoadIllusts(force, isBottom)); Task.Run(() => DoLoadIllusts(force, isBottom));
return false; return false;
}); });
#endif
} }
else else
{ {
var offset = 16 - IndicatorMarginTop; var offset = 16 - IndicatorMarginTop;
indicator.Margin = new Thickness(0, -40 - offset, 0, offset); indicator.Margin = new Thickness(0, loadingOffset - offset, 0, offset);
if (isBottom) if (isBottom)
{ {
IsBottomLoading = true; IsBottomLoading = true;
@ -255,7 +227,7 @@ namespace Pixiview.Illust
{ {
indicator.Margin = new Thickness(0, top, 0, offset); indicator.Margin = new Thickness(0, top, 0, offset);
}, },
-40 - offset, 16 - offset, easing: Easing.CubicOut, finished: (v, r) => loadingOffset - offset, 16 - offset, easing: Easing.CubicOut, finished: (v, r) =>
{ {
Task.Run(() => DoLoadIllusts(force, isBottom)); Task.Run(() => DoLoadIllusts(force, isBottom));
}); });
@ -263,6 +235,52 @@ namespace Pixiview.Illust
} }
} }
protected virtual void DoIllustsLoaded(IllustCollection collection, bool bottom)
{
collection = GetIllustsLoadedCollection(collection, bottom);
var indicator = LoadingIndicator;
if (indicator == null || bottom)
{
Illusts = collection;
IsLoading = false;
IsBottomLoading = false;
}
else
{
var offset = 16 - IndicatorMarginTop;
indicator.Animate("margin", top =>
{
indicator.Margin = new Thickness(0, top, 0, offset);
},
16 - offset, loadingOffset - offset, easing: Easing.CubicIn, finished: (v, r) =>
{
IsLoading = false;
IsBottomLoading = false;
#if __IOS__
if (IsDelayLoading)
{
Device.StartTimer(TimeSpan.FromMilliseconds(250), () =>
{
Illusts = collection;
return false;
});
}
else
{
Illusts = collection;
}
#else
Device.StartTimer(TimeSpan.FromMilliseconds(150), () =>
{
Illusts = collection;
return false;
});
#endif
});
}
}
protected DataTemplate GetCardViewTemplate(bool hideUser = false) protected DataTemplate GetCardViewTemplate(bool hideUser = false)
{ {
return new DataTemplate(() => return new DataTemplate(() =>
@ -589,7 +607,7 @@ namespace Pixiview.Illust
base.StartLoad(force, isBottom); base.StartLoad(force, isBottom);
} }
protected override void DoIllustsLoaded(IllustCollection collection, bool bottom) protected override IllustCollection GetIllustsLoadedCollection(IllustCollection collection, bool bottom)
{ {
var now = IllustCollection; var now = IllustCollection;
if (now == null) if (now == null)
@ -600,29 +618,7 @@ namespace Pixiview.Illust
{ {
now = new IllustCollection(now.Concat(collection)); now = new IllustCollection(now.Concat(collection));
} }
IllustCollection = now; return now;
var indicator = LoadingIndicator;
if (indicator == null)
{
Illusts = now;
IsLoading = false;
IsBottomLoading = false;
}
else
{
var offset = 16 - IndicatorMarginTop;
indicator.Animate("margin", top =>
{
indicator.Margin = new Thickness(0, top, 0, offset);
},
16 - offset, -40 - offset, easing: Easing.CubicIn, finished: (v, r) =>
{
IsLoading = false;
IsBottomLoading = false;
Illusts = now;
});
}
} }
protected void OnScrolled(double y) protected void OnScrolled(double y)

View File

@ -49,6 +49,12 @@ namespace Pixiview.Illust
protected override ActivityIndicator LoadingIndicator => activityLoading; protected override ActivityIndicator LoadingIndicator => activityLoading;
public override void OnUnload()
{
base.OnUnload();
Users = null;
}
private void OnIllustUserItemTapped(IllustUserItem item) private void OnIllustUserItemTapped(IllustUserItem item)
{ {
Start(async () => Start(async () =>
@ -279,8 +285,17 @@ namespace Pixiview.Illust
{ {
IsLoading = false; IsLoading = false;
UserRecommendsVisible = list.Count > 0; UserRecommendsVisible = list.Count > 0;
#if __IOS__
Users = list; Users = list;
Illusts = IllustCollection; Illusts = IllustCollection;
#else
Device.StartTimer(TimeSpan.FromMilliseconds(150), () =>
{
Users = list;
Illusts = IllustCollection;
return false;
});
#endif
}); });
DoLoadUserRecommendsImages(list); DoLoadUserRecommendsImages(list);

View File

@ -140,7 +140,13 @@ namespace Pixiview.UI
{ {
oldNotify.CollectionChanged -= flowLayout.OnCollectionChanged; oldNotify.CollectionChanged -= flowLayout.OnCollectionChanged;
} }
if (newValue is IList newList) if (newValue == null)
{
flowLayout.Children.Clear();
//flowLayout.UpdateChildrenLayout();
//flowLayout.InvalidateLayout();
}
else if (newValue is IList newList)
{ {
flowLayout.Children.Clear(); flowLayout.Children.Clear();
for (var i = 0; i < newList.Count; i++) for (var i = 0; i < newList.Count; i++)