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

seeing recursion with DTCollectionViewDelegate canFocus #64

Closed
skydivedan opened this issue Oct 24, 2018 · 5 comments
Closed

seeing recursion with DTCollectionViewDelegate canFocus #64

skydivedan opened this issue Oct 24, 2018 · 5 comments
Assignees

Comments

@skydivedan
Copy link

Sorry, this isn't really an issue, but asking for advice, as to whether you've seen this and might know the cause.

There is a situation (which I'm still trying to determine the cause) where canFocus gets called repeatedly, and recursively. Screenshot attached of stacktrace. I'm sure it's some dumb issue on my part, just not sure best way to proceed.

screen shot 2018-10-24 at 12 20 12 pm

@DenTelezhkin
Copy link
Owner

Hey!

I believe this might be a bug in DTCollectionViewManager. From documentation on UICollectionViewDelegate collectionView(_:canFocusItemAt:):

You can use this method, or a cell’s canBecomeFocused method, to control which items in the collection view can receive focus. The focus engine calls the cell’s canBecomeFocused method first, the default implementation of which defers to the collection view and this delegate method.

Which is unfortunate, because this event implementation in DTCollectionViewManager is implemented like so:
https://github.com/DenHeadless/DTCollectionViewManager/blob/master/Source/DTCollectionViewDelegate.swift#L181

And so what I was trying to do is

  1. Call closure event, if it's registered
  2. Call real UICollectionViewDelegate method, if it's implemented
  3. Call cell's canBecomeFocused.
  4. Return true if all other steps fail as a sensible default.

What seems to be happening is step 3 implicitly calls step 2 in UICollectionView implementation which leads to infinite recursion.

I don't have experience of working with this API, but it seems like removing step 3 in DTCollectionViewDelegate implementation looks like the way to go. What do you think?

@DenTelezhkin DenTelezhkin self-assigned this Oct 25, 2018
@skydivedan
Copy link
Author

Yes, your assessment looks correct. Additionally, you'll have to take out the same clause in DTTableViewDelegate.canFocusRowAt. I'm going to run some tests here, and see what develops.

@skydivedan
Copy link
Author

Quick note... sorry to say but I can't get back to this until Monday, unfortunately. But I dug around a bit more in the code and found a similar example of this DTTableViewDelegate in tableView.shouldIndentWhileEditingRowAt.

@DenTelezhkin
Copy link
Owner

@skydivedan No worries, take your time, it can wait till Monday =)

As for tableView.shouldIndentWhileEditingRowAt - it's different because UITableViewCell does not actually call delegate method if you ask it's property shouldIndentWhileEditing, and 4 steps logic I described earlier should work fine.

@DenTelezhkin
Copy link
Owner

This bug is fixed in DTCollectionViewManager 6.4.1 release. Closing.

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

2 participants