GLCanvas.m 17.4 KB
Newer Older
1 2 3
#import "RCTBridge.h"
#import "RCTUtils.h"
#import "RCTConvert.h"
4
#import "RCTEventDispatcher.h"
5
#import "RCTLog.h"
Dima's avatar
Dima committed
6
#import "RCTProfile.h"
7
#import "RNGLContext.h"
8 9 10 11 12
#import "GLCanvas.h"
#import "GLShader.h"
#import "GLTexture.h"
#import "GLImage.h"
#import "GLRenderData.h"
13
#import "UIView+React.h"
14
#import "RCTImageSource.h"
15

16
NSString* imageSourceHash (RCTImageSource *is) {
Mattias Pfeiffer's avatar
Mattias Pfeiffer committed
17
  return is.request.URL;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
18 19
}

20 21 22 23 24 25 26 27 28 29
NSArray* diff (NSArray* a, NSArray* b) {
  NSMutableArray *arr = [[NSMutableArray alloc] init];
  for (NSString* k in a) {
    if (![b containsObject:k]) {
      [arr addObject:k];
    }
  }
  return arr;
}

30 31 32 33
// For reference, see implementation of gl-shader's GLCanvas

@implementation GLCanvas
{
34
  RCTBridge *_bridge;
35

36
  GLRenderData *_renderData;
37

38
  NSArray *_contentData;
39
  NSArray *_contentTextures;
40
  NSDictionary *_images; // This caches the currently used images (imageSrc -> GLReactImage)
41

42
  BOOL _deferredRendering; // This flag indicates a render has been deferred to the next frame (when using contents)
43

44
  GLint defaultFBO;
45

46
  NSMutableArray *_preloaded;
47 48
  BOOL _dirtyOnLoad;
  BOOL _neverRendered;
49

50
  NSTimer *animationTimer;
51

52
  BOOL _needSync;
53

54 55
  NSMutableArray *_captureConfigs;
  BOOL _captureScheduled;
56 57 58 59 60 61 62
}

- (instancetype)initWithBridge:(RCTBridge *)bridge
{
  if ((self = [super init])) {
    _bridge = bridge;
    _images = @{};
63
    _preloaded = [[NSMutableArray alloc] init];
64 65
    _captureConfigs = [[NSMutableArray alloc] init];
    _captureScheduled = false;
66 67
    _dirtyOnLoad = true;
    _neverRendered = true;
68
    self.context = [bridge.rnglContext getContext];
69 70 71 72 73 74
  }
  return self;
}

RCT_NOT_IMPLEMENTED(-init)

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
- (void)dealloc
{
  _bridge = nil;
  _images = nil;
  _preloaded = nil;
  _captureConfigs = nil;
  _contentData = nil;
  _contentTextures = nil;
  _data = nil;
  _renderData = nil;
  if (animationTimer) {
    [animationTimer invalidate];
    animationTimer = nil;
  }
}

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
91 92
//// Props Setters

93
- (void) requestCaptureFrame: (CaptureConfig *)config
94 95
{
  [self setNeedsDisplay];
96 97 98 99 100 101
  for (CaptureConfig *existing in _captureConfigs) {
    if ([existing isEqualToCaptureConfig:config]) {
      return;
    }
  }
  [_captureConfigs addObject:config];
102 103
}

104 105 106
-(void)setImagesToPreload:(NSArray *)imagesToPreload
{
  _imagesToPreload = imagesToPreload;
107
  [self requestSyncData];
108
}
109

110 111
- (void)setRenderId:(NSNumber *)renderId
{
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
112
  if ([_nbContentTextures intValue] > 0) {
113 114 115 116
    [self setNeedsDisplay];
  }
}

117 118
- (void)setAutoRedraw:(BOOL)autoRedraw
{
119
  _autoRedraw = autoRedraw;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
120 121 122 123 124 125
  [self performSelectorOnMainThread:@selector(syncAutoRedraw) withObject:nil waitUntilDone:false];
}

- (void)syncAutoRedraw
{
  if (_autoRedraw) {
126
    if (!animationTimer)
127
      animationTimer =
128 129
      [NSTimer scheduledTimerWithTimeInterval:1.0/60.0
                                       target:self
130
                                     selector:@selector(autoRedrawUpdate)
131 132 133 134 135 136 137 138 139 140
                                     userInfo:nil
                                      repeats:YES];
  }
  else {
    if (animationTimer) {
      [animationTimer invalidate];
    }
  }
}

