Skip to content

Instantly share code, notes, and snippets.

@gre
Last active August 23, 2017 10:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gre/3a08cf9e82a51b0b160e to your computer and use it in GitHub Desktop.
Save gre/3a08cf9e82a51b0b160e 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>;
}
@AlexDM0
Copy link

AlexDM0 commented Mar 17, 2016

Hi, I think the surface should have the preload={true} option if you're manipulating external images since it may trigger once before loading the image and messing up the file you want to save.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment