neoneye/SwiftyFORM

TextView looses focus after first character entry

justdan0227 opened this issue · 6 comments

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?

What is your iOS version?

Never seen this behavior iirc.

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()
// }

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)

This seems like a good solution.

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

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?

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.