Skip to content

Instantly share code, notes, and snippets.

@kolombet
Forked from gre/AutoCaptureGLThing.js
Created July 15, 2017 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolombet/e3dc57fdd7f019db7fa577dad5fd18c4 to your computer and use it in GitHub Desktop.
Save kolombet/e3dc57fdd7f019db7fa577dad5fd18c4 to your computer and use it in GitHub Desktop.
example that render things offscreen with gl-react – would love if you find a way to make this use-case less hacky
class AutoCaptureGLThing extends Component {
onRef = exportable => {
if (!exportable || this.exporting) return;
this.exporting = true;
exportable.captureFrame(/* see https://projectseptemberinc.gitbooks.io/gl-react/content/docs/api/Surface.html */)
.then(path => { // oops back to node callback pattern via props callback
this.props.onCapture(null, path);
}, error => {
this.props.onCapture(error);
});
};
render () {
const deviceWidth = ...; // if you want to render "off screen", position absolute outside of the screen is a hack here
return (
<View style={{ position: "absolute", top: 0, left: deviceWidth }}>
<Surface ref={this.onRef} ...>...</Surface>
</View>
);
}
}
module.exports = AutoCaptureContent;
onCapture = (error, snapshot) => {
const { captureRequested } = this.state;
if (error) console.error(error);
else doSomethingWithSnapshot(snapshot);
this.setState({ captureRequested: false });
};
render () {
return <View>
<Button onPress={() => this.setState({ captureRequested: true })}>CAPTURE</Button>
<Text>...<Text>
<Text>...<Text>
<Text>...<Text>
{!captureRequested ? null : <AutoCaptureGLThing {...whateverProps} onCapture={this.onCapture} />}
</View>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment