From 2cdfe7042947386c14859a79398b458e766a54a8 Mon Sep 17 00:00:00 2001 From: Tsanie Lily Date: Sat, 16 May 2020 19:04:07 +0800 Subject: [PATCH] fix: Android/iOS scrolling UI adjustment --- Pixiview/Illust/IllustCollectionPage.cs | 122 ++++++++++++------------ Pixiview/Illust/RecommendsPage.xaml.cs | 15 +++ Pixiview/UI/FlowLayout.cs | 8 +- 3 files changed, 81 insertions(+), 64 deletions(-) diff --git a/Pixiview/Illust/IllustCollectionPage.cs b/Pixiview/Illust/IllustCollectionPage.cs index 709165f..eb3c309 100644 --- a/Pixiview/Illust/IllustCollectionPage.cs +++ b/Pixiview/Illust/IllustCollectionPage.cs @@ -23,8 +23,7 @@ namespace Pixiview.Illust } public abstract class IllustCollectionPage : AdaptedPage, IIllustCollectionPage { - protected static readonly Thickness normalMargin = new Thickness(16); - protected static readonly Thickness loadingMargin = new Thickness(16, 46, 0, 0); + protected const double loadingOffset = -40; #region - Properties - @@ -94,7 +93,7 @@ namespace Pixiview.Illust public override void OnUnload() { - Illusts = IllustCollection.Empty; + Illusts = null; lastUpdated = default; } @@ -179,41 +178,10 @@ namespace Pixiview.Illust var page = new ViewIllustPage(illust, IsFavoriteVisible); Navigation.PushAsync(page); } - protected virtual void DoIllustsLoaded(IllustCollection collection, bool bottom) + protected virtual IllustCollection GetIllustsLoadedCollection(IllustCollection collection, bool bottom) { IllustCollection = collection; - var indicator = LoadingIndicator; - 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; - } - }); - } + return collection; } protected virtual void StartLoad(bool force = false, bool isBottom = false) @@ -233,16 +201,20 @@ namespace Pixiview.Illust { 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)); return false; }); +#endif } else { var offset = 16 - IndicatorMarginTop; - indicator.Margin = new Thickness(0, -40 - offset, 0, offset); + indicator.Margin = new Thickness(0, loadingOffset - offset, 0, offset); if (isBottom) { IsBottomLoading = true; @@ -255,7 +227,7 @@ namespace Pixiview.Illust { 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)); }); @@ -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) { return new DataTemplate(() => @@ -589,7 +607,7 @@ namespace Pixiview.Illust base.StartLoad(force, isBottom); } - protected override void DoIllustsLoaded(IllustCollection collection, bool bottom) + protected override IllustCollection GetIllustsLoadedCollection(IllustCollection collection, bool bottom) { var now = IllustCollection; if (now == null) @@ -600,29 +618,7 @@ namespace Pixiview.Illust { now = new IllustCollection(now.Concat(collection)); } - IllustCollection = 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; - }); - } + return now; } protected void OnScrolled(double y) diff --git a/Pixiview/Illust/RecommendsPage.xaml.cs b/Pixiview/Illust/RecommendsPage.xaml.cs index 4b1c570..c036078 100644 --- a/Pixiview/Illust/RecommendsPage.xaml.cs +++ b/Pixiview/Illust/RecommendsPage.xaml.cs @@ -49,6 +49,12 @@ namespace Pixiview.Illust protected override ActivityIndicator LoadingIndicator => activityLoading; + public override void OnUnload() + { + base.OnUnload(); + Users = null; + } + private void OnIllustUserItemTapped(IllustUserItem item) { Start(async () => @@ -279,8 +285,17 @@ namespace Pixiview.Illust { IsLoading = false; UserRecommendsVisible = list.Count > 0; +#if __IOS__ Users = list; Illusts = IllustCollection; +#else + Device.StartTimer(TimeSpan.FromMilliseconds(150), () => + { + Users = list; + Illusts = IllustCollection; + return false; + }); +#endif }); DoLoadUserRecommendsImages(list); diff --git a/Pixiview/UI/FlowLayout.cs b/Pixiview/UI/FlowLayout.cs index 23b55e8..943acb8 100644 --- a/Pixiview/UI/FlowLayout.cs +++ b/Pixiview/UI/FlowLayout.cs @@ -140,7 +140,13 @@ namespace Pixiview.UI { 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(); for (var i = 0; i < newList.Count; i++)