-
Notifications
You must be signed in to change notification settings - Fork 89
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
Anvil.currentView() is null inside render method #83
Comments
Well, it definitely sounds like a bug, but to be honest - Anvil is not so good at adding/removing identical views on the fly. The reason is that it uses a very basic algorithm for diffing (to keep code short and to make it fast): if the class matches - adjust the attributes, otherwise - replace the view. E.g. if you populate the attributes of the views and remove the 2nd view - it will remove the last (3rd) view and re-apply the attributes of the 3rd view to the 2nd view instead. That's why in practice it makes more sense to either use different classnames or just toggle the visibility flag without changing the number of views. Or use adapters. Anyway, I'll try to reproduce it in the meantime, thanks for reporting! |
Thanks for the quick reply. |
Any update on this? |
@mitchryanjusay To speed things up a reproducible test case or some crash logs would be helpful. |
In my current code I have a view pager and that viewpager I have fragments that contain TextInputLayout that of course, has TextInputEditText in it. All the layouts are made with XML and state and data binding done through anvil. Anvil.render() is triggered as a subscriber to Jedux Store. I've tried debugging the code to see where the problem lies and the problem seems to be in startNode (Anvil.java). On the second time it renders (first time being the onCreateView) the node's children size is 0 hence it doesn't enter the condition then when it goes back to BaseDSL.java startFromLayout if the node's id is equal to the ID pass it's immediately return without checking if the node's view is null. For now, placing all the contents of the view method (of the class that extends RenderableView) inside a try-catch avoids crashes but of course would not render all of the updates to the state/data binding |
@danhawkes does it happen when a view is removed by some code calling "removeView" etc only? (vs via a condition in Anvil layout) |
I'm not manually adding/removing views, but am thinking it's possible that the RecyclerView (via RecyclerViewAdapter) might be. |
In fact, I think this is likely to be fixed very soon. |
Any ideas why the following exception is being thrown by withId()?
The issue occurs in the render cycle immediately after the view in question is removed from its parent, like this:
Pass 1:
Pass 2:
SomeView's render method where the crash is thrown is essentially this:
The text was updated successfully, but these errors were encountered: