【发布时间】:2021-06-23 02:56:31
【问题描述】:
我正在尝试使用 react-native 构建一个 androidTV 应用程序,并且我遵循了文档,但是无论我做什么,似乎 onFocus 和 onBlur 对我都不起作用,这是代码:
const App = () => {
return (
<View>
<TouchableHighlight
hasTVPreferredFocus={true}
accessible={true}
onFocus={() => alert('focus')}
onBlur={() => alert('blur')}
onPress={() => alert('press')}>
<Text>This is a text</Text>
</TouchableHighlight>
<Button title="title" />
</View>
);
};
我还添加了hasTVPreferredFocus 和accessible 以确保我没有错过任何内容。
【问题讨论】:
-
import {TouchableHighlight,Button} from "react-native";使用这条线,它会很适合你。 -
@MohamedBdr 我已经导入了它们,组件本身工作正常,但道具 {onBlur , onFocus} 是问题
-
你能告诉我你想做什么,所以如果你点击
This is a text你会发现按下警报是你想要的还是你想要的按钮来做这个行为? -
@MohamedBdr 我想检测组件何时聚焦以及何时离开聚焦,因此当用户在 androidTv 上使用 D-pad 移动时,我可以更改样式
标签: javascript react-native native android-tv