Skip to content

Instantly share code, notes, and snippets.

@achuvm
Created August 2, 2017 08:14
Show Gist options
  • Save achuvm/e35ab38d8f7a5af8cce71730e1425f37 to your computer and use it in GitHub Desktop.
Save achuvm/e35ab38d8f7a5af8cce71730e1425f37 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import {
ViroScene,
ViroImage,
ViroButton,
} from 'react-viro';
let imageOne = {uri: "http://wiki.magicc.org/images/c/ce/MAGICC_logo_small.jpg"};
let imageTwo = {uri: "http://planetpixelemporium.com/images/fullsize/541moon.jpg"};
// [NEW] requiring/import the TestModuleVar module.
var TestModuleVar = require('./TestModuleVar');
var SwapImageTest = React.createClass({
getInitialState: function() {
return {
showImageOne : true,
};
},
render: function() {
// [NEW] Logging out moduleVar
console.log("TestModuleVar.moduleVar is: " + TestModuleVar.moduleVar);
return (
<ViroScene>
<ViroImage position={[0,0,-1]} source={this.state.showImageOne ? imageOne : imageTwo}
onClick={this._onImageClick} />
<ViroButton position={[.5,-1,-1]} source={imageOne} onClick={this._onImageOneClick}/>
<ViroButton position={[-.5,-1,-1]} source={imageTwo} onClick={this._onImageTwoClick}/>
</ViroScene>
);
},
_onImageClick() {
// [NEW] Changing moduleVar
TestModuleVar.moduleVar = "barfoo";
this.setState({
showImageOne : !this.state.showImageOne
})
},
_onImageOneClick() {
this.setState({
showImageOne : true
})
},
_onImageTwoClick() {
this.setState({
showImageOne : false
})
},
});
module.exports = SwapImageTest;
/*
* TestModuleVar.js
*/
var moduleVar = "foobar";
exports.moduleVar = moduleVar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment