'iOS custom keyboard height increases on every switch

I have a frustrating issue I have no idea how to solve

When working on a custom keyboard I discovered that on a particular screen - Apple Mail app Reply - custom keyboard gets an increase in height on every keyboard switch.

I narrowed it down to actually zero code

class KeyboardViewController: UIInputViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .yellow
    }
}

Almost everywhere it looks 'normally', that is, takes up the same size as the standard keyboard - e.g. the Messages app

enter image description here

But the Reply screen in the Apple Mail (and maybe few other places) after a few keyboard switches looks like this

enter image description here

What could be causing it?

FWIW the UIKit code that I tried a while ago has only a minimal issue of flashing, then instantly resizing to normal. My current production code is SwiftUI, and it's going to be a pain to rewrite everything back and even then it can return at any point because the zero code version also has this.

EDIT

Also tried the manual constraint path. It made no difference.

class KeyboardViewController: UIInputViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .yellow
        let constr = NSLayoutConstraint.init(item: self.view!, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0, constant: 66)
        constr.priority = .defaultHigh
        view.addConstraint(constr)
    }
}


Solution 1:[1]

What helped for me (as a workaround) was wrapping my SwiftUI with KeyboardKit. No idea still what to do with UiKit.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anton Duzenko