Skip to content

Instantly share code, notes, and snippets.

@oddbear
Created November 29, 2016 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oddbear/903b9c30aecc1e7067b9dfd709038cdb to your computer and use it in GitHub Desktop.
Save oddbear/903b9c30aecc1e7067b9dfd709038cdb to your computer and use it in GitHub Desktop.
Some bugs in Xamarin Forms 2.3.3
public class ListViewPage : ContentPage
{
//Tree bugs (iOS):
//1. Important. If spinner is running, and you press the Entry, then the listview will get unaligned.
// to reproduce. Just start the project, click the entry, and then click the Refresh button.
//2. If changeExecute is changed while running, it will kill the spinner.
// to reproduce use pull to refresh, and se that the spinner disapairs before the list is updated.
//3. If can execute returns false, the spinner will start, but the command will never execute.
// to reproduce, just uncomment "_canExecute = true;" and do a pull to refresh.
readonly ListView _listView;
private bool? _canExecute;
readonly Command _refreshCommand;
public ListViewPage()
{
this.Padding = new Thickness(0, 20, 0, 0);
_canExecute = true; //Start bug 3 if commented out, and starts bug 2 if not.
_refreshCommand = new Command(RefreshCommandLogic, () => _canExecute ?? false);
_listView = new ListView
{
HeaderTemplate = new DataTemplate(() => {
return new StackLayout { Children = { new Label { Text = "Test 456" } } };
}),
Header = new StackLayout { Children = { new Label { Text = "Test 123" } } },
IsPullToRefreshEnabled = true,
IsRefreshing = true,
RefreshCommand = _refreshCommand,
ItemsSource = new string[0]
};
_listView.PropertyChanged += (sender, e) => {
if (e.PropertyName == nameof(ListView.ItemsSource))
_listView.IsRefreshing = false;
};
Content = new StackLayout
{
Children = {
new Button { Text = "ClearView", Command = new Command(() => Application.Current.MainPage = new ListViewPage()) },
new Entry { Placeholder = "TestTExt" },
new Button { Text = "Toggle", Command = new Command(() => _listView.IsRefreshing = !_listView.IsRefreshing) },
new Button { Text = "Refresh", Command = new Command(() => {
_listView.IsRefreshing = true;
RefreshCommandLogic();
})
},
new Grid {
RowDefinitions = {
new RowDefinition { Height = 300 }
},
Children = {
_listView
}
}
}
};
}
private async void RefreshCommandLogic()
{
_listView.IsRefreshing = true;
//Will kill spinner early:
//It is a bug, but is this the correct way of using this? Should be => parameter == something, yes/no.
//However, it will start the spinner, but not execute the command.
if (_canExecute != null)
{
_canExecute = false;
_refreshCommand.ChangeCanExecute();
}
await Task.Delay(2000);
_listView.ItemsSource = Enumerable.Range(0, 1)
.Select(i => Guid.NewGuid().ToString("N"))
.ToArray();
if (_canExecute != null)
{
_canExecute = true;
_refreshCommand.ChangeCanExecute();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment