Last active
August 23, 2017 10:42
-
-
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
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
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; |
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
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
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.