Skip to content

Commit 442f39e

Browse files
authored
Tidy up the masked text behavior handling of text changed (#1925)
* Queue up the Text update when running on Android * Provide a more consistent approach across all platforms --------- Co-authored-by: Shaun Lawrence <[email protected]>
1 parent 19097be commit 442f39e

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,10 @@ static async void OnUnmaskedCharacterPropertyChanged(BindableObject bindable, ob
104104

105105
Task OnTextPropertyChanged(CancellationToken token)
106106
{
107-
#if ANDROID
108-
// Android does not play well when we update the Text inside the TextChanged event. Therefore if we dispatch
109-
// the mechanism of updating the Text property it solves the issue of the caret position being updated incorrectly.
110-
Application.Current?.Dispatcher.Dispatch(async () => await ApplyMask(View?.Text, token));
111-
return Task.CompletedTask;
112-
#else
113-
return ApplyMask(View?.Text, token);
114-
#endif
107+
// Android does not play well when we update the Text inside the TextChanged event.
108+
// Therefore if we dispatch the mechanism of updating the Text property it solves the issue of the caret position being updated incorrectly.
109+
// https://github.com/CommunityToolkit/Maui/issues/460
110+
return View?.Dispatcher.DispatchAsync(() => ApplyMask(View?.Text, token)) ?? Task.CompletedTask;
115111
}
116112

117113
void SetMaskPositions(in string? mask)

0 commit comments

Comments
 (0)