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

SpatialNavigationVirtualizedList AutoScroll #145

Open
Veryyapeee opened this issue Jul 22, 2024 · 3 comments
Open

SpatialNavigationVirtualizedList AutoScroll #145

Veryyapeee opened this issue Jul 22, 2024 · 3 comments
Labels

Comments

@Veryyapeee
Copy link

Describe the bug
While using autoscroll on list, when user is focused, it's causing some weird behaviour in terms of DPAD.

To Reproduce

setInterval(() => {
ref.current.focus(prevActiveIndex + 1)
},10 * 1000)

<SpatialNavigationVirtualizedList ref={ref} renderItem={() => <SpatialNavigationFocusableView/>} />

When autoscroll happens, and I'm still focused on the list, and then press the left/right arrow, the focus behaves, like it's on the last element that I've focused using DPAD, not the imperative focus() method.

To visualize that:
I've focused list on index 1.
Not pressing anything -> autoscroll focused element with index 3.
Pressing right -> instead of element with index 4 being focused, element with index equal to 2 is focused

Expected behavior
DPAD is following/tracking the focus() method call

Version and OS

  • Library version: [3.5.0]
  • React Native version: [0.73.6]
  • OS [web]

Additional context
Add any other context about the problem here.

@Veryyapeee Veryyapeee added the bug Something isn't working label Jul 22, 2024
@Veryyapeee
Copy link
Author

Veryyapeee commented Jul 22, 2024

I've managed to work around it by using something like

const elementsRefs = useRef<SpatialNavigationNodeRef[]>([]);

const setRef = useCallback(
  (index: number) => (element: SpatialNavigationNodeRef) => {
    elementsRefs.current[index] = element;
  },
  [],
);

I'm assigning ref to each element in dataset. And each time when I'm setting focus on the list, I'm also focusing the element imperatively.

Seems like it's working, but, it would be cool if I won't have to do stuff like that.

Is it a bug, or maybe I'm missing something?

@pierpo
Copy link
Member

pierpo commented Jul 25, 2024

Hey! It looks like a bug. It's nice that you have a workaround. Indeed, we'd expect something simpler!
Thank you for reporting it 😊

@pierpo
Copy link
Member

pierpo commented Sep 13, 2024

Hey! I'm not sure I really solved the issue, but I did solve some race conditions with 4.0.1 regarding lists + imperative focus. Can you try again in 4.0.1, without your workaround? 😁

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

2 participants