Skip to content
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

Keyboard shifts vertically when it loads #88

Closed
wearhere opened this issue May 8, 2020 · 7 comments
Closed

Keyboard shifts vertically when it loads #88

wearhere opened this issue May 8, 2020 · 7 comments

Comments

@wearhere
Copy link
Contributor

wearhere commented May 8, 2020

Running the demo keyboard on master in the iPhone 11 Pro simulator, I see

The big vertical space that appears at the top looks kind of similar to the space allotted for the autocomplete toolbar, so I tried disabling that by commenting out this line. Curiously, that made the problem only more pronounced:

@danielsaidi
Copy link
Collaborator

I see this many versions back. However, it does not appear on hones with a home button.

Any ideas what may be causing this?

@wearhere
Copy link
Contributor Author

wearhere commented May 9, 2020

Not sure. One thing I thought I might try is forcing the keyboard to a certain height rather than letting the height be determined by auto-layout of the stack view's contents. Do you know how I might do this?

I cannot get the recommended solution for this (search "height" in this document) to work. Assuming that viewDidAppear satisfies that document's requirement of "adjust[ing] a custom keyboard’s height any time after its primary view initially draws on screen", this code (in a fresh keyboard extension, no other code than this)

class KeyboardViewController: UIInputViewController {
    var heightConstraint: NSLayoutConstraint?
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        if heightConstraint == nil, let view = view {
            let constraint = NSLayoutConstraint(item: view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 600)
            view.addConstraint(constraint)
            heightConstraint = constraint
        }
    }
}

causes the following error to appear

2020-05-09 15:38:54.010171-0700 Keyboard[32170:1265270] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x6000003f9680 UIInputView:0x7fdb6041fcd0.height == 600   (active)>",
    "<NSLayoutConstraint:0x6000003f03c0 'UIView-Encapsulated-Layout-Height' UIInputView:0x7fdb6041fcd0.height == 233   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000003f9680 UIInputView:0x7fdb6041fcd0.height == 600   (active)>

and I don't know how to resolve that. I've tried tweaking the priority of my constraint like this suggests but that seems to just make the error go away without making my constraint effective.

@wearhere
Copy link
Contributor Author

Ok I found that I can force the keyboard to a height by adding the constraint like

// In `KeyboardViewController#viewDidLoad`
view.heightAnchor.constraint(equalToConstant: 500).isActive = true

I still get the dueling constraints warning from the previous comment, but this height constraint wins out.

Doesn't fix the problem, unfortunately—the keyboard still shifts vertically. Doesn't seem to matter whether the forced height is greater or less than the system keyboard.

@wearhere
Copy link
Contributor Author

Alas, the shifting seems to be related to iOS removing its own autocomplete toolbar. With that setting (called "Predictive") disabled:

Much better, although still with a small shift upward (something else system-related?). Ah well. At least this is a clearer avenue for a Radar (I'll file at some point) and users who are bothered by the larger shift can be directed to disable the iOS setting.

@danielsaidi
Copy link
Collaborator

danielsaidi commented May 12, 2020

Annoying! I guess this is beyond the control of the library?

@wearhere
Copy link
Contributor Author

Yeah I guess so. Will close this out for now.

@danielsaidi
Copy link
Collaborator

Bummer :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants