我正在使用React VR编写VR应用,希望制作注视按钮,并添加进度条(或其他东西)以告诉用户他需要看多久才能按下该按钮。我该怎么做呢?
我考虑使用以下伪代码(可能存在一些错误):
我考虑使用以下伪代码(可能存在一些错误):
constructor(props) {
super(props);
this.state = {
watchTime: 3,
progress: 0,
watching: true
};
}
render() {
return (
<VrButton onEnter={ () => this.animateProgress() }
onExit={ () => this.stopProgress() }
onClick={ ()=> this.click() }></VrButton>
);
}
animateProgress() {
this.setState({watching: true});
while (this.state.watchTime >== this.state.progress && this.state.watching === true) {
// after a timeout of one second add 1 to `this.state.progress`
}
this.click();
}
stopProgress() {
this.setState({
progress: 0,
watching: false
});
}
click() {
// Handels the click event
}
有没有更简单的方法来完成这个任务?