dasautoooo / Parma

A SwiftUI view for displaying Markdown with customizable appearances.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ability to calculate the height of the view

alexjameslittle opened this issue · comments

I am planning to use this view to display messages as markdown in a UICollectionView cell that hosts a SwiftUI view. How would I be able to pre-calculate the required height this view will be based on a string and a constrained width?

Hi Alex! 👋

I don't think it has the ability to pre-calculate the size itself, because of the fact of SwiftUI; however, using GeometryReader to get the size is totally legit in the scenario.

For example:

struct ContentView: View {    
    var body: some View {
        GeometryReader { geo in
            Parma(markdown)
                .onAppear {
                    print(geo.size.height)
                }
        }
    }
}

Update the cell height when the view appears.