iosiphoneuitextview

UITextView, enabling paste force enables memojis & stickers


While testing some issue I discovered that enabling paste in the canPerformAction override in a UITextView force enables the memojis and stickers sections in the iOS Keyboard. Even though they are disabled in the iOS Keyboard Settings.

iOS Settings:

settings

Keyboard code:

import UIKit

class CustomTextView: UITextView {

  override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    if action == #selector(paste(_:))
    {
      return true
    }

    // Allow other actions
    return super.canPerformAction(action, withSender: sender)
  }
}

Results in the sticker buttons being shown:

stickers buttons showing

Whereas without that piece code the setting is ignored either way:

buttons not shown

This is super weird behavior and wildly inconsistent but I cannot find any information on how to handle this cases. Anyone knows how to properly display the keyboard respecting user settings? WhatsApp, Telegram and other apps handle the keyboard setting correctly, so I'm wondering what's the workaround they use, I don't think they are using private APIs.

Here is a small reproducible example


Solution

  • After scouring through the Telegram various UITextView implementations I stumbled into one that set the supportsAdapativeImageGlyph property after setting this to false and enabling the paste action, the keyboard now behaves correctly

    if #available(iOS 18.0, *) {
        self.supportsAdaptiveImageGlyph = false
    }
    

    Here is the commit that fixes the behavior on the reproducible example