Created
December 7, 2020 05:12
-
-
Save emma-k-alexandra/dcabd4d6ee8582ec9e6c1833fb8dc374 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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