Last active
August 30, 2020 00:52
-
-
Save laevandus/4f4df2f88f56bdbc2bff13f754682b8a 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 { | |
@State private var textMinWidth: CGFloat? | |
var body: some View { | |
VStack(spacing: 16) { | |
TextBubble(text: "First", minTextWidth: $textMinWidth) | |
TextBubble(text: "Second longer", minTextWidth: $textMinWidth) | |
} | |
} | |
} | |
struct TextBubble: View { | |
let text: String | |
let minTextWidth: Binding<CGFloat?> | |
var body: some View { | |
Text(text).equalWidth(minTextWidth) // custom view modifier | |
.foregroundColor(Color.white) | |
.padding() | |
.background(Color.blue) | |
.cornerRadius(8) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment