Skip to content

Commit

Permalink
Scrap QueueVC autoreload on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Sep 19, 2023
1 parent 817b08b commit 50ef395
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Sources/Stylophone.iOS/ViewControllers/QueueViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ private void ScrollToPlayingSong(object sender = null, SongChangedEventArgs e =
// Scroll to currently playing song
var playing = ViewModel.Source.Where(t => t.IsPlaying).FirstOrDefault();

if (playing != null)
UIApplication.SharedApplication.BeginInvokeOnMainThread(() =>
if (playing == null)
return;

UIApplication.SharedApplication.BeginInvokeOnMainThread(() =>
{
try
{
var indexPath = NSIndexPath.FromRowSection(ViewModel.Source.IndexOf(playing), 0);
var tableViewRows = TableView.NumberOfRowsInSection(0);
if (tableViewRows >= indexPath.Row)
TableView.ScrollToRow(indexPath, UITableViewScrollPosition.Middle, true);
}
catch (Exception e)
{
try
{
var indexPath = NSIndexPath.FromRowSection(ViewModel.Source.IndexOf(playing), 0);
var tableViewRows = TableView.NumberOfRowsInSection(0);
if (tableViewRows >= indexPath.Row)
TableView.ScrollToRow(indexPath, UITableViewScrollPosition.Middle, true);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine($"Error while scrolling to row: {e}");
}
});
else // inconsistency, reload source wholesale
ViewModel.LoadInitialDataAsync();
System.Diagnostics.Debug.WriteLine($"Error while scrolling to row: {e}");
}
});
}

private UIMenu GetRowContextMenu(NSIndexPath indexPath)
Expand Down

0 comments on commit 50ef395

Please sign in to comment.