Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Reason behind the existence of contentLayer #15

Closed
yuchi opened this issue Mar 16, 2014 · 5 comments
Closed

Reason behind the existence of contentLayer #15

yuchi opened this issue Mar 16, 2014 · 5 comments

Comments

@yuchi
Copy link

yuchi commented Mar 16, 2014

Ok, I’m surely missing something, but the fact that FBShimmeringLayer can’t simply be used with +layerClass and give whatever view the shimmering effect really bugs me.

Why is there the need for a contentLayer to limit the effect? Shouldn’t be simply self.mask = _maskLayer instead?

I tried this approach and worked perfectly…

(please keep in mind I just moved to Obj-C)

@grp
Copy link
Contributor

grp commented Mar 16, 2014

Objective-C usually favors composition over subclassing. With the current approach, you can add shimmering to any existing view or layer, without having to make a subclass of it.

Using composition can be especially useful when you don't control the creation of the view hierarchy. For example, you could add a shimmering effect to an MPMoviePlayerController's view, which is created and managed by iOS itself.

You can still use it with any view or layer you create yourself as long as you put the contents inside a single view or layer. Then, internally set that as the contentLayer.

@yuchi
Copy link
Author

yuchi commented Mar 16, 2014

Sorry if I’ll look dumb, but I really don’t get it.

Using composition can be especially useful when you don't control the creation of the view hierarchy. For example, you could add a shimmering effect to an MPMoviePlayerController's view, which is created and managed by iOS itself.

You’re still going to create a view (whose .layer will be a FBShimmeringLayer) to contain the MPMoviePlayerController whose view’s layer will be used as a contentLayer. Even using -setLayer: you could set an ‘auto-shimmering’ layer to it (I mean, the container).

You can still use it with any view or layer you create yourself as long as you put the contents inside a single view or layer. Then, internally set that as the contentLayer.

That’s exactly what I tried to do, but my special environment has spit on me. (Just for clarity, I’m porting Shimmer to Titanium SDK, where views lay in a very special way, and adding middle-views without breaking the layout is not that trivial.)

@grp
Copy link
Contributor

grp commented Mar 16, 2014

I see what you mean now, the shimmering layer could shimmer all of its children, rather than just the contentLayer. That's an interesting idea — I would suggest forking the code and modifying it as you need for that, since it's likely you'll need other changes as well to work outside the standard Cocoa Touch environment.

@yuchi
Copy link
Author

yuchi commented Mar 16, 2014

Actually I just made that changes, it’s just a fact of removing everything contentLayer related. To port that on Titanium I just had to clone what you did on FBShimmeringView, setting the +layerClass.

Would you mind if I make a PR for you to explore the idea?

@yuchi
Copy link
Author

yuchi commented Mar 16, 2014

(Oh, by the way, your code is really self explanatory. Awesome component perfectly executed)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants