-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Android Unfocused Entry Behavior only gets called when leaving the page #11881
Comments
@faceoffers28 this behavior is most likely controlled by the underlying platform. We don't automatically unfocus/focus things when navigation happens. Can you expand on your use case here? |
Hi @faceoffers28. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
@PureWeen The use case would be checking some text that was entered against a database to see if there is a match. If there is a match, changing the text to red and updating an icon image to indicate an unsuccessful outcome. The Unfocus event works as expected on iOS. It does not work as expected on Android. |
@faceoffers28 why use focus/unfocus for this? Instead of TextChanged? |
Hello @PureWeen TextChanged fires every time the text changes. It's extremely inefficient. It would result in many API calls to a rest API to check for a result. Is this really the only way to do this? |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
@PureWeen please, don't ignore this, it is a serious problem, and not even the shell navigation closes the keyboard! at least on 7,0 the keyboard can be closed by tapping on the "Done key", on 6.0 that is not possible! here is a video of the problem: https://imgur.com/a/DxG7pTW thank you! |
Still an issue. Clicking on any other part of the page should trigger Unfocused as it did in xamarin, but it doesnt. |
@PureWeen updated repo, added a page with a viewmodel. where i bind IsFocused. showing same behavior. only unfocusing when i change page through the flyout menu |
@PureWeen I can confirm that this is still happening! Can you please kindly answer, why is this being ignored for 8 months now? It basically prevents us from migrating to MAUI! |
@PureWeen i can also confirm the issue is still existed. and its very important for my app also |
I'll also confirm this still still an issue. Makes it really hard to make custom entries or use what we built in Xamarin.Forms in .NET Maui. |
Small note on my unfocus test. |
unfocused is being called on scrolling sometimes with template selectors |
Has anybody found a workaround to this issue? (Android only) |
This may be a way to listen to text changes and wait for them to stop: // used to schedule an update
Timer? timer;
// the buffer
const int TextChangedBuffer = 500; // half a second from the last character to sending the message
async void textEntry_TextChanged(object sender, TextChangedEventArgs e)
{
var entry = (Entry)sender;
// create a timer to trigger after the delay
// the dispatcher is used as the timer returns on a background thread - but may be correct if this is a request to the web
timer ??= new(_ => Dispatcher.Dispatch(() => UnFocusedLbl.Text = entry.Text));
// move the timeout forward on each update
timer.Change(TextChangedBuffer, Timeout.Infinite);
} |
We also require a (working) Unfocused event too. TextChanged fires too many events, we only need to know then the user is finished. Completed may have also worked, but if the user taps on a different entry cell it does not fire Completed(), only when user closes keyboard. This seems like such a basic functionality, its absence is surprising. Might try the timer method mentioned here but this feels like a hacky workaround. Edit: the timer method may not be ideal, but works well enough in testing so far... |
I have a small workaround for my case. public string Remark
{
get
{
return MyModel.Remark;
}
set
{
MyModel.Remark = value;
RestartTimer();
}
} Then on top of the viewmodel i also have private Timer timer; private void RestartTimer()
{
// Cancel the previous timer if it exists
timer?.Dispose();
// Start a new timer to check for inactivity after 1 seconds
timer = new Timer(_ =>
{
MainThread.BeginInvokeOnMainThread(() =>
{
Update();
});
//disposing jic
timer?.Dispose();
}, null, 1000, Timeout.Infinite);
} then update is just a function that sends my remark to the backend. EDIT private void RestartTimer()
{
timer ??= new(_ => MainThread.BeginInvokeOnMainThread(() => Update()));
timer.Change(1000, Timeout.Infinite);
} |
Hi All, In developing .NET MAUI, we learned that it is not possible on earlier versions of Android to unfocus an entry. Some control must always be focused. In Xamarin.Forms, this was approached by setting focus on the page layout; unfortunately, this approach created major accessibility issues. For these reasons, .NET MAUI no longer allows for this behavior by default. If this antipattern can be avoided, we highly recommend using a different approach. If it cannot be avoided, we'd love to learn more about your scenario so that we can better understand your development needs! That being said, we do understand the needs from a migration compatibility standpoint, so for those scenarios, there is a new property that was introduced in .NET 8. Using |
Description
This works as expected in iOS. In Android, Unfocused only gets called when leaving the page. It does not get called when you leave the Entry field.
Steps to Reproduce
Create an Entry in Xaml.
Create a Behavior like so.
Link to public reproduction project repository
https://github.com/dotnet/maui/
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 31 with a target of 33
Did you find any workaround?
Nope, there is no workaround.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: