Skip to content

Commit

Permalink
Show bundle download progress on iOS
Browse files Browse the repository at this point in the history
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 facebook/metro#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 facebook/react-native#15066

Differential Revision: D5449073

Pulled By: shergin

fbshipit-source-id: 43a8fb559393bbdc04f77916500e21898695bac5
  • Loading branch information
janicduplessis authored and facebook-github-bot committed Aug 14, 2017
1 parent 231ce36 commit f3527bb
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions RNTesterUnitTests/RCTMultipartStreamReaderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit f3527bb

Please sign in to comment.