Skip to content

Commit

Permalink
add todo demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Tw1stFate committed Jan 6, 2022
1 parent 52057ae commit 2ddd3ae
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
8 changes: 8 additions & 0 deletions SwiftUI-Apprentic/SwiftUI-Apprentic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
5E553AD62764D54400443127 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5E553AD52764D54400443127 /* Assets.xcassets */; };
5E553AD92764D54400443127 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5E553AD82764D54400443127 /* Preview Assets.xcassets */; };
5EAB840E27871ED80056C827 /* TodoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EAB840D27871ED80056C827 /* TodoView.swift */; };
5EAB8411278723840056C827 /* TodoDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EAB8410278723840056C827 /* TodoDetailView.swift */; };
5EAB8413278723BA0056C827 /* AddTodoItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EAB8412278723BA0056C827 /* AddTodoItemView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -21,6 +23,8 @@
5E553AD52764D54400443127 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5E553AD82764D54400443127 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
5EAB840D27871ED80056C827 /* TodoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoView.swift; sourceTree = "<group>"; };
5EAB8410278723840056C827 /* TodoDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoDetailView.swift; sourceTree = "<group>"; };
5EAB8412278723BA0056C827 /* AddTodoItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddTodoItemView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -98,6 +102,8 @@
isa = PBXGroup;
children = (
5EAB840D27871ED80056C827 /* TodoView.swift */,
5EAB8410278723840056C827 /* TodoDetailView.swift */,
5EAB8412278723BA0056C827 /* AddTodoItemView.swift */,
);
path = Todo;
sourceTree = "<group>";
Expand Down Expand Up @@ -180,9 +186,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5EAB8413278723BA0056C827 /* AddTodoItemView.swift in Sources */,
5EAB840E27871ED80056C827 /* TodoView.swift in Sources */,
5E553AD42764D54300443127 /* HomePage.swift in Sources */,
5E553AD22764D54300443127 /* SwiftUI_ApprenticApp.swift in Sources */,
5EAB8411278723840056C827 /* TodoDetailView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// AddTodoItem.swift
// SwiftUI-Apprentic
//
// Created by zzz on 2022/1/6.
//

import SwiftUI

struct AddTodoItemView: View {
@State var content = ""

var body: some View {
VStack(alignment: .leading) {
TextField("Enter your todo item", text: $content)
.padding()
Button {
// save todo item
} label: {
Image(systemName: "plus")
.padding()
.foregroundColor(.white)
.background(Color.red)
.cornerRadius(10)
}
Spacer()
}
.padding()
.background(Color.green)
}
}

struct AddTodoItem_Previews: PreviewProvider {
static var previews: some View {
AddTodoItemView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// TodoDetailView.swift
// SwiftUI-Apprentic
//
// Created by zzz on 2022/1/6.
//

import SwiftUI

struct TodoDetailView: View {
var content: String

var body: some View {
Text(content)
}
}

struct TodoDetailView_Previews: PreviewProvider {
static var previews: some View {
TodoDetailView(content: "")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,28 @@
import SwiftUI

struct TodoView: View {
@State var showAddTodoItemView = false

var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
NavigationView {
List {
NavigationLink(destination: TodoDetailView(content: "content")) {
HStack {
Image(systemName: "circle")
Text("Study")
}
}
}
.navigationTitle("Todo")
.navigationBarItems(trailing: Button(action: {
showAddTodoItemView.toggle()
}, label: {
Image(systemName: "plus")
}))
.sheet(isPresented: $showAddTodoItemView) {
AddTodoItemView()
}
}
}
}

Expand Down

0 comments on commit 2ddd3ae

Please sign in to comment.