Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Image Button Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Feb 28, 2018
1 parent 051700f commit 884e6c7
Show file tree
Hide file tree
Showing 78 changed files with 5,056 additions and 780 deletions.
8 changes: 8 additions & 0 deletions Stubs/Xamarin.Forms.Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ internal class _ImageRenderer { }
[RenderWith (typeof (ButtonRenderer))]
internal class _ButtonRenderer { }

#if __ANDROID__
[RenderWith(typeof(Android.FastRenderers.ImageButtonRenderer))]
#else
[RenderWith(typeof(ImageButtonRenderer))]
#endif
internal class _ImageButtonRenderer { }


[RenderWith (typeof (TableViewRenderer))]
internal class _TableViewRenderer { }

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@
<Compile Include="_60122ImageRenderer.cs" />
<Content Include="Assets\Fonts\OFL.txt" />
<Content Include="bank.png" />
<Content Include="calculator.png" />
<Content Include="coffee.png" />
<Content Include="cover1.jpg" />
<Content Include="cover1small.jpg" />
<Content Include="crimsonsmall.jpg" />
<Content Include="default.css" />
<Content Include="Fruits.jpg" />
<Content Include="invalidimage.jpg" />
<Content Include="local.html" />
<Content Include="test.jpg" />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Xamarin.Forms.Controls/CoreGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ public override string ToString()
new GalleryPageFactory(() => new EditorCoreGalleryPage(), "Editor Gallery"),
new GalleryPageFactory(() => new FrameCoreGalleryPage(), "Frame Gallery"),
new GalleryPageFactory(() => new ImageCoreGalleryPage(), "Image Gallery"),
new GalleryPageFactory(() => new ImageButtonCoreGalleryPage(), "Image Button Gallery"),
new GalleryPageFactory(() => new KeyboardCoreGallery(), "Keyboard Gallery"),
new GalleryPageFactory(() => new LabelCoreGalleryPage(), "Label Gallery"),
new GalleryPageFactory(() => new ListViewCoreGalleryPage(), "ListView Gallery"),
Expand Down
112 changes: 112 additions & 0 deletions Xamarin.Forms.Controls/CoreGalleryPages/ImageButtonCoreGalleryPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;

using Xamarin.Forms.CustomAttributes;

