Skip to content

Commit e62cb35

Browse files
Add DispatchIfRequired
It is currently unnecessary to marshall to the UI thread because `OnTextPropertyChanged` is always called from the UI thread. However, if other code in the future leverages this method, we should still ensure we propagate required tasks to the UI Thread.
1 parent 3c5b069 commit e62cb35

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/CommunityToolkit.Maui/Behaviors/UserStoppedTypingBehavior.shared.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ async Task OnTextPropertyChanged(InputView view, string? text)
126126
{
127127
if (tokenSource is not null)
128128
{
129-
tokenSource.Cancel();
129+
await tokenSource.CancelAsync();
130130
tokenSource.Dispose();
131131
}
132132

@@ -148,12 +148,12 @@ async Task OnTextPropertyChanged(InputView view, string? text)
148148

149149
if (ShouldDismissKeyboardAutomatically)
150150
{
151-
view.Unfocus();
151+
Dispatcher.DispatchIfRequired(view.Unfocus);
152152
}
153153

154154
if (Command?.CanExecute(CommandParameter ?? text) is true)
155155
{
156-
Command.Execute(CommandParameter ?? text);
156+
await Dispatcher.DispatchIfRequiredAsync(() => Command.Execute(CommandParameter ?? text));
157157
}
158158
}
159159
}

0 commit comments

Comments
 (0)