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

InfiniteCarousel does not play well with remembersLastFocusedIndexPath in tvOS 9.1 #15

Open
ehynds opened this issue Dec 17, 2015 · 6 comments
Labels

Comments

@ehynds
Copy link

ehynds commented Dec 17, 2015

STR:

  1. In the sample app in this project, set remembersLastFocusedIndexPath to true on the natGeo InfiniteCarousel instance
  2. Launch app
  3. Move focus to the natgeo carousel
  4. Attempt to go back one slide (press the left arrow on your keyboard) EDIT: or use the magic remote in the simulator or an actual Apple TV device

Expected:
Carousel moves back one slide and the newly centered slide receives focus

Actual:
Carousel moves back one slide and focus is lost. The carousel enters some weird state that ultimately requires you to force quit the app so that the carousel can be "swiped" through again.

Notes:

  • This bug is new in tvOS 9.1. It works fine in 9.0.1
  • In my code base, indexPathForPreferredFocusedViewInCollectionView does not get called at all unless remembersLastFocusedIndexPath is set to true. I'm still working to figure out why. Possibly because i'm rendering this carousel within a parent collection view?
@ianterrell
Copy link
Contributor

Thanks for the bug report. We'll definitely test this in our own apps under 9.1 as well.

At the moment part of the functionality of the carousel relies on touch events from the remote that are not sent when the keyboard is used to change focus; specifically, how far ahead you can focus is limited by the currently focused cell when you touch down. This was to keep the user from scrolling "too quickly", and mimics the tvOS iTunes top featured carousel where only one item at a time can be flicked through.

At a glance, since you mention the keyboard left key I would guess that's what you're running into (could very well be wrong).

Especially as I'd like to properly support external keyboards I'd be happy to find another alternate implementation that behaves the same (limiting focus to roughly a page ahead or behind) but that does not rely on touch events.

Possibly because i'm rendering this carousel within a parent collection view?

I would not think this is the issue, as it mimics a set up we've used too.

@ehynds
Copy link
Author

ehynds commented Dec 17, 2015

Thanks for responding. I should have mentioned that this happens when using the magic touchpad in the simulator as well as on the actual Apple TV remote, so it's not just the keyboard.

I'm curious as to how indexPathForPreferredFocusedViewInCollectionView is even firing in your example app because according to the docs, this method only fires when remembersLastFocusedIndexPath is explicitly set to true on the collection view.

@ianterrell
Copy link
Contributor

Ah — that's good information, thank you.

I think that particular bit of documentation may be wrong. It currently reads:

The functionality of this delegate method is equivalent to overriding the UICollectionView class’s preferredFocusedView method in the UIFocusEnvironment protocol. If the collection view’s remembersLastFocusedIndexPath method is set to YES, this method defines the index path that gets focused when the collection view is focused for the first time.

My understanding is that this delegate method is always called under the circumstances that preferredFocusedView would be called, which includes on initial unfocused display and after calling setNeedsFocusUpdate(). That corresponds with the first sentence of the documentation.

It's the second sentence of the documentation that is problematic; rather than reading "for the first time", I think the behavior of remembersLastFocusedIndexPath is that it will be called *when the collection view regains focus after losing it.

I will investigate further. :)

@ianterrell ianterrell added the bug label Dec 21, 2015
@ianterrell
Copy link
Contributor

This is still on our radar and something we're looking at. At the moment my proposed workaround is to disable remembersLastFocusedIndexPath and recreate its behavior using focus guides.

Have you worked around it similarly, @ehynds?

@ehynds
Copy link
Author

ehynds commented Jan 22, 2016

Yeah, I did the same.

@athadi35
Copy link

@ehynds Mind sharing code for how you used the focus guide? I'm running into the issue as well. Thank you.

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

No branches or pull requests

3 participants