Skip to content
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

Merged
merged 36 commits into from
Mar 9, 2023

Conversation

rachelkang
Copy link
Member

@rachelkang rachelkang commented Jan 24, 2023

Description of Change

Show keyboard on Android entry/editor/searchbar focus

Issues Fixed

Fixes #5983

@rachelkang rachelkang requested a review from PureWeen January 24, 2023 19:22
@Eilon Eilon added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Jan 24, 2023
@rachelkang rachelkang force-pushed the show-keyboard-on-android-focus branch from e7464bf to 54addf0 Compare February 7, 2023 20:08
@rachelkang rachelkang marked this pull request as ready for review February 7, 2023 20:36
@github-actions
Copy link
Contributor

⚠️ Your code has been reformatted. ⚠️

@rachelkang rachelkang requested a review from PureWeen February 16, 2023 21:47
Copy link
Member

@PureWeen PureWeen left a 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.

image

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

@rachelkang
Copy link
Member Author

@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

@github-actions
Copy link
Contributor

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
Copy link
Member Author

@rachelkang rachelkang Feb 21, 2023

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

@rachelkang rachelkang requested a review from PureWeen February 21, 2023 22:44
src/Controls/src/Core/VisualElement.cs Outdated Show resolved Hide resolved
@rachelkang rachelkang requested a review from PureWeen February 23, 2023 18:18
@@ -17,5 +18,28 @@ Task<string> GetPlatformText(SearchBarHandler handler)
{
return InvokeOnMainThreadAsync(() => GetPlatformControl(handler).Query);
}

[Fact]
public async Task ShowsKeyboardOnFocus()
Copy link
Member

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.

@rachelkang rachelkang requested a review from PureWeen February 28, 2023 17:26
@github-actions
Copy link
Contributor

Thank you for your pull request. We are auto-formating your source code to follow our code guidelines.


var windowToken = inputView.WindowToken;
if (windowToken != null && inputMethodManager != null)
using (var inputMethodManager = (InputMethodManager)context.GetSystemService(Context.InputMethodService)!)
Copy link
Member

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)!)
Copy link
Member

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.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2023

Thank you for your pull request. We are auto-formatting your source code to follow our code guidelines.

@PureWeen PureWeen merged commit 20f54bc into main Mar 9, 2023
@PureWeen PureWeen deleted the show-keyboard-on-android-focus branch March 9, 2023 14:39
@PureWeen PureWeen added the backport/suggested The PR author or issue review has suggested that the change should be backported. label Mar 9, 2023
@PureWeen
Copy link
Member

PureWeen commented Mar 9, 2023

/backport to net7.0

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2023

Started backporting to net7.0: https://github.com/dotnet/maui/actions/runs/4376306063

@PureWeen PureWeen added the backport/approved After some discussion or review, this PR or change was approved to be backported. label Mar 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2023

@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!

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2023

@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.

@rachelkang rachelkang restored the show-keyboard-on-android-focus branch March 9, 2023 16:06
rachelkang pushed a commit that referenced this pull request Mar 9, 2023
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.
-->
rachelkang added a commit that referenced this pull request Mar 13, 2023
PureWeen pushed a commit that referenced this pull request Mar 14, 2023
@samhouts samhouts deleted the show-keyboard-on-android-focus branch July 28, 2023 19:48
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
@samhouts samhouts added the fixed-in-8.0.0-preview.3.8149 Look for this fix in 8.0.0-preview.3.8149! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-editor Editor backport/approved After some discussion or review, this PR or change was approved to be backported. backport/suggested The PR author or issue review has suggested that the change should be backported. fixed-in-8.0.0-preview.3.8149 Look for this fix in 8.0.0-preview.3.8149! platform/android 🤖
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Soft Keyboard does not Pop Up when Entry View's Focus is set to True Programmatically
6 participants