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

Updating maxHeight should cause layoutSubviews to be called immediately #14

Closed
Daltron opened this issue Jul 28, 2017 · 9 comments
Closed

Comments

@Daltron
Copy link

Daltron commented Jul 28, 2017

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! 👍

@KennethTsang
Copy link
Owner

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.

@Daltron
Copy link
Author

Daltron commented Jul 31, 2017

@KennethTsang Thanks for doing this so quickly. Unfortunately, there were some weird side effects with that commit.

  1. I'm getting a EXC_BAD_ACCESS when setting maxHeight:

screen shot 2017-07-31 at 8 22 24 am

  1. When pasting into my textview, this now happens:
    img_0419 png

When it should be this:
img_0420 png

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! 👍

@KennethTsang
Copy link
Owner

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. 😀

@Daltron
Copy link
Author

Daltron commented Jul 31, 2017

@KennethTsang Even after deleting the DerivedData folder, both issues are still occurring

@KennethTsang
Copy link
Owner

@Daltron are you using storyboard? Could you make sure the "Module" field was set as "GrowingTextView"?
screen shot 2017-08-01 at 9 42 31 am

@Daltron
Copy link
Author

Daltron commented Aug 1, 2017

@KennethTsang I do not use storyboards. I do everything programatically.

@Daltron
Copy link
Author

Daltron commented Aug 1, 2017

@KennethTsang I assume we are talking about the EXC_BAD_ACCESS issue. Are you not seeing the pasting issue as well?

@KennethTsang
Copy link
Owner

@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.

@Daltron
Copy link
Author

Daltron commented Aug 4, 2017

@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.

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