141
- (void)setPointerEvents:(RCTPointerEvents)pointerEvents
142
{
143 144 145 146
  self.userInteractionEnabled = (pointerEvents != RCTPointerEventsNone);
  if (pointerEvents == RCTPointerEventsBoxNone) {
    self.accessibilityViewIsModal = NO;
  }
147 148
}

149 150 151 152 153 154
- (void)setPixelRatio:(NSNumber *)pixelRatio
{
  self.contentScaleFactor = [pixelRatio floatValue];
  [self setNeedsDisplay];
}

155 156 157
- (void)setData:(GLData *)data
{
  _data = data;
158
  _renderData = nil;
159 160 161
  [self requestSyncData];
}

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
162 163 164 165 166
- (void)setNbContentTextures:(NSNumber *)nbContentTextures
{
  _nbContentTextures = nbContentTextures;
}

167 168 169 170 171 172
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
  CGFloat alpha = CGColorGetAlpha(backgroundColor.CGColor);
  self.opaque = (alpha == 1.0);
}

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
173 174
//// Sync methods (called from props setters)

175 176
- (void)requestSyncData
{
177 178
  _needSync = true;
  [self setNeedsDisplay];
179 180
}

181
- (bool)syncData:(NSError **)error
182 183
{
  @autoreleasepool {
184

185 186
    NSDictionary *prevImages = _images;
    NSMutableDictionary *images = [[NSMutableDictionary alloc] init];
187

188 189 190
    GLRenderData * (^traverseTree) (GLData *data);
    __block __weak GLRenderData * (^weak_traverseTree)(GLData *data);
    weak_traverseTree = traverseTree = ^GLRenderData *(GLData *data) {
191 192
      NSNumber *width = data.width;
      NSNumber *height = data.height;
193
      NSNumber *pixelRatio = data.pixelRatio;
194
      int fboId = [data.fboId intValue];
195

196 197
      NSMutableArray *contextChildren = [[NSMutableArray alloc] init];
      for (GLData *child in data.contextChildren) {
198 199 200
        GLRenderData *node = weak_traverseTree(child);
        if (node == nil) return nil;
        [contextChildren addObject:node];
201
      }
202

203 204
      NSMutableArray *children = [[NSMutableArray alloc] init];
      for (GLData *child in data.children) {
205 206 207
        GLRenderData *node = weak_traverseTree(child);
        if (node == nil) return nil;
        [children addObject:node];
208
      }
209

210
      GLShader *shader = [_bridge.rnglContext getShader:data.shader];
211
      if (shader == nil) return nil;
212
      if (![shader ensureCompiles:error]) return nil;
213

214 215 216 217 218 219 220
      NSDictionary *uniformTypes = [shader uniformTypes];
      NSMutableDictionary *uniforms = [[NSMutableDictionary alloc] init];
      NSMutableDictionary *textures = [[NSMutableDictionary alloc] init];
      int units = 0;
      for (NSString *uniformName in data.uniforms) {
        id value = [data.uniforms objectForKey:uniformName];
        GLenum type = [uniformTypes[uniformName] intValue];
221 222


223
        if (type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE) {
224
          uniforms[uniformName] = [NSNumber numberWithInt:units++];
225
          if ([value isEqual:[NSNull null]]) {
226
            GLTexture *emptyTexture = [[GLTexture alloc] init];
227
            [emptyTexture setPixels:nil];
228
            textures[uniformName] = emptyTexture;
229
          }
230 231 232
          else if ([value isKindOfClass:[NSNumber class]]) {
            RCTLogError(@"texture uniform '%@': you cannot directly give require('./img.png') to gl-react, use resolveAssetSource(require('./img.png')) instead.", uniformName);
          }
233 234 235 236 237 238 239 240
          else {
            NSString *type = [RCTConvert NSString:value[@"type"]];
            if ([type isEqualToString:@"content"]) {
              int id = [[RCTConvert NSNumber:value[@"id"]] intValue];
              if (id >= [_contentTextures count]) {
                [self resizeUniformContentTextures:id+1];
              }
              textures[uniformName] = _contentTextures[id];
241
            }
242 243
            else if ([type isEqualToString:@"fbo"]) {
              NSNumber *id = [RCTConvert NSNumber:value[@"id"]];
244
              GLFBO *fbo = [_bridge.rnglContext getFBO:id];
245 246 247
              textures[uniformName] = fbo.color[0];
            }
            else if ([type isEqualToString:@"uri"]) {
248
              RCTImageSource *src = [RCTConvert RCTImageSource:value];
249
              if (!src) {
250 251 252
                GLTexture *emptyTexture = [[GLTexture alloc] init];
                [emptyTexture setPixels:nil];
                textures[uniformName] = emptyTexture;
253
              }
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
              else {
                NSString *key = imageSourceHash(src);
                GLImage *image = images[key];
                if (image == nil) {
                  image = prevImages[key];
                  if (image != nil)
                    images[key] = image;
                }
                if (image == nil) {
                  __weak GLCanvas *weakSelf = self;
                  image = [[GLImage alloc] initWithBridge:_bridge withOnLoad:^{
                    if (weakSelf) [weakSelf onImageLoad:src];
                  }];
                  image.source = src;
                  images[key] = image;
                }
                textures[uniformName] = [image getTexture];
271
              }
272
            }
273 274
            else {
              RCTLogError(@"texture uniform '%@': Unexpected type '%@'", uniformName, type);
275 276 277 278 279 280 281
            }
          }
        }
        else {
          uniforms[uniformName] = value;
        }
      }
282

283 284 285 286 287
      int maxTextureUnits;
      glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
      if (units > maxTextureUnits) {
        RCTLogError(@"Maximum number of texture reach. got %i >= max %i", units, maxTextureUnits);
      }
288

289
      for (NSString *uniformName in shader.uniformNames) {
290 291 292 293
        if (uniforms[uniformName] == nil) {
          RCTLogError(@"All defined uniforms must be provided. Missing '%@'", uniformName);
        }
      }
294

295 296 297 298
      return [[GLRenderData alloc]
              initWithShader:shader
              withUniforms:uniforms
              withTextures:textures
299 300
              withWidth:(int)([width floatValue] * [pixelRatio floatValue])
              withHeight:(int)([height floatValue] * [pixelRatio floatValue])
301 302
              withFboId:fboId
              withContextChildren:contextChildren
303
              withChildren:children];
304
    };
305

306 307 308 309
    GLRenderData *res = traverseTree(_data);
    if (res != nil) {
      _renderData = traverseTree(_data);
      _images = images;
310 311 312
      for (NSString *src in diff([prevImages allKeys], [images allKeys])) {
        [_preloaded removeObject:src];
      }
313
      return true;
314
    }
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
315
    else {
316
      return false;
317
    }
318 319 320
  }
}

