SwiftyFORM icon indicating copy to clipboard operation
SwiftyFORM copied to clipboard

TextView looses focus after first character entry

Open justdan0227 opened this issue 2 years ago • 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?

justdan0227 avatar Aug 27 '21 13:08 justdan0227

What is your iOS version?

Never seen this behavior iirc.

neoneye avatar Aug 27 '21 13:08 neoneye

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 avatar Aug 27 '21 14:08 justdan0227

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)

justdan0227 avatar Aug 27 '21 14:08 justdan0227

This seems like a good solution.

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

neoneye avatar Aug 27 '21 15:08 neoneye

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?

justdan0227 avatar Nov 22 '21 13:11 justdan0227

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.

neoneye avatar Nov 22 '21 16:11 neoneye