tombenner / nui

Style iOS apps with a stylesheet, similar to CSS
MIT License
3.76k stars 461 forks source link

NUI in a UIScrollView can cause odd layout exceptions #233

Open phatmann opened 10 years ago

phatmann commented 10 years ago

Right now NUI hooks into didMoveToWindow and applies the styling at that time. This can cause major problems when using a subview in a UIScrollView, since didMoveToWindow triggers the auto-layout engine and NUI's style changes at that time can confuse it. For example, in my project I got an

 Assertion failure in -[NSContentSizeLayoutConstraint _setSymbolicConstant:constant:]

(Look it up in Google -- it is so weird you won't find anything about it!) If take out the NUI styling for the element in question the error goes away.

I am not sure why the styles are applied during didMoveToWindow. To me it makes sense to apply the styles when the control is initialized. I bet a ton of weird bugs would go away if we did so. @tombenner, can you explain the current decision?

I am definitely willing to make the appropriate changes and do some testing to see if there are any issues.

tombenner commented 10 years ago

It looks like I switched from awakeFromNib to didMoveToWindow so that programmatically created elements would be styled in all cases. I'm afraid I can't remember exactly what cases were problematic, but you should absolutely feel free to test out events other than didMoveToWindow (in fact, doing so may give us insight into what test examples we should include in our suite), if you like, perhaps focusing somewhat in the context of programmatically created elements. Swizzling didMoveToWindow definitely feels heavy-handed, and I'd love to move away from it.