State Switch Master
Define different states and switch between them like a boss.
We all create different groups for states, toggle their visibility one by one to switch between states or create a copy of the artboard and put the other state there to save time and not repeating clicking progress.
When you choose the second one, bad sides are having duplicates and a crowded page. Doing this can be preferred when you need to see all the states side by side and thinking the big picture. But other than that, we need a tool or feature to create states and switch between them easily.
Let me to introduce you to my new Sketch plugin, which aims to solve this problem.
Let’s Go over an Example
Say, we are designing an app with two skins: day and night, and there is a button which has three states: normal, highlighted, disabled. Also, there are two different states of disabled state: normal and processing.
1. Creating State Reference Groups
Let’s begin with defining two terms:
- State reference group: A specially named group which its children or descendants are used to switch states. So these groups will be our switches.
- State layer: A specially named layer or group. It connects the state reference groups with real groups.
Here the state reference groups for our example:
As we did here, you can design nested states. Plugin supports unlimited nested states.
2. Binding State Reference Groups to Real Groups
Binding is like putting a note on a group which says “This group is connected to that state, oki doki?”. After binding, the plugin will know which ones to hide and which ones to show when switching the states. There are two commands for binding.
It’s very easy to bind, just select a layer from inside of a state reference group and press shift + control + C. Then select the group you want to bind and press shift + control + V. Voila! The plugin creates a state layer into the that group. You can create a state layer and name it yourself too, but this is way faster.
Note: GIF doesn’t show the whole process. Also, you can do this more efficiently, like setting one reference and using it in multiple groups.
Secret : Shift + Control + C = Shift + Control + V completely. I put two different commands, because it feels more natural in this way, like copying and pasting. If you prefer, use the same command for all.
3. Let’s Try!
4. Changing the Scope
Scope is the effect range of the state reference groups. There are three scopes: All Pages, Current Page, Artboard. You can switch between them by pressing shift + control + D.
For example, when you choose the artboard option, it only changes the states of the items which are located in the same artboard with the selected state reference groups.
Note to Sketch plugin developers: Avoid using dialog boxes as much as you can. For example for this command, I did it with dialog box and a combo box first. But then when I test, I realized that it can be much more productive and pleasing to use if I don’t ask what to select but just switching to the next.
Some Details and Suggestions
Be Careful with Naming
This plugin only works when layers in state reference groups and state layers in normal groups are named correctly. So if there is anything weird, check up this first. Names might be corrupted when changing stuff or hierarchies.
Every Step Has to be Bind
If one of the groups in a nested state group hasn’t been bind, it can break the spell.
You can create states in very different ways, it supports nested groups and multiple states in same group.
Changing Multiple States at the Same Time
You can do that.
Changing the Shortcuts
There are lots of plugins, so sometimes shortcuts overlap. If that happens or if you want to change the shortcuts, you can do that by:
- Sketch > Plugins > Reveal Plugin Folder…
- Find and right click on the file: State Switch Master.sketchplugin > Show Package Content.
- Contents > Sketch > manifest.json. (Open this with an editor.)
- Change the shortcuts and save. (You may need to click on the command manually in first use, sometimes it starts to effect after doing that.
Don’t Use This to Put Everything in One Artboard!
No need to explain this I think. Please don’t do it!
Download the Plugin and Example
You can download the example from here — it’s included in the plugin zip though.
Keep Informed / Send Suggestions
You can follow / contact me on Medium or Twitter. Also you can follow this publication:
Sketch, Form, iOS Development by Emin Inanc Unlu