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.
* keep track of created ConditionalFocusLayout's so they can all be disposed of
- Loading branch information
Showing
6 changed files
with
227 additions
and
21 deletions.
There are no files selected for viewing
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
15 changes: 15 additions & 0 deletions
15
....Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Effects/AttachedStateEffectLabel.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,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Xamarin.Forms.Internals; | ||
|
||
namespace Xamarin.Forms.Controls.Effects | ||
{ | ||
[Preserve(AllMembers = true)] | ||
public class AttachedStateEffectLabel : Label | ||
{ | ||
// Android renderers don't detach effects when the renderers get disposed | ||
// so this is a hack setup to detach those effects when testing if dispose is called from a renderer | ||
// https://github.com/xamarin/Xamarin.Forms/issues/2520 | ||
} | ||
} |
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
159 changes: 159 additions & 0 deletions
159
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2829.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,159 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using Xamarin.Forms.Controls.Effects; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
#if UITEST | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 2829, "[Android] Renderers associated with ListView cells are occasionaly not being disposed of which causes left over events to propagate to disposed views", | ||
PlatformAffected.Android)] | ||
public class Issue2829 : TestNavigationPage | ||
{ | ||
AttachedStateEffectList attachedStateEffectList = new AttachedStateEffectList(); | ||
const string kScrollMe = "kScrollMe"; | ||
const string kSuccess = "SUCCESS"; | ||
const string kCreateListViewButton = "kCreateListViewButton"; | ||
StackLayout layout = null; | ||
|
||
protected override void Init() | ||
{ | ||
var label = new Label() { Text = "Click the button then click back" }; | ||
|
||
layout = new StackLayout() | ||
{ | ||
Children = | ||
{ | ||
label, | ||
new Button() | ||
{ | ||
AutomationId = kCreateListViewButton, | ||
Text = "Create ListView", | ||
Command = new Command(() => | ||
{ | ||
attachedStateEffectList.ToList().ForEach(x=> attachedStateEffectList.Remove(x)); | ||
label.Text = "FAILURE"; | ||
Navigation.PushAsync(CreateListViewPage()); | ||
}) | ||
} | ||
} | ||
}; | ||
|
||
var page = new ContentPage() | ||
{ | ||
Content = layout | ||
}; | ||
|
||
|
||
PushAsync(page); | ||
attachedStateEffectList.AllEventsDetached += (_, __) => | ||
{ | ||
label.Text = kSuccess; | ||
}; | ||
} | ||
|
||
ListView CreateListView() | ||
{ | ||
ListView view = new ListView(ListViewCachingStrategy.RecycleElement); | ||
view.ItemTemplate = new DataTemplate(() => | ||
{ | ||
ViewCell cell = new ViewCell(); | ||
AttachedStateEffectLabel label = new AttachedStateEffectLabel(); | ||
label.TextColor = Color.Black; | ||
label.BackgroundColor = Color.White; | ||
label.SetBinding(Label.TextProperty, "Text"); | ||
attachedStateEffectList.Add(label); | ||
label.BindingContextChanged += (_, __) => | ||
{ | ||
if (label.AutomationId == null) | ||
label.AutomationId = ((Data)label.BindingContext).Text.ToString(); | ||
}; | ||
|
||
cell.View = new ContentView() | ||
{ | ||
Content = new StackLayout() | ||
{ | ||
Orientation = StackOrientation.Horizontal, | ||
Children = | ||
{ | ||
label, | ||
new Image{ Source = "coffee.png"} | ||
} | ||
}, | ||
HeightRequest = 40 | ||
}; | ||
|
||
return cell; | ||
}); | ||
var data = new ObservableCollection<Data>(Enumerable.Range(0, 72).Select(index => new Data() { Text = index.ToString() })); | ||
view.ItemsSource = data; | ||
|
||
return view; | ||
} | ||
|
||
Page CreateListViewPage() | ||
{ | ||
var view = CreateListView(); | ||
var data = view.ItemsSource as ObservableCollection<Data>; | ||
|
||
Button scrollMe = new Button() | ||
{ | ||
Text = "Scroll ListView", | ||
AutomationId = kScrollMe, | ||
Command = new Command(() => | ||
{ | ||
view.ScrollTo(data.Last(), ScrollToPosition.MakeVisible, true); | ||
}) | ||
}; | ||
|
||
return new ContentPage() | ||
{ | ||
Content = new StackLayout() | ||
{ | ||
Children = { scrollMe, view } | ||
} | ||
}; | ||
} | ||
|
||
[Preserve(AllMembers = true)] | ||
public class Data : INotifyPropertyChanged | ||
{ | ||
private string _text; | ||
|
||
public string Text | ||
{ | ||
get => _text; | ||
set | ||
{ | ||
_text = value; | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Text))); | ||
} | ||
} | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
} | ||
|
||
#if UITEST | ||
[Test] | ||
public void ViewCellsAllDisposed() | ||
{ | ||
RunningApp.Tap(kCreateListViewButton); | ||
RunningApp.WaitForElement("0"); | ||
RunningApp.Tap(kScrollMe); | ||
RunningApp.WaitForElement("70"); | ||
RunningApp.Back(); | ||
RunningApp.WaitForElement(kSuccess); | ||
} | ||
#endif | ||
} | ||
} |
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