Devlog 10
NSCollectionView?!
While i was trying to refine the Grid View we made in the last devlog (handling selection, keyboard events, animations, etc), i learned about this AppKit view called NSCollectionView that does precisely what i wanted, it is even used in Finder’s grid view
For those of you who don’t know AppKit, it is an imperative UI framework made originally for NeXTSTEP (NS for NeXTSTEP btw) in 1988 but later became MacOS’s main UI framework
Now to use an AppKit View in SwiftUI you need something called NSViewRepresentable
Using this thing on its own is somewhat complex but to use it with NSCollectionView (which is alr a very involved AppKit view) proved to be a monumental task especially for me who had never touched AppKit before
So after wasting a lot of time trying to figure this out i just went back to the LazyVGrid approach and hopefully we can come back to this later
Adding Selection and Animation to LazyVGrid
I started by adding a selection effect to the grid, meaning that if you click on a program once a background appears behind it (look at the screenshot lol i can’t explain :<)
at first it was terribly slow to activate cuz we effectively had 2 .onTapGesture but then i found this solution on stackoverflow
.gesture(
TapGesture(count: 2).onEnded {
isRunning = true
Task.detached {
try await flask.runApp(programPath)
DispatchQueue.main.async {
isRunning = false
}
}
}
)
.simultaneousGesture(
TapGesture().onEnded {
selectedProgram = programPath
}
)
as for animation it was relatively easy, I just used PhaseAnimator to replicate the MacOS app jump effect
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.