vpdn/MMLayershots

Layer naming and groups

vpdn opened this issue · 7 comments

vpdn commented

Layers are currently all named "Layer". Would be nice to structure the layers into groups.

Would be cool to put sublayers into psd groups and rename "Layer" to something more meaningful: E.g.

  • Use UIAccessibility
  • Use layer.name if set
  • If layer.name not set, fall back to auto incrementing counter (like "Layer 1.2.1")
  • If layer.delegate is set, name PSD layer based on class name (e.g. "ImageView 1.2.1")
  • If layer.delegate is a know class, could do something smarter. E.g. for UILabel, use label.text or inspect the accessibilityIdentifier

I forked MMLayershots today and created a version that supports layer grouping. I managed this by replacing PSDWriter with SFPSDWriter.

This is just something I threw together quickly so I did not create a pull request, but if you are interested the code is available at:

http://github.com/ashikase/MMLayershots/tree/layer_grouping

vpdn commented

@ashikase Cool thanks. I was initially thinking of using FMPSD but it seemed rather big compared to PSDWriter, due to the support of layer styles, PSD read support etc. all stuff that we don't really use. I wasn't aware of SFPSDWriter, will have a look!

vpdn commented

@ashikase Looks cool, will clean up and pull in. The restructuring will also fix #9.

vpdn commented

✓ Layer groups

@ashikase I merged (ashikase/MMLayershots@33fcb94) back with 5a7fa5f, thanks! Also added you to the attribution section, hope it's ok. If you want any rewording, let me know.

@vpdn Regarding grouping, did my first implementation meet your expectation ? Using container views as group, but limit depth to 10 levels ? If so, I will make a PR this afternoon.

vpdn commented

@nicolasgoutaland There's already an implementation by @ashikase, which I've extended on to check for the 10 level limit. It's in the feature branch right now and not merged yet: https://github.com/vpdn/MMLayershots/tree/feature/layer_groups

I haven't tested it long enough, that's why it's not merged back yet. Maybe you can help review the branch.

Ok, Just had a look.
3 remarks :

  • I find it complicated the way the limit is handled. Why not adding a parameter to the addImagesForLayer:renderedToRootLayer: method. For example :
    addImagesForLayer:renderedToRootLayer:depth: and incrementing depth for each sublevel
  • Their seems to have an implementation error line 23. Once level 10 reached, layers generation will stop. Instead, we should continue to generate sublayers, but not create new folders.
  • Finally, their is no logic on groups creation. I think a lot of groups will be unuseful.