Created
November 16, 2024 03:51
-
-
Save Shubham0812/ebbe0ede436cd673f11dd7486b2cb91f to your computer and use it in GitHub Desktop.
MainView
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
| // | |
| // ContentView.swift | |
| // ToDo_UI | |
| // | |
| // Created by Shubham on 11/11/24. | |
| // | |
| import SwiftUI | |
| struct MainView: View { | |
| // MARK: - Variables | |
| @Environment(\.managedObjectContext) private var viewContext | |
| @State var mainViewModel: MainViewModel = .init() | |
| @State var taskManager: TaskManager = .init() | |
| @State var viewAppeared = false | |
| // MARK: - Views | |
| var body: some View { | |
| GeometryReader { proxy in | |
| let width: CGFloat = proxy.size.width - 52 | |
| ZStack(alignment: .topLeading) { | |
| Color.background | |
| .ignoresSafeArea() | |
| ScrollView(.vertical, showsIndicators: false) { | |
| VStack(alignment: .leading) { | |
| TopBarView() | |
| TaskListView(selectedDate: mainViewModel.selectedDate, width: width) | |
| .padding(.top, 12) | |
| } | |
| .padding(2) | |
| Spacer() | |
| .frame(height: 100) | |
| } | |
| .safeAreaPadding(.top, 12) | |
| .padding(.trailing, 24) | |
| .safeAreaPadding(.leading, 24) | |
| } | |
| .blur(radius: mainViewModel.addTask ? 4 : 0) | |
| .overlay { | |
| Color.label | |
| .ignoresSafeArea() | |
| .opacity(mainViewModel.addTask ? 0.5 : 0) | |
| } | |
| .overlay(alignment: .bottom) { | |
| TaskAddingView() | |
| .colorInvert() | |
| .offset(y: !mainViewModel.addTask ? 280 : 0) | |
| .frame(height: 320) | |
| } | |
| .environment(mainViewModel) | |
| .environment(taskManager) | |
| .onAppear() { | |
| viewAppeared.toggle() | |
| } | |
| } | |
| } | |
| } | |
| #Preview { | |
| MainView() | |
| .environment(\.managedObjectContext, PersistenceController.shared.container.viewContext) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment