Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes calling setNeedsLayout does not re-trigger layoutSpecThatFits #75

Closed
christianselig opened this issue Apr 27, 2017 · 1 comment

Comments

@christianselig
Copy link
Contributor

christianselig commented Apr 27, 2017

In my project, each cell represents a specific URL. In this particular case, I make an API call to figure out what the URL represents, and re-layout the cell based on the new information I receive. It's very similar in concept to ASDKgram and how it fetches the comments specific to a post, and re-layouts the cell upon receiving.

It works great 90% of the time, but every so often, if I put a breakpoint at my setNeedsLayout call (once the cell has found out what it represents), and another at my overridden layoutSpecThatFits method, I see that the latter is never called, and I'm not sure why given that most of the time it acts as I would expect.

In the cell's init, I perform the network call, and in its completion handler I create the new node (important to note perhaps that this is the first time this node is created; it's nil prior to this as the node instantiated is dependent on what the API returns). I then call setNeedsLayout immediately, and then layoutSpecThatFits should pick up on the fact it's not nil and then include it in the node hierarchy.

If I log these calls, it looks like this when it works as expected:

layoutSpecThatFits called.
layoutSpecThatFits called.
setNeedsLayout called.
layoutSpecThatFits called.
layoutSpecThatFits called.

and when not:

layoutSpecThatFits called.
layoutSpecThatFits called.
setNeedsLayout called.

In the example project below, you can see by restarting the app a few times, that normally, the network call is received, the cell performs another layout pass, and the cell shows the new information. However, if you restart it enough (sometimes takes 5+, and is much easier to replicate on a device rather than the simulator), you'll see it won't show the image after the API call returns:

screen shot 2017-04-26 at 7 29 51 pm

I'm really at wit's end trying to figure out what may be causing it. It should already be in the view hierarchy at the time it's called so it's not as if setNeedsLayout is being called on a non-visible node. It's totally possible (even likely) that it's something I'm doing accidentally to cause this, but any light anyone could shine onto the issue would be greatly appreciated.

Sample project:
TextureTest.zip
(Just run pod install; uses most recent version of Texture. There's some other files inside that are part of the model and for API calls, but really the only relevant files are LargePostCellNode and PostsViewController. It may take a few restarts of the app to show the issue.)

@christianselig
Copy link
Contributor Author

christianselig commented May 27, 2017

Fixed with #309. Thank you @huy and @appleguy for the awesome help as well, you all rock!

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

No branches or pull requests

1 participant