Created
November 27, 2017 18:22
-
-
Save cidicles/b4e978d3f3e2de8b359bdc51b5fb3261 to your computer and use it in GitHub Desktop.
Fixed Position Components for React VR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { | |
VrHeadModel, | |
View | |
} from 'react-vr'; | |
const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); | |
/** | |
* Helper to fix a component to the viewport. | |
* @module components/fixed | |
*/ | |
class Fixed extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
hmRot: VrHeadModel.rotation(), | |
hmYpr: VrHeadModel.yawPitchRoll(), | |
hmMatrix: VrHeadModel.getHeadMatrix() | |
} | |
this._headMatrixListener = RCTDeviceEventEmitter.addListener( | |
'onReceivedHeadMatrix', | |
this._onReceivedHeadMatrix.bind(this) | |
); | |
} | |
_onReceivedHeadMatrix(headMatrix, viewMatrix, fov, aspect) { | |
this.setState({ | |
hmRot: VrHeadModel.rotation(), | |
hmYpr: VrHeadModel.yawPitchRoll(), | |
hmMatrix: VrHeadModel.getHeadMatrix() | |
}); | |
} | |
render(){ | |
let {hmRot, hmYpr, hmMatrix} = this.state; | |
return ( | |
<View | |
style={{ | |
position: 'absolute', | |
layoutOrigin: [0, 1], | |
transform: [ | |
{translate: [0, 0, 0]}, | |
{matrix: hmMatrix} | |
] | |
}}> | |
<View | |
style={{ | |
position: 'absolute', | |
layoutOrigin: [0.5, 0.5], | |
transform: [ | |
{translate: [0, 0, 0]} | |
] | |
}}> | |
{this.props.children} | |
</View> | |
</View> | |
); | |
} | |
} | |
module.exports = Fixed; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fixed mean your button like fullscreen button. and your code is position: absolute not fixed.