Pass fetch more action in via ctor to avoid potential nullref

This commit is contained in:
Dean Herbert 2021-05-26 22:49:39 +09:00
parent 9947867e84
commit 735e7b9c74
2 changed files with 10 additions and 5 deletions

View File

@ -19,11 +19,18 @@ namespace osu.Game.Overlays.News.Displays
/// </summary> /// </summary>
public class ArticleListing : CompositeDrawable public class ArticleListing : CompositeDrawable
{ {
public Action RequestMorePosts; private readonly Action fetchMorePosts;
private FillFlowContainer content; private FillFlowContainer content;
private ShowMoreButton showMore; private ShowMoreButton showMore;
private CancellationTokenSource cancellationToken;
public ArticleListing(Action fetchMorePosts)
{
this.fetchMorePosts = fetchMorePosts;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
@ -59,7 +66,7 @@ namespace osu.Game.Overlays.News.Displays
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Margin = new MarginPadding { Top = 15 }, Margin = new MarginPadding { Top = 15 },
Action = RequestMorePosts, Action = fetchMorePosts,
Alpha = 0 Alpha = 0
} }
} }
@ -75,8 +82,6 @@ namespace osu.Game.Overlays.News.Displays
}, (cancellationToken = new CancellationTokenSource()).Token) }, (cancellationToken = new CancellationTokenSource()).Token)
); );
private CancellationTokenSource cancellationToken;
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
cancellationToken?.Cancel(); cancellationToken?.Cancel();

View File

@ -152,7 +152,7 @@ namespace osu.Game.Overlays
lastCursor = response.Cursor; lastCursor = response.Cursor;
sidebar.Metadata.Value = response.SidebarMetadata; sidebar.Metadata.Value = response.SidebarMetadata;
var listing = new ArticleListing { RequestMorePosts = getMorePosts }; var listing = new ArticleListing(getMorePosts);
listing.AddPosts(response.NewsPosts, response.Cursor != null); listing.AddPosts(response.NewsPosts, response.Cursor != null);
LoadDisplay(listing); LoadDisplay(listing);
}); });