Skip to content

Fix iOS Entry password text loss when toggling IsPassword while focused#30327

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/fix-30085
Closed

Fix iOS Entry password text loss when toggling IsPassword while focused#30327
Copilot wants to merge 2 commits intomainfrom
copilot/fix-30085

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 30, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description

This PR fixes an iOS-specific issue where an Entry with IsPassword=true would lose previously entered text when toggling password visibility while the field is focused.

Problem

On iOS, when following these steps:

  1. Enter text in a password Entry field (e.g., "password123")
  2. Toggle IsPassword = false to show the text
  3. Toggle IsPassword = true to hide the text again
  4. Type additional text (e.g., "456")

The previously entered text would be lost, resulting in only "456" instead of the expected "password123456".

Root Cause

The issue was in the UpdateIsPassword method in TextFieldExtensions.cs for iOS. When toggling back to password mode while the field is focused, the existing workaround code:

  1. Temporarily disables the text field (textField.Enabled = false)
  2. Sets secure text entry (textField.SecureTextEntry = true)
  3. Re-enables the field (textField.Enabled = entry.IsEnabled)
  4. Restores focus (textField.BecomeFirstResponder())

This disable/enable cycle on iOS was inadvertently clearing the text field content.

Solution

Added minimal text preservation logic that:

  • Stores the current text before the disable/enable cycle
  • Checks if text was lost after re-enabling
  • Restores the text only if it was cleared
// Store the current text before disabling to prevent text loss
var currentText = textField.Text;
textField.Enabled = false;
textField.SecureTextEntry = true;
textField.Enabled = entry.IsEnabled;
// Restore the text after re-enabling if it was cleared
if (textField.Text != currentText)
    textField.Text = currentText;
textField.BecomeFirstResponder();

Testing

  • Added unit test PasswordTogglingPreservesTextWhenFocused in EntryHandlerTests.iOS.cs
  • Created manual test case Issue30085.cs for validation
  • Verified the fix compiles for all target frameworks
  • No breaking changes or impact on other platforms

Impact

  • ✅ Fixes text loss when toggling password visibility on iOS
  • ✅ Maintains all existing behavior and workarounds
  • ✅ Minimal, surgical change affecting only the problematic code path
  • ✅ No impact on Android, Windows, or other platforms
  • ✅ Backward compatible

Fixes #30085.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com>
Copilot AI changed the title [WIP] Entry with IsPassword toggling loses previously entered text on iOS when IsPassword is re-enabled Fix iOS Entry password text loss when toggling IsPassword while focused Jun 30, 2025
Copilot AI requested a review from PureWeen June 30, 2025 13:51
@AlleSchonWeg
Copy link
Copy Markdown
Contributor

It would be nice to also keep the cursor position when toggling.

@sheiksyedm
Copy link
Copy Markdown
Contributor

Closed as favour of #30572

@sheiksyedm sheiksyedm closed this Feb 27, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Mar 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Entry with IsPassword toggling loses previously entered text on iOS when IsPassword is re-enabled

4 participants