namespace Xamarin.Forms.Controls
{
internal class ImageButtonCoreGalleryPage : CoreGalleryPage<ImageButton>
{
protected override bool SupportsFocus => false;

protected override bool SupportsTapGestureRecognizer => false;

protected override void InitializeElement(ImageButton element)
{
element.Source = "oasissmall.jpg";
}

protected override void Build(StackLayout stackLayout)
{
base.Build(stackLayout);


IsEnabledStateViewContainer.View.Clicked += (sender, args) =>
{
IsEnabledStateViewContainer.TitleLabel.Text += " (Tapped)";
};

var aspectFillContainer = new ViewContainer<ImageButton>(Test.ImageButton.AspectFill, new ImageButton { Aspect = Aspect.AspectFill });
var aspectFitContainer = new ViewContainer<ImageButton>(Test.ImageButton.AspectFit, new ImageButton { Aspect = Aspect.AspectFit });
var fillContainer = new ViewContainer<ImageButton>(Test.ImageButton.Fill, new ImageButton { Aspect = Aspect.Fill });
var isLoadingContainer = new StateViewContainer<ImageButton>(Test.ImageButton.IsLoading, new ImageButton());
var isOpaqueContainer = new StateViewContainer<ImageButton>(Test.ImageButton.IsOpaque, new ImageButton());


var borderButtonContainer = new ViewContainer<ImageButton>(Test.ImageButton.BorderColor,
new ImageButton
{
BackgroundColor = Color.Transparent,
BorderColor = Color.Red,
BorderWidth = 1,
Source = "oasissmall.jpg"
}
);

var borderRadiusContainer = new ViewContainer<ImageButton>(Test.ImageButton.BorderRadius,
new ImageButton
{
Source = "oasissmall.jpg",
BackgroundColor = Color.Transparent,
BorderColor = Color.Red,
CornerRadius = 20,
BorderWidth = 1,
}
);

var borderWidthContainer = new ViewContainer<ImageButton>(Test.ImageButton.BorderWidth,
new ImageButton
{
Source = "oasissmall.jpg",
BackgroundColor = Color.Transparent,
BorderColor = Color.Red,
BorderWidth = 15,
}
);

var clickedContainer = new EventViewContainer<ImageButton>(Test.ImageButton.Clicked,
new ImageButton
{
Source = "oasissmall.jpg"
}
);
clickedContainer.View.Clicked += (sender, args) => clickedContainer.EventFired();

var commandContainer = new ViewContainer<ImageButton>(Test.ImageButton.Command,
new ImageButton
{
Command = new Command(() => DisplayActionSheet("Hello Command", "Cancel", "Destroy")),
Source = "oasissmall.jpg"
}
);

var imageContainer = new ViewContainer<ImageButton>(Test.Button.Image,
new ImageButton
{
Source = new FileImageSource { File = "bank.png" }
}
);


InitializeElement(aspectFillContainer.View);
InitializeElement(aspectFitContainer.View);
InitializeElement(fillContainer.View);
InitializeElement(isLoadingContainer.View);
InitializeElement(isOpaqueContainer.View);

var sourceContainer = new ViewContainer<ImageButton>(Test.ImageButton.Source, new ImageButton { Source = "https://raw.githubusercontent.com/xamarin/Xamarin.Forms/master/Xamarin.Forms.Controls/coffee.png" });

Add(aspectFillContainer);
Add(aspectFitContainer);
Add(fillContainer);
Add(isLoadingContainer);
Add(isOpaqueContainer);
Add(sourceContainer);
Add(borderButtonContainer);
Add(borderRadiusContainer);
Add(borderWidthContainer);
Add(clickedContainer);
Add(commandContainer);
Add(imageContainer);
}
}
}
2 changes: 2 additions & 0 deletions Xamarin.Forms.Core.UITests.Shared/PlatformQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ internal static class PlatformViews
public static readonly string Entry = "UITextField";
public static readonly string Frame = "view:'Xamarin_Forms_Platform_iOS_FrameRenderer'";
public static readonly string Image = "UIImageView";
public static readonly string ImageButton = "UIButton";
public static readonly string Label = "UILabel";
public static readonly string ListView = "UITableView";
public static readonly string Map = "MKMapView";
Expand All @@ -86,6 +87,7 @@ internal static class PlatformViews
public static readonly string Entry = "xamarin.forms.platform.android.EntryEditText";
public static readonly string Frame = "xamarin.forms.platform.android.appcompat.FrameRenderer";
public static readonly string Image = "android.widget.ImageView";
public static readonly string ImageButton = "android.widget.ImageButton";
public static readonly string Label = "android.widget.TextView";
public static readonly string ListView = "android.widget.ListView";
public static readonly string Map = "android.gms.maps.GoogleMap";
Expand Down
2 changes: 2 additions & 0 deletions Xamarin.Forms.Core.UITests.Shared/Queries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal static class GalleryQueries
public const string EntryGallery = "* marked:'Entry Gallery'";
public const string FrameGallery = "* marked:'Frame Gallery'";
public const string ImageGallery = "* marked:'Image Gallery'";
public const string ImageButtonGallery = "* marked:'Image Button Gallery'";
public const string LabelGallery = "* marked:'Label Gallery'";
public const string ListViewGallery = "* marked:'ListView Gallery'";
public const string OpenGLViewGallery = "* marked:'OpenGLView Gallery'";
Expand Down Expand Up @@ -84,6 +85,7 @@ internal static class Views
public static readonly string Entry = PlatformViews.Entry;
public static readonly string Frame = PlatformViews.Frame;
public static readonly string Image = PlatformViews.Image;
public static readonly string ImageButton = PlatformViews.ImageButton;
public static readonly string Label = PlatformViews.Label;
public static readonly string ListView = PlatformViews.ListView;
public static readonly string Map = PlatformViews.Map;
Expand Down
144 changes: 144 additions & 0 deletions Xamarin.Forms.Core.UITests.Shared/Tests/ImageButtonUITests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
using System.Threading;
using NUnit.Framework;
using Xamarin.Forms.CustomAttributes;

