Last active
February 15, 2020 23:16
-
-
Save GeekAndDad/d7fc6c8540bec70737de92e7743b89b6 to your computer and use it in GitHub Desktop.
Quick hack Mac app to put up a sheet with multi-line text.
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
import SwiftUI | |
struct ContentView: View { | |
@State private var showSheet: Bool = false | |
@State private var name: String = "Default Name" | |
var body: some View { | |
VStack { | |
Text("Hello, World!") | |
.frame(maxWidth: .infinity, maxHeight: .infinity) | |
Button(action: { | |
self.showSheet = true | |
}, label: { Text("Alert me!") }) | |
Spacer() | |
} | |
.sheet(isPresented: $showSheet, content: { TestSheet(name: self.$name) }) | |
} | |
struct TestSheet: View { | |
@Environment(\.presentationMode) var presentationMode | |
@Binding var name: String | |
@State var localName: String = "" | |
var body: some View { | |
VStack(alignment: .leading, spacing: 10) { | |
Text("Title Text") | |
.fontWeight(.bold) | |
Text("InfoText needs to be long enough that it should wrap so let's do that now. One would hope that this would be enough text... [END]") | |
.font(.caption) | |
.multilineTextAlignment(.leading) | |
TextField("", text: $localName) | |
HStack { | |
Button(action: { | |
self.presentationMode.wrappedValue.dismiss() | |
}, label: { | |
Text("Cancel") | |
}) | |
Spacer() | |
Button(action: { | |
self.name = self.localName | |
self.presentationMode.wrappedValue.dismiss() | |
}, label: { | |
Text("Save") | |
}) | |
.frame(alignment: .trailing) | |
} | |
} | |
.frame(width: 400) | |
.padding() | |
.onAppear { | |
self.localName = self.name | |
} | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out it's the line 48 that makes it work.
Others are using
.fixedSize(horizontal: false, vertical: true)
to make theirs work but that makes the sheet sizing go crazy for me. ¯_(ツ)_/¯