UITextInteraction doesn't support physical keyboards?

Has anyone had any luck adopting UITextInteraction?


Selection changes made via touch work (mostly) as advertised, but changes made programmatically or via a physical keyboard do not.


I believe I've set this up properly. When adding a UITextInteraction to a custom text view that supports UITextInput, iOS installs the following interactions:


UITextInteraction
_UITextMenuLinkInteraction
UIContextMenuInteraction
_UIClickPresentationInteraction
_UIClickInteraction
UITextInteraction
UITextSelectionInteraction
UITextLoupeInteraction
UITextServicesInteraction
UITextIndirectKeyboardInteraction


The touch-related UI seems to work.


  • Tapping on the custom text view causes it to become first responder. A UITextSelectionView is installed as a subview, and the caret appears on the screen at the correct location. The caret can be dragged to a new location as expected.
  • Tapping a second time causes the Select/Select All menu to appear.
  • Double-tapping causes a UITextRangeView to be added, along with the appropriate UISelectionGrabberDot and UISelectionGrabber instances and the Cut/Copy… menu appears as expected. Moving handles via touch also works.


However, when a physical keyboard like the Smart Folio is attached, pressing the arrow keys has no effect on the selection UI. The setSelectedTextRange: method is called, but the caret or selection handles do not update.


Similarly, invoking setSelectedTextRange: programmatically (and calling the appropriate selectionWillChange:/selectionDidChange: methods) does not cause the selection UI to update. For example, choosing Select from the text menu supplied by the interaction invokes the select: method defined in UIResponderStandardEditActions (which is as expected), but setting the selectedTextRange and notifying the inputDelegate has no effect.


Since UITextSelectionView and UITextRangeView are private classes, it's not possible to update them from setSelectedTextRange. Setting needsLayout doesn't seem to work either.


Is there another way to update the selection UI when setting the text selection programmatically or via a physical keyboard?


-Steve

Hi Steve,


I am experiencing the same dilemma. Custom UITextInput implemenation + UITextInteraction. Typing moves the cursor, selection rects work, ... . What doesn't work:


- programmatically changing selectedTextRange does not change the cursor or selection rects. For example, in selectAll: method.

- Tap and hold spacebar, then dragging finger to change selection changes the selectedTextRange, but has no visual effect


I noticed that if I call:


removeInteraction(textInteraction)

addInteraction(textInteraction)


after changing the selectedTextRange the selection updates visually. However, this obviously does not feel right. Also, if I call this in updateFloatingCursor(at point: CGPoint), the selection visually updates with the space bar gesture, but does not seem to be super smooth.


I wonder if I am missing something in the UITextInput implementation that would trigger UITextInteraction to draw?


Till

As of 13.5, the shortcuts situation has improved, though there are still some issues with Emacs-style shortcuts. Here's the relevant Feedback Assistant id.

FB7655372 - UITextInteraction is missing support for supported keyboard shortcuts

And some related bug reports.

FB7657103 - UITextInteraction does not respect the tintColor of the view to which it is attached

FB7637400 - UITextInteraction doesn't support autoscroll

FB7637377 - UITextInteraction doesn't account for scale changes

I wrote about these (along with some work-arounds) in a blog post in case it helps. The forums won't let me include the link, but you can find it at steveshepard dot com.

Steve
UITextInteraction doesn't support physical keyboards?
 
 
Q