Skip to content

Commit b09ee92

Browse files
committed
#200 optimize for zero listeners on ios
1 parent 48cb17a commit b09ee92

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

ios/RNZipArchive.m

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,26 @@
1616
#endif
1717

1818
@implementation RNZipArchive
19+
{
20+
bool hasListeners;
21+
}
1922

2023
@synthesize bridge = _bridge;
2124

2225
RCT_EXPORT_MODULE();
2326

27+
// Will be called when this module's first listener is added.
28+
-(void)startObserving {
29+
hasListeners = YES;
30+
// Set up any upstream listeners or background tasks as necessary
31+
}
32+
33+
// Will be called when this module's last listener is removed, or on dealloc.
34+
-(void)stopObserving {
35+
hasListeners = NO;
36+
// Remove upstream listeners, stop unnecessary background tasks
37+
}
38+
2439
- (NSArray<NSString *> *)supportedEvents
2540
{
2641
return @[@"zipArchiveProgressEvent"];
@@ -201,7 +216,9 @@ - (void)setProgressHandler {
201216
}
202217

203218
- (void)dispatchProgessEvent:(float)progress processedFilePath:(NSString *)processedFilePath {
204-
[self sendEventWithName:@"zipArchiveProgressEvent" body:@{@"progress": @(progress), @"filePath": processedFilePath}];
219+
if (hasListeners) {
220+
[self sendEventWithName:@"zipArchiveProgressEvent" body:@{@"progress": @(progress), @"filePath": processedFilePath}];
221+
}
205222
}
206223

207224
@end

0 commit comments

Comments
 (0)