This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow item source updates while CollectionView is hidden; prevent
CollectionView updates while CollectionView is hidden; fixes #13126
- Loading branch information
Showing
6 changed files
with
175 additions
and
40 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13126.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Globalization; | ||
using System.Text; | ||
using Xamarin.Forms.CustomAttributes; | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Issue(IssueTracker.Github, 13126, "[Bug] Regression: 5.0.0-pre5 often fails to draw dynamically loaded collection view content", PlatformAffected.iOS)] | ||
|
||
public class Issue13126 : TestContentPage | ||
{ | ||
_13126VM _vm; | ||
const string Success1 = "Success1"; | ||
|
||
protected override void Init() | ||
{ | ||
_vm = new _13126VM(); | ||
BindingContext = _vm; | ||
|
||
var cv1 = BindingWithConverter(); | ||
|
||
var grid = new Grid | ||
{ | ||
RowDefinitions = new RowDefinitionCollection | ||
{ | ||
new RowDefinition() { Height = GridLength.Star }, | ||
} | ||
}; | ||
|
||
grid.Children.Add(cv1); | ||
|
||
Content = grid; | ||
|
||
_vm.IsBusy = true; | ||
|
||
Device.StartTimer(TimeSpan.FromMilliseconds(300), () => | ||
{ | ||
Device.BeginInvokeOnMainThread(() => | ||
{ | ||
_vm.Data.Add(Success1); | ||
_vm.IsBusy = false; | ||
}); | ||
return false; | ||
}); | ||
} | ||
|
||
CollectionView BindingWithConverter() | ||
{ | ||
var cv = new CollectionView | ||
{ | ||
IsVisible = true, | ||
|
||
ItemTemplate = new DataTemplate(() => | ||
{ | ||
var label = new Label(); | ||
label.SetBinding(Label.TextProperty, new Binding(".")); | ||
return label; | ||
}) | ||
}; | ||
|
||
cv.SetBinding(CollectionView.ItemsSourceProperty, new Binding("Data")); | ||
cv.SetBinding(VisualElement.IsVisibleProperty, new Binding("IsBusy", converter: new BoolInverter())); | ||
|
||
return cv; | ||
} | ||
|
||
class BoolInverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return !((bool)value); | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
|
||
class _13126VM : INotifyPropertyChanged | ||
{ | ||
private bool _isBusy; | ||
|
||
public bool IsBusy | ||
{ | ||
get | ||
{ | ||
return _isBusy; | ||
} | ||
|
||
set | ||
{ | ||
_isBusy = value; | ||
OnPropertyChanged(nameof(IsBusy)); | ||
} | ||
} | ||
|
||
public ObservableCollection<string> Data { get; } = new ObservableCollection<string>(); | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
void OnPropertyChanged(string name) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters