diff --git a/Examples/Tests/Blur.js b/Examples/Tests/Blur.js
index 31ceb5446a73599e47bc849072cd3771c721f405..c541b600f85aaaa65bda1bfbbb50cefc7a0daff5 100644
--- a/Examples/Tests/Blur.js
+++ b/Examples/Tests/Blur.js
@@ -29,13 +29,12 @@ function directionForPass (p, factor, total) {
class Blur extends GL.Component {
render () {
const { width, height, factor, children, passes } = this.props;
-
const rec = p => p <= 0 ? children :
{rec(p-1)}
;
- return rec(passes);
+ return rec(passes || 0);
}
}
diff --git a/Examples/Tests/index.ios.js b/Examples/Tests/index.ios.js
index 3ab2021b3b947fd1ed7518c050641d2f1a9f81ae..964208110deed169035368ca3d019fad6f091d9e 100644
--- a/Examples/Tests/index.ios.js
+++ b/Examples/Tests/index.ios.js
@@ -34,7 +34,7 @@ const Tests = React.createClass({
)}
;
- const img = "http://i.imgur.com/zJIxPEo.jpg";
+ const img = "http://i.imgur.com/zJIxPEo.jpg?t="+Date.now();
const blurredImage =
diff --git a/RNGL/GLCanvas.m b/RNGL/GLCanvas.m
index ea40e9b0e4f4d4e02158f71a062e2edb71ee8a8f..80e4a7028c4f2afdd7d712692f21fde340a0fe98 100644
--- a/RNGL/GLCanvas.m
+++ b/RNGL/GLCanvas.m
@@ -15,7 +15,7 @@
@implementation GLCanvas
{
RCTBridge *_bridge; // bridge is required to instanciate GLReactImage
-
+
GLRenderData *_renderData;
NSArray *_contentTextures;
@@ -26,6 +26,9 @@
BOOL _deferredRendering; // This flag indicates a render has been deferred to the next frame (when using contents)
GLint defaultFBO;
+
+ NSMutableArray *_preloaded;
+ BOOL _preloadingDone;
}
- (instancetype)initWithBridge:(RCTBridge *)bridge
@@ -34,6 +37,8 @@
if ((self = [super init])) {
_bridge = bridge;
_images = @{};
+ _preloaded = [[NSMutableArray alloc] init];
+ _preloadingDone = false;
self.context = context;
}
return self;
@@ -41,6 +46,14 @@
RCT_NOT_IMPLEMENTED(-init)
+-(void)setImagesToPreload:(NSArray *)imagesToPreload
+{
+ if (_preloadingDone) return;
+ if ([imagesToPreload count] == 0) {
+ _preloadingDone = true;
+ }
+ _imagesToPreload = imagesToPreload;
+}
- (void)setOpaque:(BOOL)opaque
{
@@ -83,7 +96,7 @@ NSString* srcResource (id res)
{
[EAGLContext setCurrentContext:self.context];
@autoreleasepool {
-
+
NSDictionary *prevImages = _images;
NSMutableDictionary *images = [[NSMutableDictionary alloc] init];
@@ -135,7 +148,7 @@ NSString* srcResource (id res)
if (!src) {
RCTLogError(@"invalid uniform '%@' texture value '%@'", uniformName, value);
}
-
+
GLImage *image = images[src];
if (image == nil) {
image = prevImages[src];
@@ -144,7 +157,7 @@ NSString* srcResource (id res)
}
if (image == nil) {
image = [[GLImage alloc] initWithBridge:_bridge withOnLoad:^{
- [self requestSyncData];
+ [self onImageLoad:src];
}];
image.src = src;
images[src] = image;
@@ -171,7 +184,7 @@ NSString* srcResource (id res)
RCTLogError(@"All defined uniforms must be provided. Missing '%@'", uniformName);
}
}
-
+
return [[GLRenderData alloc]
initWithShader:shader
withUniforms:uniforms
@@ -190,6 +203,30 @@ NSString* srcResource (id res)
}
}
+- (bool)allPreloaded
+{
+ for (id toload in _imagesToPreload) {
+ if (![_preloaded containsObject:srcResource(toload)])
+ return false;
+ }
+ return true;
+}
+
+- (void)onImageLoad:(NSString *)loaded
+{
+ if (!_preloadingDone) {
+ [_preloaded addObject:loaded];
+ if ([self allPreloaded]) {
+ _preloadingDone = true;
+ [self requestSyncData];
+ }
+ }
+ else {
+ // Any texture image load will trigger a future re-sync of data (if no preloaded)
+ [self requestSyncData];
+ }
+}
+
- (void)setNbContentTextures:(NSNumber *)nbContentTextures
{
[self resizeUniformContentTextures:[nbContentTextures intValue]];
@@ -233,6 +270,7 @@ NSString* srcResource (id res)
- (void)drawRect:(CGRect)rect
{
+ if (!_preloadingDone) return;
BOOL needsDeferredRendering = _nbContentTextures > 0;
if (needsDeferredRendering && !_deferredRendering) {
dispatch_async(dispatch_get_main_queue(), ^{
diff --git a/src/View.js b/src/View.js
index 46b880921f9e5ca84504287e280d825642a7e347..ade72dc42646513fe39dab91f2a458286c7ccd4b 100644
--- a/src/View.js
+++ b/src/View.js
@@ -13,6 +13,7 @@ const GLCanvas = requireNativeComponent("GLCanvas", null);
const renderVcontent = function (width, height, id, children) {
const childrenStyle = {
+ key: id,
position: "absolute",
top: 0,
left: 0,