neoneye / SwiftyFORM

iOS framework for creating forms
MIT License
1.07k stars 87 forks source link

TextView looses focus after first character entry #61

Open justdan0227 opened 3 years ago

justdan0227 commented 3 years ago

I've noticed that if you use a TextView, that when you put the cursor in the field and start to type, that after the first character focus is lost. If you click the field again you can then continue typing. It's only on the first character the first time.
I notice that if you go into the example, and try the textview this happens. What is odd is that if you hit clear at the start then the field works correctly. Its only when it has an initial value in it and you start typing that the focus is lost.

Thoughts?

neoneye commented 3 years ago

What is your iOS version?

Never seen this behavior iirc.

justdan0227 commented 3 years ago

ios 15.

So I found that inside of TextViewCell.swift that that lines:

    public func updateValue() {
        let s = textView.text ?? ""
        let hasText = !s.isEmpty
        placeholderLabel.isHidden = hasText

        let tableView: UITableView? = form_tableView()
        if let tv = tableView {
            setNeedsLayout()
            tv.beginUpdates()
            tv.endUpdates()
        }
    }

that if I comment this out it works?

// let tableView: UITableView? = form_tableView() // if let tv = tableView { // setNeedsLayout() // tv.beginUpdates() // tv.endUpdates() // }

justdan0227 commented 3 years ago

The keyboard is getting dismissed for some reason (turn on soft keyboard in the simulator, and you'll see it get dismissed the first time)

neoneye commented 3 years ago

This seems like a good solution.

Unfortunately I can't remember why I put the code there to begin with.

justdan0227 commented 2 years ago

So I've been running with this for several months now and can not tell that it breaks anything. Can we get that put into the master branch?

neoneye commented 2 years ago

Unfortunately commenting out the code breaks the existing behavior, and places the cursor in the left-side of the screen, barely visible.

Left side: code is commented out.

Right side: the original code.

Screen Shot 2021-11-22 at 17 02 42

PRs are welcome.