TVEventHandler and useTVEventHandler captured event repetition
See original GitHub issueDescription
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.
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:
- Created 2 years ago
- Comments:20
Top GitHub Comments
@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.
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.