namespace Xamarin.Forms.Core.UITests
{
[TestFixture]
[Category(UITestCategories.Image)]
internal class ImageButtonUITests : _ViewUITests
{
public ImageButtonUITests()
{
PlatformViewType = Views.ImageButton;
}

protected override void NavigateToGallery()
{
App.NavigateToGallery(GalleryQueries.ImageButtonGallery);

// let remote images load
Thread.Sleep(2000);
}

[UiTestExempt(ExemptReason.CannotTest, "Invalid interaction")]
public override void _Focus()
{
}

// TODO
public override void _GestureRecognizers()
{
}

[UiTestExempt(ExemptReason.CannotTest, "Invalid interaction")]
public override void _IsEnabled()
{
}

[UiTestExempt(ExemptReason.CannotTest, "Invalid interaction")]
public override void _IsFocused()
{
}

[UiTestExempt(ExemptReason.CannotTest, "Invalid interaction")]
public override void _UnFocus()
{
}

// TODO
// Implement control specific ui tests

// TODO
// Tests for remote images

protected override void FixtureTeardown()
{
App.NavigateBack();
base.FixtureTeardown();
}




// ImageButton Tests
[Test]
[UiTest(typeof(ImageButton), "BorderColor")]
[UiTestBroken(BrokenReason.CalabashAndroidUnsupported, "Figure out how to get Android Drawables")]
[UiTestBroken(BrokenReason.CalabashiOSUnsupported, "iOS nil result")]
public void BorderColor()
{
//TODO iOS
var remote = new ViewContainerRemote(App, Test.ImageButton.BorderColor, PlatformViewType);
remote.GoTo();
}

[Test]
[UiTest(typeof(ImageButton), "BorderRadius")]
[UiTestBroken(BrokenReason.CalabashAndroidUnsupported, "Figure out how to get Android Drawables")]
public void BorderRadius()
{
var remote = new ViewContainerRemote(App, Test.ImageButton.BorderRadius, PlatformViewType);
remote.GoTo();

#if __IOS__
var borderRadius = remote.GetProperty<float>(ImageButton.CornerRadiusProperty);
Assert.AreEqual(20.0f, borderRadius);
#endif
}

[Test]
[UiTest(typeof(ImageButton), "BorderWidth")]
[UiTestBroken(BrokenReason.CalabashAndroidUnsupported, "Figure out how to get Android Drawables")]
public void BorderWidth()
{
var remote = new ViewContainerRemote(App, Test.ImageButton.BorderWidth, PlatformViewType);
remote.GoTo();

#if __IOS__
var borderWidth = remote.GetProperty<float>(ImageButton.BorderWidthProperty);
Assert.AreEqual(15.0f, borderWidth);
#endif
}

[Test]
[UiTest(typeof(ImageButton), "Clicked")]
public void Clicked()
{
var remote = new EventViewContainerRemote(App, Test.ImageButton.Clicked, PlatformViewType);
remote.GoTo();

var textBeforeClick = remote.GetEventLabel().Text;
Assert.AreEqual("Event: Clicked (none)", textBeforeClick);

// Click ImageButton
remote.TapView();

var textAfterClick = remote.GetEventLabel().Text;
Assert.AreEqual("Event: Clicked (fired 1)", textAfterClick);
}

[Test]
[UiTest(typeof(ImageButton), "Command")]
public void Command()
{
var remote = new ViewContainerRemote(App, Test.ImageButton.Command, PlatformViewType);
remote.GoTo();

remote.TapView();

App.WaitForElement(q => q.Marked("Hello Command"));
App.Tap(q => q.Marked("Destroy"));
}

[Test]
[UiTest(typeof(ImageButton), "Image")]
[UiTestExempt(ExemptReason.TimeConsuming, "Need way to check Android resources")]
public void Image()
{
//TODO iOS
var remote = new ViewContainerRemote(App, Test.ImageButton.Image, PlatformViewType);
remote.GoTo();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Tests\EditorUITests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tests\EntryUITests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tests\FrameUITests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tests\ImageButtonUITests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tests\ImageUITests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tests\LabelUITests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tests\Legacy-CellsUITests.cs" />
Expand Down
Loading

0 comments on commit 884e6c7

Please sign in to comment.