【问题标题】:Why onPress function fired 3 times in Android TV os?为什么 onPress 函数在 Android TV 操作系统中触发了 3 次?
【发布时间】:2021-05-16 02:52:20
【问题描述】:

我是 react native 的新手,我打算为 Android TV 开发一个应用程序。

我打开了一个新项目并尝试了一些基本的东西。但是,我发现单击选择按钮后会触发 3 次 onPress 事件。我尝试使用我的真实设备和 AVD 得到相同的结果。

谁能告诉我为什么 onPress 会被解雇 3 次?

import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';

export default function App() {
  return (
    <View style={styles.container}>
      <Button title="123" onPress={() => {
        console.log('555');
      }} />
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

控制台

555
555
555

【问题讨论】:

    标签: react-native expo android-tv


    【解决方案1】:

    https://snack.expo.io/aqnj-8iOf

    如果您查看上面包含您的代码的小吃,您会注意到按下按钮时它不会多次记录。

    似乎 JavaScript 捆绑器正在与模拟器分开记录。 尝试关闭和调试工具并仅保留在终端上,这应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-16
      • 1970-01-01
      • 1970-01-01
      • 2021-07-06
      • 1970-01-01
      • 2016-10-03
      • 1970-01-01
      相关资源
      最近更新 更多