Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import SwiftUI
struct Modifier: Identifiable
{
let id = UUID()
@State var title: String
}
struct FastnotesSettings: View
{
@State private var rows: [Modifier] = [Modifier(title:"Brightness"), Modifier(title:"Contrast"), Modifier(title:"Detail"), Modifier(title:"Saturation"), Modifier(title:"Sharpness"), Modifier(title:"Weight")]
@State private var editMode = EditMode.inactive
var body: some View
{
List {
Section {
ForEach(rows) { row in
TextField("Text", text: row.$title)
.disabled(editMode != .active)
}
.onMove(perform: move)
.onDelete(perform: delete)
}
Section {
HStack {
Spacer()
Button("Restore Default FastNotes Palette") {
withAnimation {
//self.model.reset()
}
}
Spacer()
}
}
}
.navigationBarItems(leading: addButton, trailing: EditButton())
.environment(\.editMode, $editMode)
.listStyle(GroupedListStyle())
.environment(\.horizontalSizeClass, .regular)
.navigationBarTitle("FastNotes", displayMode: .inline)
}
func move(from source: IndexSet, to destination: Int)
{
rows.move(fromOffsets: source, toOffset: destination)
}
func delete(from source: IndexSet)
{
rows.remove(atOffsets: source)
}
@ViewBuilder
private var addButton: some View
{
switch editMode {
case .active:
Button(action: onAdd)
{
Image(systemName: "plus")
}
.disabled(rows.count >= 10)
default:
EmptyView()
}
}
func onAdd()
{
withAnimation {
rows.append(Modifier(title:""))
}
}
}
struct FastNotesPalette_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
FastnotesSettings()
}
.navigationViewStyle(StackNavigationViewStyle())
.previewLayout(.fixed(width: 500, height: 600))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment