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

[iOS]Resolved Button Text Resets to Previous Value When Set to Empty String Programmatically. #25171

Merged
merged 8 commits into from
Oct 14, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public static void UpdateText(this UIButton platformButton, Button button)
var text = TextTransformUtilites.GetTransformedText(button.Text, button.TextTransform);
platformButton.SetTitle(text, UIControlState.Normal);

// The TitleLabel retains its previous text value even after a new value is assigned. As a result, the label does not display the updated text and reverts to the old value when the button is re-measured
if (string.IsNullOrEmpty(button.Text))
{
platformButton.TitleLabel.Text = string.Empty;
}

// Content layout depends on whether or not the text is empty; changing the text means
// we may need to update the content layout
platformButton.UpdateContentLayout(button);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue18235.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
x:Class="Maui.Controls.Sample.Issues.Issue18235">

<VerticalStackLayout Padding="25" Spacing="25">
<Button Clicked="OnButtonClicked" Background="#FF5D5DB4" AutomationId="PrimaryActionButton" Text="Test Button1" />
<Button Clicked="OnButtonClicked" Background="#FF5D5DB4" AutomationId="SecondaryActionButton" Text="Test Button2" />
</VerticalStackLayout>

</ContentPage>
24 changes: 24 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue18235.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.Maui.Controls.Internals;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 18235, "[7.096] Setting .NET MAUI Button.Text to String.Empty inside a Clicked event handler causes previously set buttons to revert to previous values", PlatformAffected.iOS)]
public partial class Issue18235 : ContentPage
{
public Issue18235()
{
InitializeComponent();
}

private void OnButtonClicked(object sender, EventArgs e)
{
if (sender is Button buttonClicked)
buttonClicked.Text = String.Empty;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if !MACCATALYST
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue18235 : _IssuesUITest
{
public Issue18235(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "[7.096] Setting .NET MAUI Button.Text to String.Empty inside a Clicked event handler causes previously set buttons to revert to previous values";

[Test]
[Category(UITestCategories.Button)]
public void VerifyButtonText()
{
App.WaitForElement("SecondaryActionButton");
App.Tap("PrimaryActionButton");
App.Tap("SecondaryActionButton");
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