File tree 2 files changed +23
-4
lines changed
2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -440,7 +440,9 @@ - (RCTImageLoaderCancellationBlock)_loadURLRequest:(NSURLRequest *)request
440
440
441
441
// Download image
442
442
__weak __typeof (self) weakSelf = self;
443
- RCTNetworkTask *task = [networking networkTaskWithRequest: request completionBlock: ^(NSURLResponse *response, NSData *data, NSError *error) {
443
+ __block RCTNetworkTask *task =
444
+ [networking networkTaskWithRequest: request
445
+ completionBlock: ^(NSURLResponse *response, NSData *data, NSError *error) {
444
446
__typeof (self) strongSelf = weakSelf;
445
447
if (!strongSelf) {
446
448
return ;
@@ -480,8 +482,15 @@ - (RCTImageLoaderCancellationBlock)_loadURLRequest:(NSURLRequest *)request
480
482
}
481
483
482
484
return ^{
483
- [task cancel ];
484
- [weakSelf dequeueTasks ];
485
+ __typeof (self) strongSelf = weakSelf;
486
+ if (!strongSelf || !task) {
487
+ return ;
488
+ }
489
+ dispatch_async (strongSelf->_URLRequestQueue , ^{
490
+ [task cancel ];
491
+ task = nil ;
492
+ });
493
+ [strongSelf dequeueTasks ];
485
494
};
486
495
}
487
496
@@ -496,7 +505,7 @@ - (RCTImageLoaderCancellationBlock)loadImageWithURLRequest:(NSURLRequest *)image
496
505
__block volatile uint32_t cancelled = 0 ;
497
506
__block dispatch_block_t cancelLoad = nil ;
498
507
dispatch_block_t cancellationBlock = ^{
499
- if (cancelLoad) {
508
+ if (cancelLoad && !cancelled ) {
500
509
cancelLoad ();
501
510
}
502
511
OSAtomicOr32Barrier (1 , &cancelled);
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ - (void)invalidate
53
53
_incrementalDataBlock = nil ;
54
54
_responseBlock = nil ;
55
55
_uploadProgressBlock = nil ;
56
+ _requestToken = nil ;
56
57
}
57
58
58
59
- (void )dispatchCallback : (dispatch_block_t )callback
@@ -66,6 +67,11 @@ - (void)dispatchCallback:(dispatch_block_t)callback
66
67
67
68
- (void )start
68
69
{
70
+ if (_status != RCTNetworkTaskPending) {
71
+ RCTLogError (@" RCTNetworkTask was already started or completed" );
72
+ return ;
73
+ }
74
+
69
75
if (_requestToken == nil ) {
70
76
id token = [_handler sendRequest: _request withDelegate: self ];
71
77
if ([self validateRequestToken: token]) {
@@ -77,6 +83,10 @@ - (void)start
77
83
78
84
- (void )cancel
79
85
{
86
+ if (_status == RCTNetworkTaskFinished) {
87
+ return ;
88
+ }
89
+
80
90
_status = RCTNetworkTaskFinished;
81
91
id token = _requestToken;
82
92
if (token && [_handler respondsToSelector: @selector (cancelRequest: )]) {
You can’t perform that action at this time.
0 commit comments