321
- (void)syncContentData
322
{
323
  RCT_PROFILE_BEGIN_EVENT(0, @"GLCanvas syncContentData", nil);
324 325 326 327 328
  NSMutableArray *contentData = [[NSMutableArray alloc] init];
  int nb = [_nbContentTextures intValue];
  for (int i = 0; i < nb; i++) {
    UIView *view = self.superview.subviews[i]; // We take siblings by index (closely related to the JS code)
    GLImageData *imgData = nil;
329
    if (view) {
330 331 332
      UIView *v = [view.subviews count] == 1 ?
      view.subviews[0] :
      view;
333
      imgData = [GLImageData genPixelsWithView:v withPixelRatio:self.contentScaleFactor];
334
    } else {
335
      imgData = nil;
336
    }
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
337
    if (imgData) contentData[i] = imgData;
338 339
  }
  _contentData = contentData;
340
  [self setNeedsDisplay];
Mattias Pfeiffer's avatar
Mattias Pfeiffer committed
341
  RCT_PROFILE_END_EVENT(0, @"gl");
342 343 344 345 346 347 348 349
}


- (void)syncContentTextures
{
  unsigned long max = MIN([_contentData count], [_contentTextures count]);
  for (int i=0; i<max; i++) {
    [_contentTextures[i] setPixels:_contentData[i]];
350 351 352
  }
}

353 354 355
- (BOOL)haveRemainingToPreload
{
  for (id res in _imagesToPreload) {
356
    if (![_preloaded containsObject:imageSourceHash([RCTConvert RCTImageSource:res])]) {
357 358 359 360 361 362
      return true;
    }
  }
  return false;
}

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
363 364 365

//// Draw

366
- (void) autoRedrawUpdate
367
{
368 369 370 371 372
  if ([self haveRemainingToPreload]) {
    return;
  }
  if ([_nbContentTextures intValue] > 0) {
    [self syncContentData];
373
  }
374 375 376
  [self setNeedsDisplay];
}

