Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up relevant CA1416 warnings - Set 2 #26724

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/CheckBoxUITest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.None, 26593, "CheckBox UI Test", PlatformAffected.iOS)]
public partial class CheckBoxUITestSample : ContentPage
{
public CheckBoxUITestSample()
{
Grid grid = new Grid()
{
ColumnDefinitions = new ColumnDefinitionCollection
{
new ColumnDefinition(),
new ColumnDefinition()
}
};

Label label = new Label
{
Text = "CheckBox",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.End,
AutomationId = "Label"
};

CheckBox checkBox = new CheckBox
{
IsChecked = true,
Color = Colors.Red,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
AutomationId = "CheckBox"
};

checkBox.CheckedChanged += (s, e) =>
{
label.Text = $"CheckBox is {(checkBox.IsChecked ? "Checked" : "Unchecked")}";
};

grid.AddChild(label, 0, 0);
grid.AddChild(checkBox, 1, 0);
Content = grid;
}
}
39 changes: 39 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/SwipeViewUITest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.None, 26593, "SwipeView UI Test", PlatformAffected.iOS)]
public partial class SwipeViewUITest : ContentPage
{
public SwipeViewUITest()
{

SwipeItem favoriteSwipeItem = new SwipeItem
{
Text = "Coffee",
IconImageSource = "coffee.png",
BackgroundColor = Colors.Brown
};

// SwipeView content
Grid grid = new Grid
{
HeightRequest = 60,
BackgroundColor = Colors.LightGray
};
grid.Add(new Label
{
Text = "Swipe right",
AutomationId = "SwipeRight",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
});

SwipeView swipeView = new SwipeView
{
RightItems = new SwipeItems { favoriteSwipeItem },
Content = grid
};

Content = swipeView;

}
}
20 changes: 20 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/TimePickerUITest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.None, 26593, "TimePicker UI Test", PlatformAffected.iOS)]
public partial class TimePickerUITest : ContentPage
{
public TimePickerUITest()
{
Grid grid = new Grid();

TimePicker timePicker = new TimePicker
{
Time = new TimeSpan(4, 14, 23),
Format = "hh:mm:ss",
AutomationId = "TimePicker"
};

grid.Children.Add(timePicker);
Content = grid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#if TEST_FAILS_ON_CATALYST // On Catalyst, the CheckBox was not able to be tapped in the CI.
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class CheckBoxUITest : _IssuesUITest
{
public override string Issue => "CheckBox UI Test";

public CheckBoxUITest(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.CheckBox), Order(1)]
public void VerifyCheckBoxUnCheckedState()
{
App.WaitForElement("CheckBox");
App.Tap("CheckBox");
VerifyScreenshot();
}

[Test]
[Category(UITestCategories.CheckBox), Order(2)]
public void VerifyCheckBoxCheckedState()
{
App.WaitForElement("CheckBox");
App.Tap("CheckBox");
VerifyScreenshot();
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if ANDROID || IOS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class SwipeViewUITest : _IssuesUITest
{
public override string Issue => "SwipeView UI Test";

public SwipeViewUITest(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.SwipeView)]
public void VerifySwipeViewApperance()
{
var rect = App.WaitForElement("SwipeRight").GetRect();
var centerX = rect.X + rect.Width / 2;
var centerY = rect.Y + rect.Height / 2;
App.DragCoordinates(centerX, centerY, centerX - 200, centerY);
VerifyScreenshot();
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#if TEST_FAILS_ON_CATALYST // TimePicker not opens the dialog, issue: https://github.com/dotnet/maui/issues/10827
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class TimePickerUITest : _IssuesUITest
{
public override string Issue => "TimePicker UI Test";

public TimePickerUITest(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.TimePicker)]
public void VerifyTimePickerApperance()
{
App.WaitForElement("TimePicker");
App.Tap("TimePicker");
VerifyScreenshot();
}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ -142,12 +142,39 @@ static UIImage MaxResizeSwipeItemIconImage(UIImage sourceImage, nfloat maxWidth,

var width = maxResizeFactor * sourceSize.Width;
var height = maxResizeFactor * sourceSize.Height;
UIGraphics.BeginImageContextWithOptions(new CGSize((nfloat)width, (nfloat)height), false, 0);
sourceImage.Draw(new CGRect(0, 0, (nfloat)width, (nfloat)height));
var resultImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
if (!OperatingSystem.IsIOSVersionAtLeast(17))
{
UIGraphics.BeginImageContextWithOptions(new CGSize((nfloat)width, (nfloat)height), false, 0);
sourceImage.Draw(new CGRect(0, 0, (nfloat)width, (nfloat)height));
var resultImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();

return resultImage;
}

var format = new UIGraphicsImageRendererFormat
{
Opaque = false,
Scale = 0
};

return resultImage;
using (var renderer = new UIGraphicsImageRenderer(new CGSize(width, height), format))
{
var resultImage = renderer.CreateImage((UIGraphicsImageRendererContext imageContext) =>
{
var cgcontext = imageContext.CGContext;

// The image is drawn upside down because Core Graphics uses a bottom-left origin,
// whereas UIKit uses a top-left origin. Adjust the coordinate system to align with UIKit's top-left origin.
cgcontext.TranslateCTM(0, (nfloat)height);
cgcontext.ScaleCTM(1, -1);
cgcontext.DrawImage(new CGRect(0, 0, (nfloat)width, (nfloat)height), sourceImage.CGImage);
cgcontext.ScaleCTM(1, -1);
cgcontext.TranslateCTM(0, -(nfloat)height);
});

return resultImage;
}
}
}

Expand Down
36 changes: 21 additions & 15 deletions src/Core/src/Platform/iOS/MauiCheckBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,17 @@ static void DrawCheckMark(UIBezierPath path)

UIImage CreateCheckBox(UIImage? check)
{
UIGraphics.BeginImageContextWithOptions(new CGSize(DefaultSize, DefaultSize), false, 0);
var context = UIGraphics.GetCurrentContext();
context.SaveState();
var renderer = new UIGraphicsImageRenderer(new CGSize(DefaultSize, DefaultSize));
var image = renderer.CreateImage((UIGraphicsImageRendererContext ctx) =>
{
var context = ctx.CGContext;
RenderCheckMark(context, check);
});
return image;
}

void RenderCheckMark(CGContext context, UIImage? check)
{
var checkedColor = CheckBoxTintUIColor;

if (checkedColor != null)
Expand All @@ -203,18 +210,21 @@ UIImage CreateCheckBox(UIImage? check)
boxPath.Fill();
check.Draw(new CGPoint(0, 0), CGBlendMode.DestinationOut, 1);
}

context.RestoreState();
var img = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();

return img;
}

static UIImage CreateCheckMark()
{
UIGraphics.BeginImageContextWithOptions(new CGSize(DefaultSize, DefaultSize), false, 0);
var context = UIGraphics.GetCurrentContext();
using var renderer = new UIGraphicsImageRenderer(new CGSize(DefaultSize, DefaultSize));
var image = renderer.CreateImage((UIGraphicsImageRendererContext ctx) =>
{
var context = ctx.CGContext;
RenderCheckMark(context);
});
return image;
}

static void RenderCheckMark(CGContext context)
{
context.SaveState();

var vPadding = LineWidth / 2;
Expand All @@ -230,10 +240,6 @@ static UIImage CreateCheckMark()
checkPath.Stroke();

context.RestoreState();
var img = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();

return img;
}

public override CGSize SizeThatFits(CGSize size)
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Platform/iOS/MauiTimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MauiTimePicker()
_proxy = new(dateSelected);
#endif

if (OperatingSystem.IsIOSVersionAtLeast(14))
if (OperatingSystem.IsIOSVersionAtLeast(13, 4) || OperatingSystem.IsMacCatalyst())
{
_picker.PreferredDatePickerStyle = UIDatePickerStyle.Wheels;
}
Expand Down
Loading