Skip to content

Commit

Permalink
Implemented the looper
Browse files Browse the repository at this point in the history
  • Loading branch information
excitement-engineer committed May 20, 2017
1 parent 9e68b9e commit 41e9a48
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
63 changes: 45 additions & 18 deletions index.vr.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,61 @@
import React from 'react';
import {
AppRegistry,
asset,
Pano,
Text,
View,
} from 'react-vr';
import React from "react";
import { AppRegistry, asset, Pano, Text, View } from "react-vr";
import text from "./text";

const textSplit = text.split(" ");

export default class VRTextReader extends React.Component {

constructor() {
super();

this.timer = this.timer.bind(this);
this.state = {
currentCount: 0
}
}
componentDidMount() {
var intervalId = setInterval(this.timer, 200);
// store intervalId in the state so it can be accessed later:
this.setState({ intervalId: intervalId });
}

componentWillUnmount() {
// use intervalId from the state to clear the interval
clearInterval(this.state.intervalId);
}

timer() {
// setState method is used to update the state

if (this.state.currentCount === textSplit.length) {
clearInterval(this.state.intervalId);
}
else {
this.setState({ currentCount: this.state.currentCount + 1 });
}
}

render() {
return (
<View>
<Pano source={asset('chess-world.jpg')}/>
<Text
style={{
backgroundColor: '#777879',
fontSize: 0.8,
fontWeight: '400',
fontWeight: "400",
layoutOrigin: [0.5, 0.5],
paddingLeft: 0.2,
paddingRight: 0.2,
textAlign: 'center',
textAlignVertical: 'center',
transform: [{translate: [0, 0, -3]}],
}}>
hello
textAlign: "center",
textAlignVertical: "center",
transform: [{ translate: [0, 0, -3] }]
}}
>
{textSplit[this.state.currentCount]}
</Text>
</View>
);
}
};
}

AppRegistry.registerComponent('VRTextReader', () => VRTextReader);
AppRegistry.registerComponent("VRTextReader", () => VRTextReader);
2 changes: 2 additions & 0 deletions text.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 41e9a48

Please sign in to comment.