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

@ -23,8 +23,7 @@ namespace Pixiview.Illust
}
public abstract class IllustCollectionPage<T> : 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)

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

@ -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++)