diff --git a/packages/react-native/Libraries/Network/RCTNetworkTask.mm b/packages/react-native/Libraries/Network/RCTNetworkTask.mm index 47a2e92d0d5..96a7ded6c9c 100644 --- a/packages/react-native/Libraries/Network/RCTNetworkTask.mm +++ b/packages/react-native/Libraries/Network/RCTNetworkTask.mm @@ -190,7 +190,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) incrementalDataBlock(data, length, total); }]; } - if (_downloadProgressBlock && total > 0) { + if (_downloadProgressBlock) { RCTURLRequestProgressBlock downloadProgressBlock = _downloadProgressBlock; [self dispatchCallback:^{ downloadProgressBlock(length, total); diff --git a/packages/rn-tester/js/examples/XHR/XHRExampleDownload.js b/packages/rn-tester/js/examples/XHR/XHRExampleDownload.js index e021cb06f1a..70941b73c5f 100644 --- a/packages/rn-tester/js/examples/XHR/XHRExampleDownload.js +++ b/packages/rn-tester/js/examples/XHR/XHRExampleDownload.js @@ -40,6 +40,7 @@ class XHRExampleDownload extends React.Component<{...}, Object> { readystateHandler: false, progressHandler: true, arraybuffer: false, + chunked: false, }; xhr: ?XMLHttpRequest = null; @@ -107,12 +108,19 @@ class XHRExampleDownload extends React.Component<{...}, Object> { Alert.alert('Error', xhr.responseText); } }; - xhr.open( - 'GET', - 'http://aleph.gutenberg.org/cache/epub/100/pg100-images.html.utf8', - ); - // Avoid gzip so we can actually show progress - xhr.setRequestHeader('Accept-Encoding', ''); + if (this.state.chunked) { + xhr.open( + 'GET', + 'https://filesamples.com/samples/ebook/azw3/Around%20the%20World%20in%2028%20Languages.azw3', + ); + } else { + xhr.open( + 'GET', + 'http://aleph.gutenberg.org/cache/epub/100/pg100-images.html.utf8', + ); + // Avoid gzip so we can actually show progress + xhr.setRequestHeader('Accept-Encoding', ''); + } xhr.send(); this.setState({downloading: true}); @@ -133,7 +141,11 @@ class XHRExampleDownload extends React.Component<{...}, Object> { ) : ( - Download 7MB Text File + + {this.state.chunked + ? 'Download 10MB File' + : 'Download 19KB pdf File'} + ); @@ -188,6 +200,13 @@ class XHRExampleDownload extends React.Component<{...}, Object> { onValueChange={arraybuffer => this.setState({arraybuffer})} /> + + transfer-encoding: chunked + this.setState({chunked})} + /> + {button} {readystate} {progress}