gre / gl-react

gl-react – React library to write and compose WebGL shaders

Home Page:https://gl-react-cookbook.surge.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question - Is it possible to detect when the content of the Surface have loaded?

serhiipalash opened this issue · comments

feature request?

I want to take the snapshot of the loaded Surface, but onLoad event fires early then all content have loaded. Do you have any idea how to handle this?

library version

screen shot 2017-09-14 at 17 38 41

Expected behavior

screen shot 2017-09-14 at 17 42 12

Actual behavior

screen shot 2017-09-14 at 17 39 47

Steps to reproduce the behavior

Clone this repo and open in Expo XDE

https://github.com/serhiipalash/opengl-test

by default, the Surface will render as soon as possible and won't wait images, if an image is not loaded yet, it renders black instead.

To have a different behavior, you need to specify the images to wait in a preload prop.
it will force Surface to wait for all images to render the first frame AND should only trigger onLoad after that.

example

<Surface preload={[ image1, image2 ]} onLoad={this.onLoad} ...>
  <Node ... uniforms={{ t1: image1, t2: image2 }} />
</Surface>

(the preload array contains same format as you would pass to uniform texture)

Thank you for your help @gre !