TextureGroup / Texture

Smooth asynchronous user interfaces for iOS apps.
https://texturegroup.org/
Other
8k stars 1.29k forks source link

[Question] size changes for wrapped UIView #579

Open ghost opened 6 years ago

ghost commented 6 years ago

I wrapped UIView in a ASDisplayNode block and put it in stack layout in 1 ASTableCell. When UIView size changed (said there're some images/videos like html pages delegate callback), the wrapper ASDisplayNode doesn't know about it at all, even when I called a setNeedLayout() on it. And so the cell is not resized correctly.

textContentNode = ASDisplayNode { [unowned self] () -> UIView in let textView = CustomUIView() textView.attributedString = attrText textView.delegate = self return textView }

My cell layout structure ==========Cell========== [HEADER STACK /] [STACK TEXT NODE] ====== textContentNode= ===== [/STACK TEXT NODE] [FOOTER STACK /] ==========Cell==========

Did I miss something or this is a problem? Really appreciate the awesome library!

RaymondBakker commented 6 years ago

+1

hannahmbanana commented 6 years ago

Sounds like you are trying to resize a ASCellNode based on size information contained in a UIView (in a custom ASDisplayNode). See https://github.com/TextureGroup/Texture/issues/593 for more information, but here's a quick answer:

Because the UIView size information is restricted to the main thread, but Texture layout must be safe for background threads, you need to set the new size on something accessible to the texture layout system. The easiest way to do this is often by using the .node.style.preferredSize (or other style methods including aspectRatio to define the size in the layout). In your case, when the size changes, the code needs to set a new value on the .style for the node and then call -setNeedsLayout.

Let me know if that works! Also, I encourage you to adopt ASNetworkImageNode as it would work better than wrapping views.