Great tutorial! As I was reading, I kept wondering how YogaKit handles scrolling when the content extends beyond the end of the device’s screen. I looked at the Facebook Yoga site and can’t find information there about scrolling behavior if any. Can you comment on what, if any, scroll behavior happens when the content extends too far to the right or off the bottom of the screen?
Good question. YogaKit handles laying out your subviews. To handle content that may extend beyond the bounds, you have to set the scroll view’s content size. Right now, I believe that YogaKit doesn’t automatically do this for you. The way I handled it in the sample app was by setting the content size after the layout was completed by YogaKit:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// Calculate and set the content size for the scroll view
var contentViewRect: CGRect = .zero
for view in contentView.subviews {
contentViewRect = contentViewRect.union(view.frame)
}
contentView.contentSize = contentViewRect.size
}
Let me know if that doesn’t answer your question.
Very cool tutorial. Thanks @lucdion! Interesting to use Flexbox for layout. I like it!
Any idea how to animate the layout properties? I tried changing a layout property (of let’s say a topBar) in an animation block on button click, tried setting the marginTop or height. But it didn’t work. I also tried calling view.layoutIfNeeded() after setting the new value, like you do when animating constraints. Also it didn’t animate.
Hi @lucdion thanks a lot for your tip. I will try it out soon. Haven’t tried FlexLayout yet because I wanted to learn the basics first, but will definitely try it soon. The chaining (I mean nesting) is something I miss in Swift, worked with React before.
This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]