-
Notifications
You must be signed in to change notification settings - Fork 10
SwiftUI Navigator #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: swiftui-navigator
Are you sure you want to change the base?
SwiftUI Navigator #332
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 |
|---|---|---|
| @@ -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 } | ||
| } | ||
|
|
||
| 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() | ||
|
Collaborator
Author
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. По тапу необычно, но я думаю, что так не надо. Лучше при редактировании списка дать выделять несколько компонентов, а в тулбаре показывать кнопку |
||
| } | ||
| Text(element.element.label) | ||
| } | ||
| .padding(.leading, CGFloat(element.indentationLevel * 20)) | ||
|
Comment on lines
+26
to
+33
Collaborator
Author
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. Это стоит вынести в отдельную вью |
||
| .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
Collaborator
Author
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. Само перемещение хорошо работает, но тут лучше вызывать метод перезентера, чтобы он внутри фрейма данные переставлял |
||
|
|
||
| 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
Collaborator
Author
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. Вот эта логика в презентере уже есть |
||
|
|
||
| hierarchicalElements[index].indentationLevel = currentIndentationLevel | ||
| isPreviousElementParent = hierarchicalElements[index].isParent | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
Нам бы вот этот интерфейс натянуть прямо на объект, свойства сделать вычисляемыми. Тогда получится что при перетаскивании мы можем влиять на сам фрейм и его обновление будет обновляться и в других частях.