-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS] Fix Entry Next Keyboard Button Finds Next TextField #11914
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1e92437
Enable the Next button on keyboard to find next text field - ios
8583d30
Merge remote-tracking branch 'origin/main' into KeyboardNextReturnType
7ac22f7
Use the most top superview or allow user to specify
ff16920
Add message for IQKeyboard and stop the upward search as the Containe…
c988a6b
add ThirdPartyNotice.txt from Android repo
4a176a8
remove the ThirdPartyNotices.txt file for now
93512f9
address Shane comments and use more efficient search for next field
488812a
make the search modular and more generic to fit inside ViewExtensions.cs
b1042cd
Merge remote-tracking branch 'origin/main' into KeyboardNextReturnType
a52da3f
change signatures for tests
2828530
add third party notice
83fa0ee
Change names, support RightToLeft, loop back to beginning
23bd48e
add comment for IsRtl
84dfaf6
Use logical tree ordering, add more unit tests, and create horizontal…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * This class is adapted from IQKeyboardManager which is an open-source | ||
| * library implemented for iOS to handle Keyboard interactions with | ||
| * UITextFields/UITextViews. Link to their MIT License can be found here: | ||
| * https://github.com/hackiftekhar/IQKeyboardManager/blob/7399efb730eea084571b45a1a9b36a3a3c54c44f/LICENSE.md | ||
| */ | ||
|
|
||
| using System; | ||
| using UIKit; | ||
|
|
||
| namespace Microsoft.Maui.Platform; | ||
|
|
||
| internal static class KeyboardAutoManager | ||
| { | ||
| internal static void GoToNextResponderOrResign(UIView view, UIView? customSuperView = null) | ||
| { | ||
| if (!view.CheckIfEligible()) | ||
| { | ||
| view.ResignFirstResponder(); | ||
| return; | ||
| } | ||
|
|
||
| var superview = customSuperView ?? view.FindResponder<ContainerViewController>()?.View; | ||
| if (superview is null) | ||
| { | ||
| view.ResignFirstResponder(); | ||
| return; | ||
| } | ||
|
|
||
| var nextField = view.FindNextView(superview, view => | ||
| { | ||
| var isValidTextView = view is UITextView textView && textView.Editable; | ||
| var isValidTextField = view is UITextField textField && textField.Enabled; | ||
|
|
||
| return (isValidTextView || isValidTextField) && !view.Hidden && view.Alpha != 0f; | ||
| }); | ||
|
|
||
| view.ChangeFocusedView(nextField); | ||
| } | ||
|
|
||
| static bool CheckIfEligible(this UIView view) | ||
| { | ||
| if (view is UITextField field && field.ReturnKeyType == UIReturnKeyType.Next) | ||
| return true; | ||
| else if (view is UITextView) | ||
| return true; | ||
|
|
||
| return false; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -698,5 +698,66 @@ internal static void UpdateLayerBorder(this CoreAnimation.CALayer layer, IButton | |
| if (stroke.CornerRadius >= 0) | ||
| layer.CornerRadius = stroke.CornerRadius; | ||
| } | ||
|
|
||
| internal static T? FindResponder<T>(this UIView view) where T : UIResponder | ||
| { | ||
| var nextResponder = view as UIResponder; | ||
| while (nextResponder is not null) | ||
| { | ||
| nextResponder = nextResponder.NextResponder; | ||
|
|
||
| if (nextResponder is T responder) | ||
| return responder; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| internal static UIView? FindNextView(this UIView view, UIView superView, Func<UIView, bool> isValidType) | ||
| { | ||
| var passedOriginal = false; | ||
|
|
||
| var nextView = superView.FindNextView(view, ref passedOriginal, isValidType); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of always starting at the top level view and searching down to find your place can we start the search from where we are at and search out? This way we aren't always traversing the entire view stack? |
||
|
|
||
| // if we did not find the next view, try to find the first one | ||
| nextView ??= superView.FindNextView(null, ref passedOriginal, isValidType); | ||
|
|
||
| return nextView; | ||
| } | ||
|
|
||
| static UIView? FindNextView(this UIView view, UIView? origView, ref bool passedOriginal, Func<UIView, bool> isValidType) | ||
| { | ||
| foreach (var child in view.Subviews) | ||
| { | ||
| if (isValidType(child)) | ||
| { | ||
| if (origView is null) | ||
| return child; | ||
|
|
||
| if (passedOriginal) | ||
| return child; | ||
|
|
||
| if (child == origView) | ||
| passedOriginal = true; | ||
| } | ||
|
|
||
| else if (child.Subviews.Length > 0 && !child.Hidden && child.Alpha > 0f) | ||
| { | ||
| var nextLevel = child.FindNextView(origView, ref passedOriginal, isValidType); | ||
| if (nextLevel is not null) | ||
| return nextLevel; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| internal static void ChangeFocusedView(this UIView view, UIView? newView) | ||
| { | ||
| if (newView is null) | ||
| view.ResignFirstResponder(); | ||
|
|
||
| else | ||
| newView.BecomeFirstResponder(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.