377 378
- (void)drawRect:(CGRect)rect
{
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
379 380
  if (_neverRendered) {
    _neverRendered = false;
381 382
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
383
  }
384

385
  if (_needSync) {
386
    NSError *error;
387 388 389 390 391
    BOOL syncSuccessful = [self syncData:&error];
    BOOL errorCanBeRecovered = error==nil || (error.code != GLLinkingFailure && error.code != GLCompileFailure);
    if (!syncSuccessful && errorCanBeRecovered) {
      // something failed but is recoverable, retry in one tick
      [self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
392 393 394 395
    }
    else {
      _needSync = false;
    }
396
  }
397

398
  if ([self haveRemainingToPreload]) {
399 400
    return;
  }
401

402 403
  BOOL needsDeferredRendering = [_nbContentTextures intValue] > 0 && !_autoRedraw;
  if (needsDeferredRendering && !_deferredRendering) {
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
404
    _deferredRendering = true;
405
    [self performSelectorOnMainThread:@selector(syncContentData) withObject:nil waitUntilDone:NO];
406
  }
407 408
  else {
    _deferredRendering = false;
409
    [self render];
410 411
    if (!_captureScheduled && [_captureConfigs count] > 0) {
      _captureScheduled = true;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
412
      [self performSelectorOnMainThread:@selector(capture) withObject:nil waitUntilDone:NO];
413
    }
414 415 416
  }
}

417
-(void) capture
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
418
{
419 420
  _captureScheduled = false;
  if (!self.onGLCaptureFrame) return;
421

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
422
  UIImage *frameImage = [self snapshot];
423

424 425 426
  for (CaptureConfig *config in _captureConfigs) {
    id result;
    id error;
427

428 429
    BOOL isPng = [config.type isEqualToString:@"png"];
    BOOL isJpeg = !isPng && ([config.type isEqualToString:@"jpeg"] || [config.type isEqualToString:@"jpg"]);
430

431 432
    BOOL isBase64 = [config.format isEqualToString:@"base64"];
    BOOL isFile = !isBase64 && [config.format isEqualToString:@"file"];
433

434 435 436 437
    NSData *frameData =
    isPng ? UIImagePNGRepresentation(frameImage) :
    isJpeg ? UIImageJPEGRepresentation(frameImage, [config.quality floatValue]) :
    nil;
438

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
    if (!frameData) {
      error = [NSString stringWithFormat:@"Unsupported capture type '%@'", config.type];
    }
    else if (isBase64) {
      NSString *base64 = [frameData base64EncodedStringWithOptions: NSDataBase64Encoding64CharacterLineLength];
      result = [NSString stringWithFormat:@"data:image/%@;base64,%@", config.type, base64];
    }
    else if (isFile) {
      NSError *e;
      if (![frameData writeToFile:config.filePath options:0 error:&e]) {
        error = [NSString stringWithFormat:@"Could not write file: %@", e.localizedDescription];
      }
      else {
        result = [NSString stringWithFormat:@"file://%@", config.filePath];
      }
    }
    else {
      error = [NSString stringWithFormat:@"Unsupported capture format '%@'", config.format];
    }
458

459 460 461 462 463 464
    NSMutableDictionary *response = [[NSMutableDictionary alloc] init];
    response[@"config"] = [config dictionary];
    if (error) response[@"error"] = error;
    if (result) response[@"result"] = result;
    self.onGLCaptureFrame(response);
  }
465

466
  _captureConfigs = [[NSMutableArray alloc] init];
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
467 468
}

469
- (void)render
470
{
471 472
  GLRenderData *rd = _renderData;
  if (!rd) return;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
473
  RCT_PROFILE_BEGIN_EVENT(0, @"GLCanvas render", nil);
474

475
  @autoreleasepool {
476

477 478 479
    void (^recDraw) (GLRenderData *renderData);
    __block __weak void (^weak_recDraw) (GLRenderData *renderData);
    weak_recDraw = recDraw = ^void(GLRenderData *renderData) {
480 481
      int w = renderData.width;
      int h = renderData.height;
482

483 484
      for (GLRenderData *child in renderData.contextChildren)
        weak_recDraw(child);
485

486
      for (GLRenderData *child in renderData.children)
487
        weak_recDraw(child);
488

Mattias Pfeiffer's avatar
Mattias Pfeiffer committed
489 490
      NSString *nodeName = [NSString stringWithFormat:@"node:%@", renderData.shader.name];
      RCT_PROFILE_BEGIN_EVENT(0, nodeName, nil);
491 492

      RCT_PROFILE_BEGIN_EVENT(0, @"bind fbo", nil);
493
      if (renderData.fboId == -1) {
494 495
        glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
        glViewport(0, 0, w, h);
496
        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
497 498
      }
      else {
499
        GLFBO *fbo = [_bridge.rnglContext getFBO:[NSNumber numberWithInt:renderData.fboId]];
500 501
        [fbo setShapeWithWidth:w withHeight:h];
        [fbo bind];
502
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
503
      }
Mattias Pfeiffer's avatar
Mattias Pfeiffer committed
504
      RCT_PROFILE_END_EVENT(0, @"gl");
505

506
      RCT_PROFILE_BEGIN_EVENT(0, @"bind shader", nil);
507
      [renderData.shader bind];
Mattias Pfeiffer's avatar
Mattias Pfeiffer committed
508
      RCT_PROFILE_END_EVENT(0, @"gl");
509

510
      RCT_PROFILE_BEGIN_EVENT(0, @"bind textures", nil);
511 512 513 514 515
      for (NSString *uniformName in renderData.textures) {
        GLTexture *texture = renderData.textures[uniformName];
        int unit = [((NSNumber *)renderData.uniforms[uniformName]) intValue];
        [texture bind:unit];
      }
Mattias Pfeiffer's avatar
Mattias Pfeiffer committed
516
      RCT_PROFILE_END_EVENT(0, @"gl");
517

518
      RCT_PROFILE_BEGIN_EVENT(0, @"bind set uniforms", nil);
519 520 521
      for (NSString *uniformName in renderData.uniforms) {
        [renderData.shader setUniform:uniformName withValue:renderData.uniforms[uniformName]];
      }
Mattias Pfeiffer's avatar
Mattias Pfeiffer committed
522
      RCT_PROFILE_END_EVENT(0, @"gl");
523

524
      RCT_PROFILE_BEGIN_EVENT(0, @"draw", nil);
525 526
      glClearColor(0.0, 0.0, 0.0, 0.0);
      glClear(GL_COLOR_BUFFER_BIT);
527
      glDrawArrays(GL_TRIANGLES, 0, 3);
Mattias Pfeiffer's avatar
Mattias Pfeiffer committed
528
      RCT_PROFILE_END_EVENT(0, @"gl");
529

Mattias Pfeiffer's avatar
Mattias Pfeiffer committed
530
      RCT_PROFILE_END_EVENT(0, @"gl");
531
    };
532

533
    // DRAWING THE SCENE
534

535
    [self syncContentTextures];
536

537
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
538
    glEnable(GL_BLEND);
539
    recDraw(rd);
540
    glDisable(GL_BLEND);
541
    glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
542
    glBindBuffer(GL_ARRAY_BUFFER, 0);
543

544 545 546 547
    if (_dirtyOnLoad && ![self haveRemainingToPreload]) {
      _dirtyOnLoad = false;
      [self dispatchOnLoad];
    }
548
  }
549

Mattias Pfeiffer's avatar
Mattias Pfeiffer committed
550
  RCT_PROFILE_END_EVENT(0, @"gl");
551 552
}

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
553 554
//// utility methods

555
- (void)onImageLoad:(RCTImageSource *)source
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
556
{
557
  [_preloaded addObject:imageSourceHash(source)];
558 559 560 561 562 563
  int count = [self countPreloaded];
  int total = (int) [_imagesToPreload count];
  double progress = ((double) count) / ((double) total);
  [self dispatchOnProgress:progress withLoaded:count withTotal:total];
  _dirtyOnLoad = true;
  [self requestSyncData];
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
564 565 566 567 568 569
}

- (int)countPreloaded
{
  int nb = 0;
  for (id toload in _imagesToPreload) {
570
    if ([_preloaded containsObject:imageSourceHash([RCTConvert RCTImageSource:toload])])
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
571 572 573 574
      nb++;
  }
  return nb;
}
575

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
- (void)resizeUniformContentTextures:(int)n
{
  int length = (int) [_contentTextures count];
  if (length == n) return;
  if (n < length) {
    _contentTextures = [_contentTextures subarrayWithRange:NSMakeRange(0, n)];
  }
  else {
    NSMutableArray *contentTextures = [[NSMutableArray alloc] initWithArray:_contentTextures];
    for (int i = (int) [_contentTextures count]; i < n; i++) {
      [contentTextures addObject:[[GLTexture alloc] init]];
    }
    _contentTextures = contentTextures;
  }
}

- (void)dispatchOnLoad
{
594
  if (self.onGLLoad) self.onGLLoad(@{});
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
595 596 597 598
}

- (void)dispatchOnProgress: (double)progress withLoaded:(int)loaded withTotal:(int)total
{
599
  if (self.onGLProgress) self.onGLProgress(
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
600 601 602 603 604
                                           @{
                                             @"progress": @(RCTZeroIfNaN(progress)),
                                             @"loaded": @(RCTZeroIfNaN(loaded)),
                                             @"total": @(RCTZeroIfNaN(total))
                                             });
605 606
}

Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
607
@end