[Lona Studio] Update the "add" menu when new components are created
dabbott opened this issue · comments
Summary
The "add" menu is used to add new instances of components, "layers", to the current component's layer hierarchy.
Currently the "add" menu only scans for custom components when the UI is instantiated. This means that when new components are created, moved, or deleted, it can become stale:
This is pretty annoying, and usually requires restarting the app to fix. Let's make it so that the menu updates automatically. We want it to look like this (which is how it looks if you restart the app):
Proposed Implementation
There are several steps involved, but most should reuse existing mechanisms in place for firing and responding to events.
-
I think we should add a new event, specifically to handle filesystem-level component changes, e.g. components being created, moved, deleted. We could call the event something like
onChange:fileSystem:components
. Events are defined here:
https://github.com/airbnb/Lona/blob/0571d6aa7c7796073eece13aa6a43acdb15840c7/studio/LonaStudio/Plugins/LonaPlugins.swift#L12 -
I think the simplest place to trigger the event is whenever the
FileNavigator
detects a change. For example, we could trigger it here to catch file deletions:
https://github.com/airbnb/Lona/blob/0571d6aa7c7796073eece13aa6a43acdb15840c7/studio/LonaStudio/Workspace/WorkspaceViewController.swift#L332 We would also want to add handlers foronCreateFile
andonMoveFile
(which will need to be propagated up from thefileTree
throughfileNavigator
, just likeonDeleteFile
). As an example of triggering events, see https://github.com/airbnb/Lona/blob/0571d6aa7c7796073eece13aa6a43acdb15840c7/studio/LonaStudio/Workspace/WorkspaceViewController.swift#L676 -
Now we can subscribe to this new event from within the
LayerListHeader
. Here's the call that populates the menu that needs to be re-run
https://github.com/airbnb/Lona/blob/0571d6aa7c7796073eece13aa6a43acdb15840c7/studio/LonaStudio/Workspace/LayerListHeader.swift#L43 We can subscribe to our new event ininit
and unsubscribe in adeinit
block. The file navigator demonstrates how to handle subscriptions https://github.com/airbnb/Lona/blob/0571d6aa7c7796073eece13aa6a43acdb15840c7/studio/LonaStudio/Workspace/FileNavigator.swift#L61-L65
We might run into issues along the way and have to change the plan, but let's start with this. Let me know if you run into anything weird!
I'd like to work on this issue.