maui-linux/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issu.../Issue2411.cs

316 строки
8.6 KiB
C#
Исходник Обычный вид История

2016-03-22 23:02:25 +03:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
2016-03-22 23:02:25 +03:00
#if UITEST
using NUnit.Framework;
using Xamarin.UITest;
#endif
namespace Xamarin.Forms.Controls.Issues
2016-03-22 23:02:25 +03:00
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 2411, "ListView.ScrollTo not working in TabbedPage", PlatformAffected.Android)]
2016-03-22 23:02:25 +03:00
public class Issue2411 : TestTabbedPage
{
protected override void Init()
2016-03-22 23:02:25 +03:00
{
Children.Add(new XamarinListViewScrollToBugPage1());
Children.Add(new XamarinListViewScrollToBugPage2());
Children.Add(new XamarinListViewScrollToBugPage3());
2016-03-22 23:02:25 +03:00
}
#if UITEST
[Test]
#if __ANDROID__
[Ignore("Appearing event is tied to virtualization in TabbedPage for Material")]
2016-03-22 23:02:25 +03:00
#endif
[Issue(IssueTracker.Github, 2411, "ScrollToPosition.MakeVisible not called every time TabbedPage", PlatformAffected.Android)]
public void Issue2411ScrollToPositionMakeVisible()
2016-03-22 23:02:25 +03:00
{
RunningApp.WaitForElement(q => q.Marked("99 99 99 99 99 99"));
RunningApp.Screenshot("ScrollTo working correctly");
RunningApp.Tap(q => q.Marked("Crash in ScrollToPosition.End"));
RunningApp.Screenshot("On Second Tab");
RunningApp.WaitForElement(q => q.Marked("2 0 0 0 0 0 0"));
RunningApp.Tap(q => q.Marked("Scroll To in OnAppearing"));
RunningApp.Screenshot("On First Tab");
RunningApp.WaitForElement(q => q.Marked("99 99 99 99 99 99"));
var listViewBound = RunningApp.Query(q => q.Marked("listView"))[0].Rect;
Xamarin.Forms.Core.UITests.Gestures.ScrollForElement(RunningApp, "* marked:'0 0 0 0 0 0'", new Xamarin.Forms.Core.UITests.Drag(listViewBound, Xamarin.Forms.Core.UITests.Drag.Direction.TopToBottom, Xamarin.Forms.Core.UITests.Drag.DragLength.Long));
RunningApp.Screenshot("Scrolled to Top");
RunningApp.Tap(q => q.Marked("Crash in ScrollToPosition.End"));
RunningApp.Screenshot("On Second Tab");
RunningApp.WaitForElement(q => q.Marked("2 0 0 0 0 0 0"));
RunningApp.Tap(q => q.Marked("Scroll To in OnAppearing"));
RunningApp.Screenshot("On First Tab");
RunningApp.WaitForElement(q => q.Marked("99 99 99 99 99 99"));
2016-03-22 23:02:25 +03:00
}
[Test]
[Issue(IssueTracker.Github, 2411, "ScrollToPosition.End crashing in TabbedPage", PlatformAffected.Android)]
public void Issue2411ScrollToPositionEndCrash()
2016-03-22 23:02:25 +03:00
{
RunningApp.Tap(q => q.Marked("Crash in ScrollToPosition.End"));
RunningApp.Screenshot("On Second Tab");
RunningApp.Tap(q => q.Marked("Scroll To in OnAppearing"));
RunningApp.Screenshot("On First Tab");
RunningApp.Tap(q => q.Marked("Crash in ScrollToPosition.End"));
RunningApp.Screenshot("On Second Tab Again");
RunningApp.Tap(q => q.Marked("ScrollToPosition.End End - Not animated"));
RunningApp.WaitForElement(q => q.Marked("2 99 99 99 99 99 99"));
2016-03-22 23:02:25 +03:00
}
[Test]
[Issue(IssueTracker.Github, 2411, "ScrollToPositon.End crashing in TabbedPage", PlatformAffected.Android)]
public void Issue2411ScrollToPositionWrongOnUneven()
2016-03-22 23:02:25 +03:00
{
RunningApp.Tap(q => q.Marked("Crash in ScrollToPosition.End"));
RunningApp.Tap(q => q.Marked("Scroll To in OnAppearing Uneven"));
var dontRun = RunningApp.Query(q => q.Marked(XamarinListViewScrollToBugPage3.DontRun));
if (dontRun.Length > 0)
Assert.Inconclusive("Ignored on iOS < 9 until Bugzilla 28277 is resolved.");
RunningApp.Screenshot("On Third Tab");
RunningApp.WaitForElement(q => q.Marked("99 99 99 99 99 99"));
2016-03-22 23:02:25 +03:00
}
#endif
}
[Preserve(AllMembers = true)]
2016-03-22 23:02:25 +03:00
internal class ListObj
{
public string Name { get; set; }
}
[Preserve(AllMembers = true)]
2016-03-22 23:02:25 +03:00
public class CellTemplateScrollTo : ViewCell
{
public CellTemplateScrollTo()
2016-03-22 23:02:25 +03:00
{
Label cellLabel = new Label()
{
2016-03-22 23:02:25 +03:00
HorizontalOptions = LayoutOptions.FillAndExpand,
};
cellLabel.SetBinding(Label.TextProperty, new Binding("Name", BindingMode.OneWay));
2016-03-22 23:02:25 +03:00
StackLayout root = new StackLayout()
{
2016-03-22 23:02:25 +03:00
Children = {
cellLabel
}
};
View = root;
}
}
[Preserve(AllMembers = true)]
2016-03-22 23:02:25 +03:00
public class CellTemplateScrollToUneven : CellTemplateScrollTo
{
public CellTemplateScrollToUneven()
2016-03-22 23:02:25 +03:00
{
Height = 60 + new Random().Next(10, 100);
}
}
[Preserve(AllMembers = true)]
2016-03-22 23:02:25 +03:00
public class XamarinListViewScrollToBugPage1 : ContentPage
{
ListView _listView;
ObservableCollection<ListObj> _collection = new ObservableCollection<ListObj>();
2016-03-22 23:02:25 +03:00
public XamarinListViewScrollToBugPage1()
2016-03-22 23:02:25 +03:00
{
Title = "Scroll To in OnAppearing";
for (int i = 0; i < 100; i++)
{
var item = new ListObj { Name = string.Format("{0} {0} {0} {0} {0} {0}", i) };
_collection.Add(item);
2016-03-22 23:02:25 +03:00
}
_listView = new ListView
{
2016-03-22 23:02:25 +03:00
ItemsSource = _collection,
ItemTemplate = new DataTemplate(typeof(CellTemplateScrollTo))
2016-03-22 23:02:25 +03:00
};
_listView.AutomationId = "listView";
Content = new StackLayout
{
2016-03-22 23:02:25 +03:00
Children = {
_listView
}
};
}
protected override void OnAppearing()
2016-03-22 23:02:25 +03:00
{
base.OnAppearing();
_listView.ScrollTo(_collection.Last(), ScrollToPosition.MakeVisible, false);
2016-03-22 23:02:25 +03:00
}
}
[Preserve(AllMembers = true)]
2016-03-22 23:02:25 +03:00
public class XamarinListViewScrollToBugPage2 : ContentPage
{
ListView _listView;
ObservableCollection<ListObj> _collection = new ObservableCollection<ListObj>();
2016-03-22 23:02:25 +03:00
public XamarinListViewScrollToBugPage2()
2016-03-22 23:02:25 +03:00
{
Title = "Crash in ScrollToPosition.End";
for (int i = 0; i < 100; i++)
{
var item = new ListObj { Name = string.Format("2 {0} {0} {0} {0} {0} {0}", i) };
_collection.Add(item);
2016-03-22 23:02:25 +03:00
}
_listView = new ListView
{
2016-03-22 23:02:25 +03:00
ItemsSource = _collection,
ItemTemplate = new DataTemplate(typeof(CellTemplateScrollTo))
2016-03-22 23:02:25 +03:00
};
var endButton = new Button
{
2016-03-22 23:02:25 +03:00
Text = "ScrollToPosition.End End - Not animated",
Command = new Command(() =>
{
_listView.ScrollTo(_collection.Last(), ScrollToPosition.End, false);
2016-03-22 23:02:25 +03:00
})
};
var endButtonAnimated = new Button
{
2016-03-22 23:02:25 +03:00
Text = "ScrollToPosition.MakeVisible End - Animated",
Command = new Command(() =>
{
_listView.ScrollTo(_collection.Last(), ScrollToPosition.MakeVisible, true);
2016-03-22 23:02:25 +03:00
})
};
Content = new StackLayout
{
2016-03-22 23:02:25 +03:00
Children = {
endButton,
endButtonAnimated,
_listView
}
};
}
}
public class XamarinListViewScrollToBugPage3 : ContentPage
{
ListView _listView;
ObservableCollection<ListObj> _collection = new ObservableCollection<ListObj>();
int _i = 0;
public const string DontRun = "Don't run";
public XamarinListViewScrollToBugPage3()
2016-03-22 23:02:25 +03:00
{
Title = "Scroll To in OnAppearing Uneven";
bool runTest = true;
// This test will fail in iOS < 9 because using ScrollTo with UnevenRows with estimation is currently not working.
// It did not previously fail because this test used `TakePerformanceHit` to turn off row estimation. However, as
// that was never a public feature, it was never a valid fix for the test.
// https://bugzilla.xamarin.com/show_bug.cgi?id=28277
#if !UITEST
if (App.IOSVersion < 9)
runTest = false;
#endif
if (!runTest)
_collection.Add(new ListObj { Name = DontRun });
else
{
for (_i = 0; _i < 100; _i++)
{
var item = new ListObj { Name = string.Format("{0} {0} {0} {0} {0} {0}", _i) };
_collection.Add(item);
}
2016-03-22 23:02:25 +03:00
}
var btnAdd = new Button
{
2016-03-22 23:02:25 +03:00
Text = "Add item",
WidthRequest = 100
};
btnAdd.Clicked += BtnAddOnClicked;
var btnBottom = new Button
{
2016-03-22 23:02:25 +03:00
Text = "Scroll to end",
WidthRequest = 100
};
btnBottom.Clicked += BtnBottomOnClicked;
var btnPanel = new StackLayout
{
2016-03-22 23:02:25 +03:00
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.Center,
Children = {
btnAdd,
btnBottom
}
};
_listView = new ListView
{
2016-03-22 23:02:25 +03:00
ItemsSource = _collection,
BackgroundColor = Color.Transparent,
VerticalOptions = LayoutOptions.FillAndExpand,
HasUnevenRows = true,
ItemTemplate = new DataTemplate(typeof(CellTemplateScrollToUneven))
2016-03-22 23:02:25 +03:00
};
_listView.ItemTapped += (sender, e) => ((ListView)sender).SelectedItem = null;
_listView.AutomationId = "listView";
Content = new StackLayout
{
2016-03-22 23:02:25 +03:00
Children = {
btnPanel,
_listView
}
};
}
protected override void OnAppearing()
2016-03-22 23:02:25 +03:00
{
base.OnAppearing();
_listView.ScrollTo(_collection.Last(), ScrollToPosition.MakeVisible, false);
2016-03-22 23:02:25 +03:00
}
void BtnBottomOnClicked(object sender, EventArgs e)
{
var item = _collection.Last();
_listView.ScrollTo(item, ScrollToPosition.End, true);
}
void BtnAddOnClicked(object sender, EventArgs eventArgs)
{
var str = string.Format("Item {0}", _i++);
var item = new ListObj { Name = string.Format("{0} {0} {0} {0} {0} {0}", _i) };
2016-03-22 23:02:25 +03:00
_collection.Add(item);
_listView.ScrollTo(item, ScrollToPosition.End, true);
}
}
}