Skip to content
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

[Lona Studio] Update the "add" menu when new components are created #338

Closed
dabbott opened this issue Mar 12, 2019 · 1 comment
Closed

Comments

@dabbott
Copy link
Member

dabbott commented Mar 12, 2019

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:

Screen_Shot_2019-03-12_at_10_27_51_AM

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):

Screen Shot 2019-03-12 at 10 37 50 AM

Proposed Implementation

There are several steps involved, but most should reuse existing mechanisms in place for firing and responding to events.

  1. 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

  2. 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 for onCreateFile and onMoveFile (which will need to be propagated up from the fileTree through fileNavigator, just like onDeleteFile). As an example of triggering events, see https://github.com/airbnb/Lona/blob/0571d6aa7c7796073eece13aa6a43acdb15840c7/studio/LonaStudio/Workspace/WorkspaceViewController.swift#L676

  3. 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 in init and unsubscribe in a deinit 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!

@vldmrkl
Copy link
Contributor

vldmrkl commented Mar 12, 2019

I'd like to work on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants