Flatten Plugin for Sketch

Flatten single or multiple layers instantly, create shared artboard styles, keep them all updated like a boss and boost your Sketch documents’ performance.

5 min readJan 6, 2016

--

The Logic

Flatten plugin converts layers into images a little different than the default flattening action of the Sketch. Instead of deleting the targeted layer, it keeps the layer as hidden and use it to update the flattened image in the future.

Plugin puts the actual layer into a newly created group and use it when group is needed to be updated.

You can convert any layer, group or artboard into image. For converting to happen, the item has to include #flatten tag in its name.

So with this plugin, you don’t need to hide blurred layers for performance concerns. Just flatten them all and keep them updated easily.

Plugin Commands

1. Flatten

Shift ⇧ + Control ⌃ + F

Flatten command can be used for multiple purposes. You will use this command most of the time. Here the list of different uses:

1. To Flatten Items for the First Time

Use on the layers or groups which don’t contain any flattened items. The plugin will add the #flatten tag and flatten them.

2. To Update Flattened Items

If you run it on the item(s) flattened before, it will update/reflatten them. Mostly this will be needed if there is a layer with background blur effect.

Here an example for both:

You can also apply this on multiple items at the same time.

3. To Flatten Artboards and to Create Shared Artboard Styles

Flattening artboards works a little different. When you flatten an artboard, the plugin creates a flattened image layer and adds it to the first row in the artboard.

It also asks you if you want to create a shared layer style from this flattened image layer or not — we can call this shared artboard style. So with this way, you will be able to bind any artboard to other artboards and keep them updated.

There is also a tag for keeping particular layers hidden in shared artboard style. If you want one or multiple layers hidden, just add #flattenHidden tag to the layer or group — adding tag can also be done via plugin menu: Flatten → Add Tag → #flattenHidden

Creating a shared artboard style and using #flattenHidden tag.

4. To Keep a Shared Artboard Style Updated

Select only one artboard and run flatten command to update its flattened image layer and also the shared style if it exists.

Binding an artboard to another artboard via shared artboard style and keeping it updated.

5. To Update All Flattened Items in the Current Artboard

For convenience, I thought we should be able to easily update the current artboard which we’re working on. So when nothing is selected, if you run the flatten command, all of the flattened items in the current artboard will be updated.

2. Flatten All

Use to flatten or update all layers with #flatten tag across the document.

3. Suggest Layers

Selects all the layers in the page which have blur effect but not #flatten tag in their names. So practically you can use it to find layers that should be flattened for increase of performance.

4. Add Tag

Select some layers and run one of the add tag commands to add the tag to the name of layers. You can type it yourself too, but this should be faster when multiple layers is the case.

5. Layer Mode and Image Mode

As it’s obvious from names, you can use these commands to switch to relevant mode.

Use “Layer Mode” when exporting things since the flattened image layers might decrease the export quality.

6. Feedback / Contact

Use this command for any kind of suggestion or encouragement! 😉

And one more thing…

Performance Comparison!

The video below is created with Meng To’s iOS9 iPad GUI. Left one is the original document and right one is after flattening blurred layers.

Sketch version used: 3.4.4, original document size: 79.1 MB, processed document size: 83.5 MB.

Took the videos on my MacBook Pro (Retina, 13-inch, Early 2015)

Things to be Careful

Although the logic looks simple, there are some points to be careful to get the ideal result. Here some of my discoveries during my use:

Shadows

Overflowing shadows — out of layer/group bounds — won’t be included in the flattened image.

So, for now, if there is an overflowing shadow, you can find a way to imitate the shadow with using parent group’s shadow property or creating another layer inside; or if it’s hard to imitate, you can group the layer and put something invisible inside to extend the bounds of the group. Personally I prefer creating overflowing shadows by using the parent group’s shadow property.

Note: I’m open to suggestions for finding a better way to overcome this issue right inside the plugin.

Layers with Background Blur

If you’re flattening a layer with background blur, either the artboard should have a background color, or there should be something solid behind the layer — which should be covering all of the borders of the layer. Otherwise background blur will look faulty. So consider to activate the artboard background colors at least.

And, if a layer with background blur has some part overflowed the artboard borders, it causes faulty flattening too.

Download the Plugin

You can download and install the plugin via Sketch Toolbox or from here.

What is Next?

In my next post, I’m planning to share some pro Sketch tips which I believe they weren’t shared before, and of course a new Sketch plugin, focused on saving important stages of your design.

So don’t forget to follow me for upcoming plugins, tutorials, freebies and updates!

--

--

Product designer and prototype developer. Likes traveling, nature, photography and sharing — www.emin.space