-
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
Show keyboard on Android entry/editor/searchbar focus #12890
Conversation
e7464bf
to
54addf0
Compare
src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs
Outdated
Show resolved
Hide resolved
|
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.
One case this doesn't cover is if a control is already focused and the keyboard is closed.
The problem here is that our Focus
call inside controls feels like it's trying to be too smart.
It checks its own internal concept of IsFocused
and then doesn't trigger the Handler
logic.
My initial thought here is that we should move all of this focus code into the mappers.
I feel like we should move all of this focus code into a VisualElement
CommandMapper
so that users can even modify or adjust the focus code in general.
As is we sort of block the user from being able to influence the focus calls
@PureWeen In what scenario would someone call focus to a control that's already focused? And on the flipside, what might the repercussions be of letting someone focus on a control that's already focused? Only the risks come to mind at the moment I'm not opposed to exposing it as a mapper though |
Thank you for your pull request. We are auto-formating your source code to follow our code guidelines. |
@@ -799,7 +800,14 @@ public ResourceDictionary Resources | |||
public bool Focus() | |||
{ | |||
if (IsFocused) | |||
{ | |||
#if ANDROID | |||
// TODO: Refactor using mappers for .NET 8 |
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.
After chatting with @PureWeen, we've agreed to do this in a follow-up PR. While this code here isn't ideal, it keeps this PR backport-friendly
@@ -17,5 +18,28 @@ Task<string> GetPlatformText(SearchBarHandler handler) | |||
{ | |||
return InvokeOnMainThreadAsync(() => GetPlatformControl(handler).Query); | |||
} | |||
|
|||
[Fact] | |||
public async Task ShowsKeyboardOnFocus() |
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.
Can we move these to a general test class so we don't have this code copied around?
I think we can create a TextInput set of tests
\TextInput\TextInput.Android.cs
Then you can use a theory with classdata to pass in all the textinput types.
Thank you for your pull request. We are auto-formating your source code to follow our code guidelines. |
This reverts commit 54addf0.
|
||
var windowToken = inputView.WindowToken; | ||
if (windowToken != null && inputMethodManager != null) | ||
using (var inputMethodManager = (InputMethodManager)context.GetSystemService(Context.InputMethodService)!) |
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.
Can we remove the null forgiveness operator here? !
{ | ||
// Cannot find the TextView; nothing else to do | ||
return; | ||
} | ||
|
||
using (var inputMethodManager = (InputMethodManager)searchView.Context.GetSystemService(Context.InputMethodService)!) |
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.
Remove !
here as well? You might have to grab the service before the using and check it for null.
Thank you for your pull request. We are auto-formatting your source code to follow our code guidelines. |
/backport to net7.0 |
Started backporting to net7.0: https://github.com/dotnet/maui/actions/runs/4376306063 |
@PureWeen backporting to net7.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Show keyboard on Android entry/editor/searchbar focus
Applying: Move logic to mappers
Applying: Tweak Keyboard logic
Applying: Show keyboard on Android entry/editor/searchbar focus
Applying: Revert "Show keyboard on Android entry/editor/searchbar focus"
Applying: Small tweaks
Applying: Refactor UpdateFocus code into ViewExtensions
Applying: Add tests
Using index info to reconstruct a base tree...
M src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs
M src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Android.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Android.cs
CONFLICT (content): Merge conflict in src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Android.cs
Auto-merging src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs
CONFLICT (content): Merge conflict in src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0008 Add tests
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@PureWeen an error occurred while backporting to net7.0, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
Show keyboard on Android entry/editor/searchbar focus <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #5983 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
Description of Change
Show keyboard on Android entry/editor/searchbar focus
Issues Fixed
Fixes #5983