Skip to content

Instantly share code, notes, and snippets.

@thatswiftguy
Created April 11, 2021 16:19
Show Gist options
  • Save thatswiftguy/73dfa6236a0c1b72337035832d2b351d to your computer and use it in GitHub Desktop.
Save thatswiftguy/73dfa6236a0c1b72337035832d2b351d to your computer and use it in GitHub Desktop.
//
// MainViewModifier.swift
// TaskManager
//
// Created by Mohammad Yasir on 11/04/21.
//
import Foundation
import SwiftUI
struct MainViewModifier : ViewModifier {
@ObservedObject var taskVM : TaskViewModel
func body(content : Content) -> some View {
content
.navigationBarTitle("My Tasks")
.navigationBarItems(trailing: HStack(spacing:30){
EditButton()
.disabled(taskVM.tasks.isEmpty)
Button(
action : { taskVM.isPresented.toggle()},
label: {
Image(systemName: "plus")
.imageScale(.large)
})
})
.onChange(of: taskVM.sortType, perform: { _ in
guard !taskVM.tasks.isEmpty else { return }
withAnimation() {taskVM.sort()}
})
.fullScreenCover(isPresented: $taskVM.isPresented, content: {
AddTaskView(taskVM: taskVM)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment