1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-24 11:55:38 +01:00

run on main thread fixes

This commit is contained in:
kspearrin 2018-09-24 15:45:36 -04:00
parent f394eddc01
commit 44fe5af4fb

View File

@ -174,26 +174,30 @@ namespace Bit.iOS.Autofill
public override void TextChanged(UISearchBar searchBar, string searchText)
{
var cts = new CancellationTokenSource();
Task.Run(async () =>
Task.Run(() =>
{
if(!string.IsNullOrWhiteSpace(searchText))
NSRunLoop.Main.BeginInvokeOnMainThread(async () =>
{
await Task.Delay(300);
if(searchText != searchBar.Text)
if (!string.IsNullOrWhiteSpace(searchText))
{
return;
await Task.Delay(300);
if (searchText != searchBar.Text)
{
return;
}
else
{
_filterResultsCancellationTokenSource?.Cancel();
}
}
else
try
{
_filterResultsCancellationTokenSource?.Cancel();
((TableSource)_controller.TableView.Source).FilterResults(searchText, cts.Token);
_controller.TableView.ReloadData();
}
}
try
{
((TableSource)_controller.TableView.Source).FilterResults(searchText, cts.Token);
_controller.TableView.ReloadData();
}
catch(OperationCanceledException) { }
catch (OperationCanceledException) { }
_filterResultsCancellationTokenSource = cts;
});
}, cts.Token);
}
}