Create ImageButton with correct Button Type (#10394)
This commit is contained in:
Родитель
26bba27edc
Коммит
c92600adbd
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Foundation;
|
||||
using NUnit.Framework;
|
||||
using UIKit;
|
||||
|
||||
namespace Xamarin.Forms.Platform.iOS.UnitTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ImageButtonTests : PlatformTestFixture
|
||||
{
|
||||
[Test, Category("ImageButton")]
|
||||
public async Task CreatedWithCorrectButtonType()
|
||||
{
|
||||
var imageButton = new ImageButton();
|
||||
UIButtonType buttonType = await GetControlProperty(imageButton, uiButton => uiButton.ButtonType);
|
||||
Assert.AreNotEqual(UIButtonType.Custom, buttonType);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -140,6 +140,23 @@ namespace Xamarin.Forms.Platform.iOS.UnitTests
|
|||
});
|
||||
}
|
||||
|
||||
protected UIButton GetNativeControl(ImageButton button)
|
||||
{
|
||||
var renderer = GetRenderer(button);
|
||||
var viewRenderer = renderer.NativeView as ImageButtonRenderer;
|
||||
return viewRenderer.Control;
|
||||
}
|
||||
|
||||
protected async Task<TProperty> GetControlProperty<TProperty>(ImageButton button, Func<UIButton, TProperty> getProperty)
|
||||
{
|
||||
return await Device.InvokeOnMainThreadAsync(() => {
|
||||
using (var uiButton = GetNativeControl(button))
|
||||
{
|
||||
return getProperty(uiButton);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected async Task<TProperty> GetRendererProperty<TProperty>(View view,
|
||||
Func<IVisualElementRenderer, TProperty> getProperty, bool requiresLayout = false)
|
||||
{
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
<Compile Include="CornerRadiusTests.cs" />
|
||||
<Compile Include="EmbeddingTests.cs" />
|
||||
<Compile Include="FlowDirectionTests.cs" />
|
||||
<Compile Include="ImageButtonTests.cs" />
|
||||
<Compile Include="IsEnabledTests.cs" />
|
||||
<Compile Include="IsVisibleTests.cs" />
|
||||
<Compile Include="NavigationTests.cs" />
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
|
||||
protected override UIButton CreateNativeControl()
|
||||
{
|
||||
return new UIButton();
|
||||
return new UIButton(UIButtonType.System);
|
||||
}
|
||||
|
||||
protected override void SetAccessibilityLabel()
|
||||
|
|
Загрузка…
Ссылка в новой задаче