Skip to content

Commit

Permalink
Added a minor optimisation to prevent sending events when no listener…
Browse files Browse the repository at this point in the history
…s are registered.
  • Loading branch information
jdmunro committed May 7, 2018
1 parent 399b175 commit 8df1e9a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ios/RCTSpotlightSearch/RCTSpotlightSearch/RCTSpotlightSearch.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ @interface RCTSpotlightSearch ()
@property (nonatomic, strong) id<NSObject> continueUserActivityObserver;
@property (nonatomic, strong) id<NSObject> bundleDidLoadObserver;
@property (nonatomic, copy) NSString *initialIdentifier;
@property (nonatomic, assign) BOOL hasListeners;

@end

Expand Down Expand Up @@ -68,6 +69,14 @@ - (dispatch_queue_t)methodQueue {
return dispatch_get_main_queue();
}

- (void)startObserving {
self.hasListeners = YES;
}

- (void)stopObserving {
self.hasListeners = NO;
}

- (void)drainActivityQueue {
NSMutableArray *activityQueue = [[self class] activityQueue];

Expand Down Expand Up @@ -105,6 +114,10 @@ - (void)handleContinueUserActivity:(NSUserActivity *)userActivity {

self.initialIdentifier = uniqueItemIdentifier;

if (!self.hasListeners) {
return;
}

[self sendEventWithName:kSpotlightSearchItemTapped body:uniqueItemIdentifier];
}

Expand Down

0 comments on commit 8df1e9a

Please sign in to comment.