I was making a sources tab to configure your files and I scripted it that when you press the plus button, a sheet will appear. And you could set the source's title using a TextField, and when you press "Add Source" it will add a source and I made it that it changes the source's title into just a blank so when trying to add a source you don't need to delete the text from the TextField. But when I press when you press "Add Source" it changes the previous Source Name/
This is the code:
import SwiftUI
struct ContentView: View {
// Source
@State var AddingSourceSheet = false
@AppStorage("SourceName") var SourceName = ""
@AppStorage("Sources") private var Sources = 0
var body: some View {
NavigationView {
List {
// Packages
Section(header: Text("Packages")) {
NavigationLink(destination: List {
// Configuration
Section(header: Text("Configuration")) {
NavigationLink(destination: List {
Text("Test")
}) {
HStack {
ZStack {
RoundedRectangle(cornerRadius: 5)
.frame(width: 40, height: 40)
.foregroundColor(.gray)
.aspectRatio(contentMode: .fit)
Image(systemName: "screwdriver.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 30, height: 30)
.foregroundColor(.white)
}
VStack(alignment: .leading) {
Text("Configuration")
.font(.system(size: 18, weight: .bold, design: .monospaced))
.padding(0.0)
Text("Configure Your Sources")
.font(.system(size: 16, weight: .regular, design: .monospaced))
.foregroundColor(.secondary)
}
}
}
}
// Sources
Section(header: Text("Sources")) {
ForEach(0..<Sources, id: \.self) { SourcesList in
Text(SourceName)
}
}
.navigationTitle("Sources")
// Toolbar
} .toolbar {
Button() {
AddingSourceSheet = true
} label: {
Label("Add Source", systemImage: "externaldrive.fill.badge.plus")
}
}
) {
HStack {
ZStack {
RoundedRectangle(cornerRadius: 5)
.frame(width: 30, height: 30)
.foregroundColor(.gray)
Image(systemName: "mail.and.text.magnifyingglass.rtl")
.foregroundColor(.white)
.scaledToFit()
}
Text("Sources")
}
}
}
// Sheets
.sheet(isPresented: $AddingSourceSheet) {
List {
// Title and description
HStack {
ZStack {
// Icon Placed Here
}
VStack(alignment: .leading) {
Text("Add Source")
.font(.system(size: 40, weight: .bold, design: .monospaced))
Text("Add a source to a URL")
.font(.system(size: 20, weight: .regular, design: .monospaced))
}
}
TextField("Source Name", text: $SourceName)
Button("Add Source", action: {
Sources += 1
AddingSourceSheet = false
SourceName = ""
} )
}
}
}
.navigationTitle("FolderConfig")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Its kinda long because I need to organize it.