-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: TJ Lambert <[email protected]>
- Loading branch information
1 parent
259b6bd
commit 5104062
Showing
4 changed files
with
122 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Controls/tests/TestCases.HostApp/Issues/Issue25409.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Issues.Issue25409" | ||
Title="Issue25409"> | ||
<Button | ||
x:Name="button1" | ||
AutomationId="button1" | ||
Text="Click me" | ||
Clicked="OnCounterClicked" /> | ||
</ContentPage> |
54 changes: 54 additions & 0 deletions
54
src/Controls/tests/TestCases.HostApp/Issues/Issue25409.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[Issue(IssueTracker.Github, 25409, "UIButton CurrentImage can be set without crashing", PlatformAffected.iOS)] | ||
public partial class Issue25409 : ContentPage | ||
{ | ||
public Issue25409() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
#if IOS | ||
int count = 0; | ||
#endif | ||
|
||
private void OnCounterClicked(object sender, EventArgs e) | ||
{ | ||
#if IOS | ||
((Action)(async () => | ||
{ | ||
if (count % 2 == 0) | ||
{ | ||
var imageSource = new FileImageSource() { File = "shopping_cart.png" }; | ||
if (button1.Handler?.MauiContext is not null && (button1.Handler.PlatformView is UIKit.UIButton platformButton)) | ||
{ | ||
var imageResult = await imageSource.GetPlatformImageAsync(button1.Handler.MauiContext); | ||
if (imageResult is not null) | ||
{ | ||
platformButton.SetImage(imageResult.Value, UIKit.UIControlState.Normal); | ||
} | ||
} | ||
// since changing the UIButton.CurrentImage with SetImage does not trigger a layout pass, | ||
// we can change something else to force a layout pass | ||
button1.Text = string.Empty; | ||
} | ||
else | ||
{ | ||
if (button1.Handler?.PlatformView is UIKit.UIButton platformButton) | ||
{ | ||
platformButton.SetImage(null, UIKit.UIControlState.Normal); | ||
} | ||
// since changing the UIButton.CurrentImage with SetImage does not trigger a layout pass, | ||
// we can change something else to force a layout pass | ||
button1.Text = "Trigger Layout!"; | ||
} | ||
count++; | ||
}))(); | ||
#endif | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25409.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#if IOS | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
||
public class Issue25409 : _IssuesUITest | ||
{ | ||
public Issue25409(TestDevice testDevice) : base(testDevice) | ||
{ | ||
} | ||
|
||
public override string Issue => "UIButton CurrentImage can be set without crashing"; | ||
|
||
[Test] | ||
[Category(UITestCategories.Button)] | ||
public void CurrentImageSet() | ||
{ | ||
App.WaitForElement("button1"); | ||
App.Tap("button1"); | ||
App.WaitForElement("button1"); | ||
App.Tap("button1"); | ||
App.WaitForElement("button1"); | ||
App.Tap("button1"); | ||
} | ||
} | ||
#endif |