8
我正在使用React VR編寫一個VR應用程序,並且會使用進度條(或其他)來製作注視按鈕,以向用戶顯示他必須觀看該按鈕的時間。我怎麼能這樣做?如何使用React VR創建凝視按鈕?
我想利用這個僞(可能有一些bug的代碼裏):
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
}
是否有更簡單的方法來做到這一點?