question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TVEventHandler and useTVEventHandler captured event repetition

See original GitHub issue

Description

Hello and thank you for the support; I am building a sliding component using TVEventHandler on Android TV when I noticed that a single event is logged twice, I used the useTVEventHandler hook for the same purpose, same side effect.

Screen Shot 2021-10-29 at 8 57 11 PM

React + Native /Deps info:

System: OS: macOS 11.6 CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 299.29 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.12.0 - /usr/local/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 8.1.0 - /usr/local/bin/npm Watchman: 2021.10.18.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0 Android SDK: API Levels: 28, 29, 30 Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3 System Images: android-Q | Android TV Intel x86 Atom Android NDK: 22.1.7171670 IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7621141 Xcode: 13.0/13A233 - /usr/bin/xcodebuild Languages: Java: 14.0.1 - /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/bin/javac npmPackages: react: 17.0.1 => 17.0.1 react-native-tvos: 0.64.2-4

Steps To Reproduce

use the example mentioned in this repo readme on a boilerplate app. https://github.com/react-native-tvos/react-native-tvos#code-changes

Expected Results

To log the event once.

Code example

`import React from “react”; import {View,Text,useTVEventHandler,TouchableOpacity} from “react-native”;

const App =() => { const [lastEventType, setLastEventType] = React.useState(“”); const myTVEventHandler = evt => { console.log(evt.eventType) setLastEventType(evt.eventType) }; useTVEventHandler(myTVEventHandler); return ( <View > <TouchableOpacity hasTVPreferredFocus={true} /> <Text>{lastEventType}</Text> <TouchableOpacity /> </View> ); }; export default App;`

Personal Observation

The behaviour is similar to keyup and keydown web events difference, whenever I press any of the 4 directions on the remote, an event is fired, when I release the button immediately after, same event logged again.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20

github_iconTop GitHub Comments

2reactions
douglowdercommented, Jan 11, 2022

@etiennelab @PDabek-StreamitApp @NikitaGura I will look into making the keyDown events optional. It seems like there are scenarios like yours where they are useful, but they cause problems in other use cases. I’ll create a new issue for this.

2reactions
douglowdercommented, Nov 5, 2021

I’m going to look into modifying the Android code to send key events only when key up happens. In the meantime, developers can filter out the key down event by looking for the eventKeyAction in the TV events. The value will be 0 for key down, 1 for key up. So on Android, only run your event handler when the value is 1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to rewrite the TVEventHandler of React Native using ...
How should this code be rewritten using React Hooks? I can't figure out this particular line: this._tvEventHandler.enable(this, function(cmp, ...
Read more >
react-native-tvos - npm
In 0.64.2-2, we added a TV event display to the new app template using useTVEventHandler . import { TVEventHandler, useTVEventHandler } from ...
Read more >
React Native on the Big Screen — Part 1: Introduction
This article will go through the first steps to show how we can create a React Native starter app for TV, and show...
Read more >
Building For TV Devices - React Native
When TV remote events occur, this class fires a JS event. This event will be picked up by instances of the TVEventHandler JavaScript...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found