SketchAPI icon indicating copy to clipboard operation
SketchAPI copied to clipboard

Updating a layer’s property doesn’t also update the inspector panel

Open KevinGutowski opened this issue 7 years ago • 3 comments

For example, if you set a fill color for a layer like this:

layer.style.fills = [{
   color: #1ca9c4,
   fill: Style.FillType.Color
})

The layer will update properly but the inspector panel doesn’t update. Currently I have to manually reload the inspector panel each time with document.sketchObject.inspectorController().reload()

Ideally this is already handled for me when setting a layer property.

Here is an example of this issue: jun-09-2018 00-59-45

KevinGutowski avatar Jun 09 '18 23:06 KevinGutowski

FTR, this also happens when changing the frame for a layer.

bomberstudios avatar Jun 14 '18 11:06 bomberstudios

I'm wondering what's best here: there is a potential performance issue with updating the inspector on every changes.

We might need a "batch" mode that you can toggle on the document. When it's on, we don't reload the the inspector. When it's turned off, then we reload. And if it's off and there are some changes, then we reload.

What do you think?

mathieudutour avatar Jun 14 '18 15:06 mathieudutour

One possible solution is to defer the update - schedule an inspector update for the end of the JS event loop any time the frame/color/etc of a layer is mutated. Since I don't think JavaScriptCore provides a means to query/schedule on the event loop you'll have to do it from Objective-C or something using dispatch_async? Or, since I think a JS timer function already exists(?), just create a debounced update? Actually I think you might be able to use async/Promise for this, since I think they guarantee execution at the end of the event loop.

matt-curtis avatar Jul 11 '18 21:07 matt-curtis