Created
April 11, 2021 16:19
-
-
Save thatswiftguy/73dfa6236a0c1b72337035832d2b351d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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