react-tv-space-navigation icon indicating copy to clipboard operation
react-tv-space-navigation copied to clipboard

It is not possible to select the focusable element for the 2nd time when we return to the previous screen.

Open amoonnra opened this issue 1 year ago • 1 comments

Describe the bug This is played in android TV (android studio emulator). Everything works correctly in the web version. I use expo-route for navigation. But I don't think that's the point.

https://github.com/user-attachments/assets/5709a79f-ce96-4ea8-9f55-a679c284846c

If you click on any place in the emulator, the bug does not play, but you will not be able to do this on a real TV)

To Reproduce

configureRemoteControl (I used TVEventHandler, react-native-keyevent not work for me)
SpatialNavigation.configureRemoteControl({
	remoteControlSubscriber: (callback) => {
		const mapping: Record<string, Directions | null> = {
			right: Directions.RIGHT,
			left: Directions.LEFT,
			up: Directions.UP,
			down: Directions.DOWN,
			select: Directions.ENTER,
		}
		const eventId = TVEventHandler.addListener((keyEvent) => {
			if (!keyEvent) {
				return
			}

			const mapped =
				mapping[keyEvent.eventType] && keyEvent.eventKeyAction === 1 ? mapping[keyEvent.eventType] : null
			callback(mapped)
		})

		return eventId
	},

	remoteControlUnsubscriber: (eventId: EventSubscription) => {
		eventId?.remove()
	},
})
index file code
const Item = () => {
	const router = useRouter()
	return (
		<SpatialNavigationFocusableView
			onSelect={() => {
				router.push('search')
			}}
		>
			{({ isFocused }) => {
				return (
					<Pressable
						style={[
							{ width: 100, height: 50, marginRight: 10 },
							isFocused ? { backgroundColor: 'red' } : { backgroundColor: 'green' },
						]}
					/>
				)
			}}
		</SpatialNavigationFocusableView>
	)
}


export default function Index() {
	return (
		<Page>
			<Stack.Screen />
			<SpatialNavigationView direction="horizontal">
				<Item />
				<Item />
				<Item />
			</SpatialNavigationView>
		</Page>
	)
}

Expected behavior onSelect is triggered when we click on the element a second time

Version and OS

  • expo: ~52.0.17
  • react-native-tvos : ~0.76.3-0
  • react-tv-space-navigation: ^5.1.0

amoonnra avatar Dec 07 '24 09:12 amoonnra

Hi, I encountered the same problem, did you find any workaround?

"react-tv-space-navigation": "5.0.0"+

goldqwert avatar Mar 13 '25 23:03 goldqwert