Skip to content

Instantly share code, notes, and snippets.

@emma-k-alexandra
Created December 7, 2020 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emma-k-alexandra/dcabd4d6ee8582ec9e6c1833fb8dc374 to your computer and use it in GitHub Desktop.
Save emma-k-alexandra/dcabd4d6ee8582ec9e6c1833fb8dc374 to your computer and use it in GitHub Desktop.
struct ContentView: View {
// The current height of the view
@State private var height: CGFloat = 0
var body: some View {
VStack {
GeometryReader { geometry in
// Needs to be .topLeading so we can modify alignments on top and leading
ZStack(alignment: .topLeading) {
...
}
.background(calculateHeight($height))
}
}.frame(height: height)
}
// Determine the height of the view containing our combined Text and Link views
func calculateHeight(_ binding: Binding<CGFloat>) -> some View {
GeometryReader { geometry -> Color in
DispatchQueue.main.async {
binding.wrappedValue = geometry.frame(in: .local).height
}
return .clear
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment