-
Notifications
You must be signed in to change notification settings - Fork 768
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: ios PasswordBox changed event when focus #19337
Open
ajpinedam
wants to merge
2
commits into
unoplatform:master
Choose a base branch
from
ajpinedam:fix/ios.passwordbox
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+43
−20
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||
using System; | ||||||
#nullable enable | ||||||
using System; | ||||||
using System.Runtime.InteropServices; | ||||||
using CoreGraphics; | ||||||
using Foundation; | ||||||
|
@@ -19,10 +20,10 @@ namespace Microsoft.UI.Xaml.Controls | |||||
{ | ||||||
public partial class SinglelineTextBoxView : UITextField, ITextBoxView, DependencyObject, IFontScalable | ||||||
{ | ||||||
private SinglelineTextBoxDelegate _delegate; | ||||||
private SinglelineTextBoxDelegate _delegate = null!; | ||||||
private readonly WeakReference<TextBox> _textBox; | ||||||
private Action _foregroundChanged; | ||||||
private IDisposable _foregroundBrushChangedSubscription; | ||||||
private Action? _foregroundChanged; | ||||||
private IDisposable? _foregroundBrushChangedSubscription; | ||||||
|
||||||
public SinglelineTextBoxView(TextBox textBox) | ||||||
{ | ||||||
|
@@ -32,13 +33,13 @@ public SinglelineTextBoxView(TextBox textBox) | |||||
Initialize(); | ||||||
} | ||||||
|
||||||
public override void Paste(NSObject sender) => HandlePaste(() => base.Paste(sender)); | ||||||
public override void Paste(NSObject? sender) => HandlePaste(() => base.Paste(sender)); | ||||||
|
||||||
public override void PasteAndGo(NSObject sender) => HandlePaste(() => base.PasteAndGo(sender)); | ||||||
public override void PasteAndGo(NSObject? sender) => HandlePaste(() => base.PasteAndGo(sender)); | ||||||
|
||||||
public override void PasteAndMatchStyle(NSObject sender) => HandlePaste(() => base.PasteAndMatchStyle(sender)); | ||||||
public override void PasteAndMatchStyle(NSObject? sender) => HandlePaste(() => base.PasteAndMatchStyle(sender)); | ||||||
|
||||||
public override void PasteAndSearch(NSObject sender) => HandlePaste(() => base.PasteAndSearch(sender)); | ||||||
public override void PasteAndSearch(NSObject? sender) => HandlePaste(() => base.PasteAndSearch(sender)); | ||||||
|
||||||
public override void Paste(NSItemProvider[] itemProviders) => HandlePaste(() => base.Paste(itemProviders)); | ||||||
|
||||||
|
@@ -54,7 +55,7 @@ private void HandlePaste(Action baseAction) | |||||
|
||||||
internal TextBox TextBox => _textBox.GetTarget(); | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
public override string Text | ||||||
public override string? Text | ||||||
{ | ||||||
get => base.Text; | ||||||
set | ||||||
|
@@ -69,15 +70,14 @@ public override string Text | |||||
} | ||||||
} | ||||||
|
||||||
private void OnEditingChanged(object sender, EventArgs e) | ||||||
private void OnEditingChanged(object? sender, EventArgs e) | ||||||
{ | ||||||
OnTextChanged(); | ||||||
} | ||||||
|
||||||
private void OnTextChanged() | ||||||
{ | ||||||
var textBox = _textBox?.GetTarget(); | ||||||
if (textBox != null) | ||||||
if (TextBox is { } textBox) | ||||||
{ | ||||||
var text = textBox.ProcessTextInput(Text); | ||||||
SetTextNative(text); | ||||||
|
@@ -99,29 +99,40 @@ private void Initialize() | |||||
|
||||||
partial void OnLoadedPartial() | ||||||
{ | ||||||
this.EditingChanged += OnEditingChanged; | ||||||
this.EditingDidEnd += OnEditingChanged; | ||||||
SubscribeEditingEvents(); | ||||||
} | ||||||
|
||||||
partial void OnUnloadedPartial() | ||||||
{ | ||||||
this.EditingChanged -= OnEditingChanged; | ||||||
this.EditingDidEnd -= OnEditingChanged; | ||||||
UnsubscribeEditingEvents(); | ||||||
} | ||||||
|
||||||
//Forces the secure UITextField to maintain its current value upon regaining focus | ||||||
public override bool BecomeFirstResponder() | ||||||
{ | ||||||
var result = base.BecomeFirstResponder(); | ||||||
|
||||||
if (SecureTextEntry) | ||||||
if (SecureTextEntry && !string.IsNullOrEmpty(Text)) | ||||||
{ | ||||||
UnsubscribeEditingEvents(); | ||||||
|
||||||
var text = Text; | ||||||
Text = string.Empty; | ||||||
UpdatePasswordText(string.Empty); | ||||||
InsertText(text); | ||||||
UpdatePasswordText(text); | ||||||
|
||||||
SubscribeEditingEvents(); | ||||||
} | ||||||
|
||||||
Comment on lines
+115
to
125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldnt it be better to use a flag to guard the handlers, instead of un- and re-registering the events? |
||||||
return result; | ||||||
|
||||||
void UpdatePasswordText(string text) | ||||||
{ | ||||||
if (TextBox is PasswordBox passwordBox) | ||||||
{ | ||||||
passwordBox.Password = text; | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
public override CGSize SizeThatFits(CGSize size) | ||||||
|
@@ -261,5 +272,17 @@ public void Select(int start, int length) | |||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
private void SubscribeEditingEvents() | ||||||
{ | ||||||
EditingChanged += OnEditingChanged; | ||||||
EditingDidEnd += OnEditingChanged; | ||||||
} | ||||||
|
||||||
private void UnsubscribeEditingEvents() | ||||||
{ | ||||||
EditingChanged -= OnEditingChanged; | ||||||
EditingDidEnd -= OnEditingChanged; | ||||||
} | ||||||
} | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and tag
Initialize()
with[MemberNotNull(nameof(_delegate))]