Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public typealias AppleDocument = UIDocument
import Combine
import Artboard

public class VODesignDocument: AppleDocument, VODesignDocumentProtocol {
public class VODesignDocument: AppleDocument , VODesignDocumentProtocol {

// MARK: - Data
public var elements: [any ArtboardElement] = []
Expand Down
58 changes: 53 additions & 5 deletions Shared/Sources/NavigatorSwiftUI/Navigator.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,67 @@
import SwiftUI
import Artboard

struct HierarchicalElement: Identifiable { //Structure creating element (similarity of a binary tree node)
var element: any ArtboardElement
var indentationLevel: Int
var isParent: Bool
var id: UUID { element.id }
Comment on lines +4 to +8
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нам бы вот этот интерфейс натянуть прямо на объект, свойства сделать вычисляемыми. Тогда получится что при перетаскивании мы можем влиять на сам фрейм и его обновление будет обновляться и в других частях.

}

public struct NavigatorView: View {

@ObservedObject var frame: Frame

@State private var hierarchicalElements: [HierarchicalElement]

public init(frame: Frame) {
self.frame = frame
_hierarchicalElements = State(initialValue: frame.elements.map {
HierarchicalElement(element: $0, indentationLevel: 0, isParent: false)
})
}

public var body: some View {
Text(frame.label)
List(frame.elements, id: \.id) { frame in
Text(frame.label)
// TODO: Add detalisation for elements inside frame
List {
ForEach($hierarchicalElements, id: \.element.id) { $element in
HStack {
Image(systemName: element.isParent ? "folder" : "doc") // Images for creating hiererchy folders
.onTapGesture {
element.isParent.toggle()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По тапу необычно, но я думаю, что так не надо. Лучше при редактировании списка дать выделять несколько компонентов, а в тулбаре показывать кнопку group, так поведение будет более системным, а значит и предсказуемым

}
Text(element.element.label)
}
.padding(.leading, CGFloat(element.indentationLevel * 20))
Comment on lines +26 to +33
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это стоит вынести в отдельную вью

.onDrag {
return NSItemProvider(object: String(element.id.uuidString) as NSString) //Data encapsulation
}
}
.onMove(perform: move)
}
.toolbar {
EditButton()
}
}

func move(from source: IndexSet, to destination: Int) {
hierarchicalElements.move(fromOffsets: source, toOffset: destination)

updateIndentationLevels()
}
Comment on lines +45 to +49
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Само перемещение хорошо работает, но тут лучше вызывать метод перезентера, чтобы он внутри фрейма данные переставлял


func updateIndentationLevels() {
var currentIndentationLevel = 0
var isPreviousElementParent = false

for index in hierarchicalElements.indices {
if isPreviousElementParent {
currentIndentationLevel += 1
} else {
currentIndentationLevel = 0
}
Comment on lines +56 to +60
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот эта логика в презентере уже есть


hierarchicalElements[index].indentationLevel = currentIndentationLevel
isPreviousElementParent = hierarchicalElements[index].isParent
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DocumentBrowserViewController: UIDocumentBrowserViewController, UIDocument
super.viewDidAppear(animated)

#if targetEnvironment(simulator) && (os(visionOS) || os(iOS)) // Fake document for simulaton, drag'n'drop won't work
presentDocumentModally(url: URL(filePath: "/Users/mikhail/Library/Mobile Documents/iCloud~com~akaDuality~VoiceOver-Designer/Documents/Drinkit Product Card.vodesign"), animated: true)
presentDocumentModally(url: URL(filePath: "/Users/mac/Projects/Drinkit Product Card.vodesign"), animated: true)
#endif
}

Expand Down