I've got a bit of a tricky situation here and I'm not having much luck finding a tutorial for it.
I'm creating an audiobook library manager app. I have a fairly standing 2-column NavigationView list/detail setup.
The detail view is a FlipCard view where the front of the card is the book cover and general title/author information, and the back of the card is the description/summary of the book and more obscure information (like the inside of a dust jacket or back cover of a paperback.)
So, say the user is looking at a book in the detail view. At the bottom of that detail view is a toolbar with buttons allowing the user to do things like navigate chapters or edit the book details. If the user taps the button to edit the book details, it presents a sheet that contains a tab view for general details, authors, narrators, etc.
This view has a top bar that shows in all tabs that allows the user to cancel or save their editing:
var body: some View {
VStack {
topBar
TabView(selection: $selection,
content: {
generalTab
.tabItem { Text("General") }
.tag(Tab.general)
authorsTab
.tabItem { Text("Authors") }
.tag(Tab.authors)
narratorsTab
.tabItem { Text("Narrators") }
.tag(Tab.narrators)
genresTab
.tabItem { Text("Gebres") }
.tag(Tab.genres)
summaryTab
.tabItem { Text("Summary") }
.tag(Tab.description)
})
}
}
private var topBar: some View {
HStack {
Button(
action: { cancel() },
label: {
Text("Cancel")
.font(.title3)
.bold()
})
Spacer()
Text(title)
Spacer()
Button(
action: { save() },
label: {
Text("Save")
.font(.title3)
.bold()
})
}.padding()
}
(layouts aren't fine-tuned yet, I'm working on functionality for the moment.)
I want to add the ability to add/remove/re-order the authors, but I'm not in a NavigationView, I'm in a tabView that is inside a modal/sheet view. I don't think I can activate EditMode in this view, can I? (or if so, nothing I've tried so far is correct.)
How would I go about synthesizing EditMode behavior for lists inside a sheet view?
@State private var authorEditing = EditMode.inactive
private var authorsTab: some View {
VStack(alignment: .leading) {
HStack {
Text("Authors")
.foregroundColor(.gray)
.font(.title2)
}.padding()
List {
ForEach(authors) {
LineRowView($0)
}
}
.listStyle(InsetListStyle())
.onAppear(perform: {
authors = book.authors
})
}
}