Updating maxHeight should cause layoutSubviews to be called immediately
Daltron opened this issue ยท 9 comments
Hi @KennethTsang! ๐ First off, great job with this library! As the title suggests, I am suggesting that when the maxHeight is updated, that layoutSubviews be called immediately to update the heightConstraint. For my use case, I am working on something where the maxHeight of the text view is constantly changing depending on certain factors within my app.
Line 100 in GrowingTextView.swift
will need to be removed because even though the text and width may be the same, the maxHeight may not be.
Let me know what you think! ๐
Hi @Daltron, thank for your idea. I've updated GrowingTextView so it will trigger layoutSubviews after changing minHeight or maxHeight.
The "Line 100" cannot be remove because it prevent the layoutSubviews infinite loop #9 . As you mentioned, comparing width is not good, instead, I compare the size, so it would be better now.
@KennethTsang Thanks for doing this so quickly. Unfortunately, there were some weird side effects with that commit.
- I'm getting a EXC_BAD_ACCESS when setting maxHeight:
The text appears as normal as soon as a new line is added or removed to the textview.
I can confirm it is indeed the 0.3.0 release as I rolled back to 0.2.8 and pasting worked as expected. Let me know if you need any more information!
Thanks again! ๐
Hi @Daltron, I also got this error when I was testing today. After I empty the DerivedData folder, the problem has gone, please try it.
Please let me know if it is still not working. ๐
@KennethTsang Even after deleting the DerivedData folder, both issues are still occurring
@Daltron are you using storyboard? Could you make sure the "Module" field was set as "GrowingTextView"?
@KennethTsang I do not use storyboards. I do everything programatically.
@KennethTsang I assume we are talking about the EXC_BAD_ACCESS
issue. Are you not seeing the pasting issue as well?
@Daltron I know, so that was the way I fixed the EXC_BAD_ACCESS issue in my project using storyboard.
I have reviewed the code and also tested programmatically (without storyboard) and it works, see my codes below:
import GrowingTextView
import Cartography
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor(white: 0.92, alpha: 1)
let textView = GrowingTextView()
textView.minHeight = 30
textView.maxHeight = 80
view.addSubview(textView)
constrain(view, textView) { (view, textView) in
textView.top == view.top + 16
textView.left == view.left + 16
textView.right == view.right - 16
}
}
}
I still can't figure out why you got EXC_BAD_ACCESS. If you don't mind could you share your code? The possible reason I can imagine now may be something was calling in background thread or some particular sequence of setting up the textview.
@KennethTsang Thanks for the support but I went ahead and built a custom growing text view that fits with my app's needs a little bit better.