So, how do I know which one to use?
I see that Sketch has a lot of tricky stuff inside and many not obvious rules.
Please understand my case:
Somewhere deep inside code code I have objects with a reference to layers.
I need to hide/show those layers
If I go up and rewrire everything it will take ages. Please tell me how do I check which version of hide should I use? Should I do some checks before using hide/show?
Oh if you already have a plugin codebase that’s built on top of the legacy native APIs, then please refer to the second code snippet (under a spoiler) in my previous post. It should do the trick
Hmm I can’t replicate this issue in my testing: it exports the page as I see it on the canvas (i.e. with symbols hidden). Can you share a sample document and your exact script you’re running?
Ohhh I see now, yes there’s indeed a race condition here because some parts of Sketch’ internal machinery run on a background thread, so basically they don’t get enough time to actually “apply” the new visibility status of a symbol before you try to export the corresponding area of the document – and as a result, it’s rendered as still visible.
Luckily, there’s a workaround. Do this right after your setIsVisible(false) call:
slice.setIsVisible(false);
if (slice.isKindOfClass(MSSymbolInstance) || slice.isKindOfClass(MSSymbolMaster)) {
slice.ensureDetachHasUpdated()
}