-
Notifications
You must be signed in to change notification settings - Fork 6k
[iOS] Add UITextInteraction only when inputDelegate is nil
#32881
[iOS] Add UITextInteraction only when inputDelegate is nil
#32881
Conversation
jmagman
left a comment
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.
Was it an accident? #24224 (comment)
That comment says it was "delayed" not removed so maybe it was an accident?
Can you confirm this change doesn't regress
for some reason, the OS seems to be adding a grey shaded rectangle to the screen when using scribble to delete. I suspect it is related to autocorrect highlighting, but I'm not sure. So far I haven't been able to get rid of it. It does go away when tapping the screen again.
5386b20 to
b8319b5
Compare
|
@fbcouch it looks like the Japanese romaji keyboard needs the |
|
Hm. I didn't have another workaround, but – I notice you're just changing where the interaction gets set up. Is it possible to either detect the language the user is using and conditionally set up the UITextInteraction there, or add something to the framework that tells the engine that it needs that to be already available? |
|
The romaji keyboard doesn't seem to call any of |
|
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. |
This reverts commit f499993.
|
I wonder if we might be able to make use of https://developer.apple.com/documentation/uikit/uiscribbleinteraction/3566750-pencilinputexpected?language=objc somehow to conditionally set up the UITextInteraction...or, from reading your comment on the linked issue, is there a way to just not clear the |
|
Did a bit testing and flutter/flutter#99652 seems to be a UIKit bug. @fbcouch I have a (not so pleasant) workaround to reset the |
b4ffe70 to
64222c9
Compare
64222c9 to
517743a
Compare
The easiest way out is to keep the |
| if (!self.inputDelegate && self.isFirstResponder) { | ||
| NSAssert(!_restartingInputDelegate, @"setTextInputState is not re-entrant."); | ||
| _restartingInputDelegate = YES; | ||
| [self resignFirstResponder]; |
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.
For unknown reasons -[UIResponder reloadInputViews] does not work here (while it does set the inputDelegate when called in setTextInputClient:withConfiguration). -[UIKeyboardImpl setDelegate:force:] is called but it doesn't actually set inputDelegate to the receiver UIKeyboardImpl.
|
I guess I could add a dummy text interaction when the input delegate is being set to 0. I'll try that tomorrow |
I think the only issue is that there's a grey rectangle left over in some cases (maybe when deleting with scribble?) that goes away on the next interaction. I wonder if an alternative workaround would be to remove the interaction when a scribble interaction starts, then add it back when it ends? |
UITextInteraction backUITextInteraction only when inputDelegate is nil
| #pragma mark - Floating Cursor - Tests | ||
|
|
||
| - (void)testInputViewsHaveUIInteractions { | ||
| - (void)testInputViewsDoNotHaveUITextInteractions { |
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.
I can't think of a good way to test this.
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.
Well I guess I can verify setInputDelegate is called in setTextInputState. Let me do that.
a64b0c7 to
c15a69c
Compare
c15a69c to
3a9a7ca
Compare
| if (!_textInteraction) { | ||
| _textInteraction = | ||
| [[UITextInteraction textInteractionForMode:UITextInteractionModeEditable] retain]; | ||
| _textInteraction.textInput = self; |
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.
Does _textInteraction.textInput need to be nil'd out somewhere to break the retain cycle?
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.
https://developer.apple.com/documentation/uikit/uitextinteraction/3255084-textinput?language=objc this is a weak property and the framework is compiled with ARC so I assume it doesn't increase the retain count?
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.
👍 Thanks for checking.
Sorry that was supposed to be a comment not approval.
jmagman
left a comment
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.
LGTM
| if (!_textInteraction) { | ||
| _textInteraction = | ||
| [[UITextInteraction textInteractionForMode:UITextInteractionModeEditable] retain]; | ||
| _textInteraction.textInput = self; |
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.
👍 Thanks for checking.
TextEditingController.clearwith Japanese text input flutter#99652This pull request removes the
UITextInteractioninitialization in[FlutterTextInputView initWithOwner:]previously added toFlutterTextInputViewin #26486.When a certain
UITextInteractionis removed from the text input view, it (incorrectly?) setsinputDelegatetonilinstead of[UIKeyboardImpl activeInstance]. This workaround adds aUITextInteractionto the view when we needinputDelegatebut it's currentlynil(seesetTextInputState), so theUITextInteraction's setup process setsinputDelegateto aUITextInteractionInputDelegatewhich eventually notifies the current activeUIKeyboardImplin itsUITextInputDelegateimplementation. And we remove theUITextInteractionwhen we finish usinginputDelegate.A few observations:
UITextInteractionnow.inputDelegateis set to nil when the last/root text interaction is removed from the view. So another (easier) workaround for the issue is to add our ownUITextInteractionto the input view to make sure there's always oneUITextInteractioninstalled, but that adds unwanted visual artifacts during scribble.Pre-launch Checklist
writing and running engine tests.
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.