macteo / Marklight

Markdown syntax highlighter for iOS
Other
638 stars 44 forks source link

Dynamic height view #14

Closed Dan2552 closed 6 years ago

Dan2552 commented 7 years ago

Marklight looks great, fantastic work!

When using a plain UITextView, as I type the size of the view changes to fit the content/text of the view. When enabling Marklight, this behaviour seems to stop. Do you know what could be causing this?

Only constraints for the view in question are (using PureLayout):

view.autoPinEdge(.top, to: .bottom, of: previousView, withOffset: 8)
view.autoPinEdge(toSuperviewEdge: .left, withInset: 8)
view.autoPinEdge(toSuperviewEdge: .right, withInset: 8)
macteo commented 7 years ago

Hello, could you link to a sample project with the two different behaviours? Thanks

Dan2552 commented 7 years ago

Thanks for your time.

Here's a sample project: https://www.dropbox.com/s/dj4y5s47f62n9m9/MarklightExample.zip?dl=1

macteo commented 6 years ago

Hello, the order is important, I've changed the sample project you provided with this code (taken from the provided Marklight Sample project) and the grow seems to work perfectly.

    private func insert(_ text: String) {
    let layoutManager = NSLayoutManager()

    let textStorage = MarklightTextStorage()
    // Assign the `UITextView`'s `NSLayoutManager` to the `NSTextStorage` subclass
    textStorage.addLayoutManager(layoutManager)

    let textContainer = NSTextContainer()
    layoutManager.addTextContainer(textContainer)

    let view = UITextView(frame: CGRect(x: 0, y: 0, width: 100, height: 20), textContainer: textContainer)

    // let view = UITextView()
    view.isScrollEnabled = false

    let last = scrollView.subviews.last!
    scrollView.addSubview(view)

    view.autoPinEdge(.top, to: .bottom, of: last, withOffset: 8)
    view.autoPinEdge(toSuperviewEdge: .left, withInset: 8)
    view.autoPinEdge(toSuperviewEdge: .right, withInset: 8)
}

simulator screen shot - iphone 8 - 2017-09-20 at 12 35 17

I'm closing the issue as it seems that it was caused by a wrong client-side implementation.