NoriginMedia / react-spatial-navigation

DEPRECATED. HOC-based Spatial Navigation. NEW Hooks version is available here: https://github.com/NoriginMedia/norigin-spatial-navigation
MIT License
226 stars 64 forks source link

Focus jumps on wrong component #46

Closed salvan13 closed 4 years ago

salvan13 commented 4 years ago

Sometimes when navigating in a direction the focus jumps on an element in another direction. It's not happening often, in our case only on Tizen when we keep pressed down/up keys in the homepage.

We investigated the problem and we found wrong layout.top positions, causing wrong siblings detection in a direction ( the array siblings here https://github.com/NoriginMedia/react-spatial-navigation/blob/master/src/spatialNavigation.js#L540 contains wrong elements )

The root cause is the setTimeout in measureLayout function https://github.com/NoriginMedia/react-spatial-navigation/blame/master/src/measureLayout.js#L28 It seems some of the callbacks are executed before the actual sibling detection while some other are executed after.

We removed it to update the layouts synchronously and the problem disappeared.

If there isn't any reason to keep it I suggest to remove it.

asgvard commented 4 years ago

Makes sense. The main reason for it to be async is to unblock main thread and recalculate layouts within animation frames intervals. But if it causing issues like this, let’s remove it.