From f3527bb883bfa95597fb5b1b53f685291283bae7 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Mon, 14 Aug 2017 10:54:33 -0700 Subject: [PATCH] Show bundle download progress on iOS Summary: This shows progress for the download of the JS bundle (different from the packager transform progress that we show already). This is useful especially when loading the JS bundle from a remote source or when developing on device (on simulator + localhost it pretty much just downloads instantly). This will be nice for the expo client since all bundles are loaded over the network and can take several seconds to load. This depends on https://github.com/facebook/metro-bundler/pull/28 to work but won't crash or anything without it, it just won't show the progress percentage. ![img_05070155d2cc-1](https://user-images.githubusercontent.com/2677334/28293828-2c08d974-6b24-11e7-9334-e106ef3326d9.jpeg) **Test plan** Tested that bundle download progress is shown properly in RNTester on both localhost + simulator and on real device with network conditionner to simulate a slow loading bundle. Tested that it doesn't cause issues if the packager doesn't send the Content-Length header. Closes https://github.com/facebook/react-native/pull/15066 Differential Revision: D5449073 Pulled By: shergin fbshipit-source-id: 43a8fb559393bbdc04f77916500e21898695bac5 --- .../RCTMultipartStreamReaderTests.m | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/RNTesterUnitTests/RCTMultipartStreamReaderTests.m b/RNTesterUnitTests/RCTMultipartStreamReaderTests.m index 20df842757a..c92a505a9ec 100644 --- a/RNTesterUnitTests/RCTMultipartStreamReaderTests.m +++ b/RNTesterUnitTests/RCTMultipartStreamReaderTests.m @@ -31,12 +31,12 @@ - (void)testSimpleCase { NSInputStream *inputStream = [NSInputStream inputStreamWithData:[response dataUsingEncoding:NSUTF8StringEncoding]]; RCTMultipartStreamReader *reader = [[RCTMultipartStreamReader alloc] initWithInputStream:inputStream boundary:@"sample_boundary"]; __block NSInteger count = 0; - BOOL success = [reader readAllParts:^(NSDictionary *headers, NSData *content, BOOL done) { + BOOL success = [reader readAllPartsWithCompletionCallback:^(NSDictionary *headers, NSData *content, BOOL done) { XCTAssertTrue(done); XCTAssertEqualObjects(headers[@"Content-Type"], @"application/json; charset=utf-8"); XCTAssertEqualObjects([[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding], @"{}"); count++; - }]; + } progressCallback: nil]; XCTAssertTrue(success); XCTAssertEqual(count, 1); } @@ -56,13 +56,13 @@ - (void)testMultipleParts { NSInputStream *inputStream = [NSInputStream inputStreamWithData:[response dataUsingEncoding:NSUTF8StringEncoding]]; RCTMultipartStreamReader *reader = [[RCTMultipartStreamReader alloc] initWithInputStream:inputStream boundary:@"sample_boundary"]; __block NSInteger count = 0; - BOOL success = [reader readAllParts:^(__unused NSDictionary *headers, NSData *content, BOOL done) { + BOOL success = [reader readAllPartsWithCompletionCallback:^(__unused NSDictionary *headers, NSData *content, BOOL done) { count++; XCTAssertEqual(done, count == 3); NSString *expectedBody = [NSString stringWithFormat:@"%ld", (long)count]; NSString *actualBody = [[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding]; XCTAssertEqualObjects(actualBody, expectedBody); - }]; + } progressCallback:nil]; XCTAssertTrue(success); XCTAssertEqual(count, 3); } @@ -73,9 +73,9 @@ - (void)testNoDelimiter { NSInputStream *inputStream = [NSInputStream inputStreamWithData:[response dataUsingEncoding:NSUTF8StringEncoding]]; RCTMultipartStreamReader *reader = [[RCTMultipartStreamReader alloc] initWithInputStream:inputStream boundary:@"sample_boundary"]; __block NSInteger count = 0; - BOOL success = [reader readAllParts:^(__unused NSDictionary *headers, __unused NSData *content, __unused BOOL done) { + BOOL success = [reader readAllPartsWithCompletionCallback:^(__unused NSDictionary *headers, __unused NSData *content, __unused BOOL done) { count++; - }]; + } progressCallback:nil]; XCTAssertFalse(success); XCTAssertEqual(count, 0); } @@ -93,9 +93,9 @@ - (void)testNoCloseDelimiter { NSInputStream *inputStream = [NSInputStream inputStreamWithData:[response dataUsingEncoding:NSUTF8StringEncoding]]; RCTMultipartStreamReader *reader = [[RCTMultipartStreamReader alloc] initWithInputStream:inputStream boundary:@"sample_boundary"]; __block NSInteger count = 0; - BOOL success = [reader readAllParts:^(__unused NSDictionary *headers, __unused NSData *content, __unused BOOL done) { + BOOL success = [reader readAllPartsWithCompletionCallback:^(__unused NSDictionary *headers, __unused NSData *content, __unused BOOL done) { count++; - }]; + } progressCallback:nil]; XCTAssertFalse(success); XCTAssertEqual(count, 1); }