-
Notifications
You must be signed in to change notification settings - Fork 0
sujileelea: Model, View 수정 및 Asset 추가 #5
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"originHash" : "f85ec36b55e6c3bddc4e146f4fc996922ed5c902954d863dc9c50577c5aae4c9", | ||
"pins" : [ | ||
{ | ||
"identity" : "popupview", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/exyte/PopupView.git", | ||
"state" : { | ||
"revision" : "8c85ff09d474dd3cfb69aba33046395bcf365573", | ||
"version" : "2.9.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "swiftui-introspect", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/siteline/swiftui-introspect", | ||
"state" : { | ||
"revision" : "0cd2a5a5895306bc21d54a2254302d24a9a571e4", | ||
"version" : "1.1.3" | ||
} | ||
} | ||
], | ||
"version" : 3 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>UTExportedTypeDeclarations</key> | ||
<array> | ||
<dict> | ||
<key>UTTypeConformsTo</key> | ||
<array> | ||
<string>com.public.data</string> | ||
</array> | ||
<key>UTTypeDescription</key> | ||
<string>TaskItem</string> | ||
<key>UTTypeIconFiles</key> | ||
<array/> | ||
<key>UTTypeIdentifier</key> | ||
<string>com.sujileelea.DragDrop.taskItem</string> | ||
<key>UTTypeTagSpecification</key> | ||
<dict/> | ||
</dict> | ||
</array> | ||
</dict> | ||
</plist> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,22 +7,33 @@ | |||||
|
||||||
import Foundation | ||||||
import SwiftData | ||||||
import UniformTypeIdentifiers | ||||||
import SwiftUI | ||||||
|
||||||
|
||||||
@Model | ||||||
class Task { | ||||||
class TaskData { | ||||||
var taskItems: [TaskItem]? | ||||||
|
||||||
init(taskItems: [TaskItem]? = nil) { | ||||||
self.taskItems = taskItems | ||||||
} | ||||||
} | ||||||
|
||||||
struct TaskItem: Equatable, Identifiable, Codable, Transferable { | ||||||
static var transferRepresentation: some TransferRepresentation { | ||||||
CodableRepresentation(for: TaskItem.self, contentType: .taskItem) | ||||||
} | ||||||
var id: String | ||||||
var name: String | ||||||
@Attribute(.unique) var category: String | ||||||
var category: String | ||||||
var isPinned: Bool { | ||||||
if category == "board" { | ||||||
return true | ||||||
} else { | ||||||
return false | ||||||
} | ||||||
} | ||||||
var isDone: Bool = false | ||||||
|
||||||
init(name: String, category: String) { | ||||||
self.name = name | ||||||
self.category = category | ||||||
return category == "board" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 디테일한 부분까지...🥹 감사합니다. |
||||||
} | ||||||
var isDone: Bool | ||||||
} | ||||||
|
||||||
extension UTType { | ||||||
static var taskItem = UTType(exportedAs: "com.sujileelea.DragDrop.taskItem") | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
// | ||
// EditPage.swift | ||
// BoardEditPage.swift | ||
// DragDrop | ||
// | ||
// Created by Suji Lee on 3/21/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct EditPage: View { | ||
struct BoardEditPage: View { | ||
@Environment(\.modelContext) private var modelContext | ||
|
||
var body: some View { | ||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) | ||
} | ||
} | ||
|
||
#Preview { | ||
EditPage() | ||
BoardEditPage() | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||||||||||
// | ||||||||||||||||
// MainPage.swift | ||||||||||||||||
// BoardPage.swift | ||||||||||||||||
// DragDrop | ||||||||||||||||
// | ||||||||||||||||
// Created by Suji Lee on 3/21/24. | ||||||||||||||||
|
@@ -8,10 +8,12 @@ | |||||||||||||||
import SwiftUI | ||||||||||||||||
import SwiftData | ||||||||||||||||
|
||||||||||||||||
struct MainPage: View { | ||||||||||||||||
struct BoardPage: View { | ||||||||||||||||
@Environment(\.modelContext) private var modelContext | ||||||||||||||||
// @Query private var tasks: [Task] | ||||||||||||||||
let today = Date().formatted(.iso8601.year().month().day()) | ||||||||||||||||
var tasks: [Task] = [Task(name: "one", category: "One"), Task(name: "two", category: "Two")] | ||||||||||||||||
@State var taskItems: [TaskItem] = [TaskItem(id: "1", name: "one", category: "iOS", isDone: false), TaskItem(id: "2", name: "two", category: "Year", isDone: false), TaskItem(id: "3", name: "three", category: "iOS", isDone: false)] | ||||||||||||||||
@State private var draggingItem: TaskItem? | ||||||||||||||||
|
||||||||||||||||
var body: some View { | ||||||||||||||||
NavigationView { | ||||||||||||||||
|
@@ -34,12 +36,33 @@ struct MainPage: View { | |||||||||||||||
} | ||||||||||||||||
//Board List | ||||||||||||||||
VStack { | ||||||||||||||||
List { | ||||||||||||||||
ForEach(tasks) { task in | ||||||||||||||||
TaskCard(task: task, isOnBoard: true) | ||||||||||||||||
ScrollView { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 38번째줄 indent가 잘못 적용된거 같아요. 전체적으로 들여쓰기 한번씩 단축키로 체크해주세요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이런 부끄러운 실수를...지적해주셔서 감사합니다.
Comment on lines
38
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. VStack 안에 ScrollView 밖에 없어서 불필요한거 같은데 의도하신게 아래 코드일까요? ScrollView {
LazyVStack { // lazy 하게 데이터 가져와서 불필요한 메모리 사용을 줄임
// ForEach ...
}
} 이게 아니라면 List(taskItems) { ... }
// 또는
List {
ForEach(taskItems) { ... } // 👈 이유는 모르겠으나 애플 샘플코드에는 List 를 이런식으로 쓰더라구요?
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기존에는 List였으나 draggable이 적용이 안돼서 ScrollView로 바꿨습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 List는 draggable 적용이 안되는군요! 하나 배워갑니다~ |
||||||||||||||||
ForEach(taskItems) { taskItem in | ||||||||||||||||
TaskCard(task: taskItem, isOnBoard: true) | ||||||||||||||||
.listRowBackground(Color.clear) | ||||||||||||||||
.draggable(taskItem) { | ||||||||||||||||
/// Custom Preview View | ||||||||||||||||
EmptyView() | ||||||||||||||||
.onAppear { | ||||||||||||||||
draggingItem = taskItem | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
.dropDestination(for: TaskItem.self) { items, location in | ||||||||||||||||
draggingItem = nil | ||||||||||||||||
return false | ||||||||||||||||
} isTargeted: { status in | ||||||||||||||||
if let draggingItem, status, draggingItem != taskItem { | ||||||||||||||||
/// Moving Color from source to destination | ||||||||||||||||
if let sourceIndex = taskItems.firstIndex(of: draggingItem), | ||||||||||||||||
let destinationIndex = taskItems.firstIndex(of: taskItem) { | ||||||||||||||||
Comment on lines
+54
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 중첩으로 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드가 간결해지겠네요 적용하겠습니다! |
||||||||||||||||
withAnimation(.bouncy) { | ||||||||||||||||
let sourceItem = taskItems.remove(at: sourceIndex) | ||||||||||||||||
taskItems.insert(sourceItem, at: destinationIndex) | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
.listRowSeparator(.hidden) | ||||||||||||||||
} | ||||||||||||||||
.cornerRadius(10) | ||||||||||||||||
} | ||||||||||||||||
|
@@ -59,5 +82,5 @@ struct MainPage: View { | |||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
#Preview { | ||||||||||||||||
MainPage() | ||||||||||||||||
BoardPage() | ||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ | |
import SwiftUI | ||
|
||
struct TaskCard: View { | ||
var task: Task | ||
|
||
var task: TaskItem | ||
var isOnBoard: Bool | ||
|
||
var body: some View { | ||
|
@@ -42,6 +43,6 @@ struct TaskCard: View { | |
} | ||
} | ||
|
||
#Preview { | ||
TaskCard(task: Task(name: "preview", category: "Preview"), isOnBoard: false) | ||
} | ||
//#Preview { | ||
// TaskCard(task: TaskItem(name: "preview", category: "Preview"), isOnBoard: false) | ||
//} | ||
Comment on lines
+46
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 안쓸거라면 주석보단 그냥 제거하는 것이 좋습니다. 사용할거라면 주석보단 수정하는 것이 좋구요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 수정하는 방향으로 적용하겠습니다! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import 구문에도 나열 규칙이 있다면 좋을 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전혀 고려하지 못했던 부분이네요. 퍼스트파티부터 순차적으로 나열하는 방법이 생각납니다.
혹시 재성님은 어떤식으로 하는지 여쭤볼 수 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
선호도에 따라 다른데
보통 formatting이나 linting 규칙에서는 두가지를 사용합니다
전 보통 길이순을 선호합니다. 알파벳순하면 새 모듈 임포트할때마다 머릿속으로 abc 세야해서...