[Android] Fix ImageSource being set to null and fix ImageCell so it loads images (#4601) fixes #4597 fixes #4584

* [Android] fix imageCell and null ImageSource

* [iOS] fixed ui tests for iOS

* [Android] fix FR UI Tests

* suggested formatting fixes
This commit is contained in:
Shane Neuville 2018-12-04 17:55:00 -07:00 коммит произвёл Rui Marinho
Родитель ab6147a6c1
Коммит db0467a5eb
3 изменённых файлов: 140 добавлений и 4 удалений

Просмотреть файл

@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Linq;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 4597, "[Android] ImageCell not loading images and setting ImageSource to null has no effect",
PlatformAffected.Android)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Image)]
[NUnit.Framework.Category(UITestCategories.ListView)]
#endif
public class Issue4597 : TestContentPage
{
ImageButton _imageButton;
Button _button;
Image _image;
ListView _listView;
string _disappearText = "You should see 4 images. Clicking this should cause the images to all disappear";
string _appearText = "Clicking this should cause the images to all appear";
string _theListView = "theListViewAutomationId";
string _fileName = "coffee";
protected override void Init()
{
_image = new Image() { Source = _fileName, AutomationId = _fileName };
_button = new Button() { Image = _fileName, AutomationId = _fileName };
_imageButton = new ImageButton() { Source = _fileName, AutomationId = _fileName };
_listView = new ListView()
{
ItemTemplate = new DataTemplate(() =>
{
var cell = new ImageCell();
cell.SetBinding(ImageCell.ImageSourceProperty, ".");
return cell;
}),
AutomationId = _theListView,
ItemsSource = new[] { _fileName },
HasUnevenRows = true,
BackgroundColor = Color.Purple
};
Button button = null;
button = new Button()
{
AutomationId = "ClickMe",
Text = _disappearText,
Command = new Command(() =>
{
if (button.Text == _disappearText)
{
_image.Source = null;
_button.Image = null;
_imageButton.Source = null;
_listView.ItemsSource = new string[] { null };
button.Text = _appearText;
}
else
{
_image.Source = _fileName;
_button.Image = _fileName;
_imageButton.Source = _fileName;
_listView.ItemsSource = new string[] { _fileName };
button.Text = _disappearText;
}
})
};
var layout = new StackLayout()
{
Children =
{
button,
_image,
_button,
_imageButton,
_listView,
}
};
Content = layout;
}
#if UITEST
[Test]
public void TestImagesDisappearCorrectly()
{
RunningApp.WaitForElement(_fileName);
var elementsBefore = RunningApp.WaitForElement(_fileName);
var imageCell = RunningApp.Query(app => app.Marked(_theListView).Descendant()).Where(x => x.Class.Contains("Image")).FirstOrDefault();
#if __IOS__
Assert.AreEqual(4, elementsBefore.Where(x => x.Class.Contains("Image")).Count());
#else
Assert.AreEqual(3, elementsBefore.Length);
#endif
Assert.IsNotNull(imageCell);
RunningApp.Tap("ClickMe");
var elementsAfter = RunningApp.WaitForElement(_fileName);
var imageCellAfter = RunningApp.Query(app => app.Marked(_theListView).Descendant()).Where(x => x.Class.Contains("Image")).FirstOrDefault();
Assert.IsNull(imageCellAfter);
#if __IOS__
Assert.AreEqual(0, elementsAfter.Where(x => x.Class.Contains("Image")).Count());
#endif
#if __ANDROID__
foreach(var newElement in elementsAfter)
{
foreach(var oldElement in elementsBefore)
{
if(newElement.Class == oldElement.Class)
{
Assert.IsTrue(newElement.Rect.Height < oldElement.Rect.Height);
continue;
}
}
}
#endif
}
#endif
}
}

Просмотреть файл

@ -17,6 +17,7 @@
<DependentUpon>Issue1588.xaml</DependentUpon> <DependentUpon>Issue1588.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue4597.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Github3856.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Github3856.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1937.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1937.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3809.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue3809.cs" />

Просмотреть файл

@ -24,13 +24,13 @@ namespace Xamarin.Forms.Platform.Android
{ {
IImageController imageController = newView as IImageController; IImageController imageController = newView as IImageController;
newImageSource = newView?.Source; newImageSource = newImageSource ?? newView?.Source;
previousImageSource = previousView?.Source; previousImageSource = previousImageSource ?? previousView?.Source;
if (newImageSource == null || imageView.IsDisposed()) if (imageView.IsDisposed())
return; return;
if (Equals(previousImageSource, newImageSource)) if (newImageSource != null && Equals(previousImageSource, newImageSource))
return; return;
imageController?.SetIsLoading(true); imageController?.SetIsLoading(true);