【发布时间】:2018-09-12 21:26:52
【问题描述】:
我想使用 React-Native 构建一个 Android TV 应用。我已跟进此文档的建议:Building For TV Devices。
之后,更新我使用命令行运行应用程序的 AndroidManifest.xml 文件 - react-native run android。该应用程序运行没有任何问题;但是,我尝试使用 android emulator TV (720p) API 23 模拟器中的 Directional-pad 选项,但没有成功。我期待捕获下面代码中列出的事件并将每个事件的相应测试写入控制台。另一方面,当我尝试使用 Directional-pad 导航时,即使是用于文本的组件也没有突出显示。
我正在与社区联系,看看过去是否有人遇到过这个问题,你的问题是什么,你为解决这个问题做了什么?另外,正如我在下面列出的步骤,如果我遗漏了什么,你能告诉我吗?
如果您需要任何额外的信息来帮助我,请告诉我。
- react-native init Dpad
- cd 方向键
- 更新代码基于 - Building For TV Devices
- 启动 Android TV (720p) API 23 模拟器。
- react-native run-android
代码如下:
import React, { Component } from 'react';
import { Text, View } from 'react-native';
import Channel from '../channel/channel.component';
import styles from './presentation.component.styles';
var TVEventHandler = require('TVEventHandler');
export default class Grid extends Component {
constructor(props){
super(props);
this.state = {
command: 'undefined'
}
}
setcomand( command) {
this.setState( () => { return { command: command }; });
}
_tvEventHandler: null;
_enableTVEventHandler() {
this._tvEventHandler = new TVEventHandler();
this._tvEventHandler.enable(this, function(cmp, evt) {
if (evt && evt.eventType === 'right') {
setcomand('Press Right!');
} else if(evt && evt.eventType === 'up') {
setcomand('Press Up!');
} else if(evt && evt.eventType === 'left') {
setcomand('Press Left!');
} else if(evt && evt.eventType === 'down') {
setcomand('Press Down!');
}
});
}
_disableTVEventHandler() {
if (this._tvEventHandler) {
this._tvEventHandler.disable();
delete this._tvEventHandler;
}
}
componentDidMount() {
this._enableTVEventHandler();
console.warn("component did mount");
}
componentWillUnmount() {
this._disableTVEventHandler();
console.warn("component Will Unmount");
}
render() {
return (
<View style={styles.container}>
<Text>{this.state.command}</Text>
<Channel name="Globo" description="Its brazilian TV channles for news"/>
<Channel name="TVI" description="Its Portuguese TV channles for news"/>
<Channel name="TVI" description="Its Portuguese TV channles for news"/>
</View>
);
}
}
【问题讨论】:
-
为什么不能测试?你有错误吗?您需要提供更多信息
-
欢迎来到 Stack Overflow!其他用户将您的问题标记为低质量和需要改进。我重新措辞/格式化您的输入,使其更容易阅读/理解。请查看我的更改以确保它们反映您的意图。但我认为你的问题仍然无法回答。 你现在应该edit你的问题,添加缺失的细节(见minimal reproducible example)。如果您对我有其他问题或反馈,请随时给我留言。
-
仅删除“我想要的”+“我当前的代码”是不够的。你必须清楚地解释你的代码有什么样的问题!
标签: react-native d-pad