I am trying out to implement a Mailview like I've seen in a tutorial before. After solving the layout, I tried to get some features on it.
If I begin to write a new message, I want to clear the filled Textfield boxes, when the user clicks the trash bin. But however I don't find out how to clear it.
import SwiftUI
var inboundMails = [[String()]]
var outboundMails = [[String()]]
struct ContentView: View {
@State var showComposeMessageView: Bool = false
var body: some View {
TabView
{
NavigationView
{
List (0 ..< 6)
{
_ in
NavigationLink(destination: Text("Nachrichtentext"))
{
SingleMessageView()
}
}
.listStyle(GroupedListStyle())
.navigationTitle("Inbox")
.navigationBarItems(trailing:
Button(action: { showComposeMessageView.toggle() }, label: {
Image(systemName: "square.and.pencil")
})
)
}
// Verfassen Button
.sheet(isPresented: $showComposeMessageView, content:
{
NewMessage()
}) //.sheet
.tabItem {
Image(systemName: "envelope.fill")
Text("Inbox")
}
Text("Sent")
.tabItem {
Text("Sent")
Image(systemName: "paperplane.fill")
}
}
}
}
// Design eines einzelnen Nachrichtenblocks
struct SingleMessageView: View {
var body: some View {
HStack
{
Image(systemName: "person.circle.fill")
.resizable()
.frame(width: 40, height: 40, alignment: .center)
.foregroundColor(.gray)
VStack(alignment: .leading)
{
HStack
{
Text("Absender")
.font(.headline)
Spacer()
Text("01-07-2020")
.font(.subheadline.monospacedDigit())
.foregroundColor(.secondary)
}
Text("Betreff")
.font(.subheadline)
.lineLimit(2)
}
}
}
}
//Neue Nachricht verfassen
struct NewMessage: View {
@State var messageText = ""
@State var betreff = ""
@State var cc = ""
@State var empfaenger = ""
@State var sendButton: Bool = false
var body: some View {
ZStack
{
Color.white
Spacer()
VStack(alignment: .leading)
{
// Kopfzeile
HStack(alignment: .top)
{
Spacer()
Image(systemName: "paperplane.circle")
.resizable()
.frame(width: 70, height: 70, alignment: .leading)
VStack(alignment: .leading)
{
Text("Empfänger: ")
Spacer()
Text("Betreff: ")
Spacer()
Text("CC:")
}.frame(height: 70)
VStack
{
TextField("Empfänger", text: $empfaenger).lineLimit(2)
.font(.subheadline)
Spacer()
TextField("Betreff", text: $betreff).lineLimit(2)
.font(.subheadline)
Spacer()
TextField("CC", text: $cc)
.font(.subheadline)
}.frame(height: 70)
}
.foregroundColor(.black)
.background(Color.white)
.font(.headline)
// Knöpfe
HStack
{
Spacer()
// Senden
Button(
action: { sendButton.toggle()
outboundMails = Mails().MailManager(inbound: false, from_to: empfaenger, cc: cc, subject: betreff, message: messageText, mailarray: outboundMails)},
label: {Image(systemName: "paperplane")})
.frame(width: 20, height: 20, alignment: .leading)
Spacer()
// Farbe bearbeiten
Button(
action: { sendButton.toggle() },
label: {Image(systemName: "pencil")})
.frame(width: 20, height: 20, alignment: .leading)
Spacer()
// Anlage hinzufügen
Button(
action: { sendButton.toggle() },
label: {Image(systemName: "doc")})
.frame(width: 20, height: 20, alignment: .leading)
Spacer()
// Verwerfen
Button(
action: { sendButton.toggle()
messageText = ""
cc = ""
betreff = ""
empfaenger = ""
},
label: {Image(systemName: "trash")})
.frame(width: 20, height: 20, alignment: .leading)
Spacer()
}.frame(height: 30, alignment: .top)
// NachichtentextFeld
TextEditor(text: $messageText)
.frame(width: 411, height: 400, alignment: .top)
.border(Color.gray)
Spacer()
}
}
}
}
// Design eines einzelnen Nachrichtenblocks
struct SendMessageView: View {
var body: some View {
HStack
{
Image(systemName: "person.circle.fill")
.resizable()
.frame(width: 40, height: 40, alignment: .center)
.foregroundColor(.gray)
VStack(alignment: .leading)
{
HStack
{
Text("Absender")
.font(.headline)
Spacer()
Text("01-07-2020")
.font(.subheadline.monospacedDigit())
.foregroundColor(.secondary)
}
Text("Betreff")
.font(.subheadline)
.lineLimit(2)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
} ```
Thanks in advance for your help!