Skip to content

Commit 6ed5a2b

Browse files
authored
Fix initial event emission on iOS and tracing in example app (oblador#91)
1 parent aa6e9fb commit 6ed5a2b

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

examples/vanilla/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const traceRender: ProfilerOnRenderCallback = (
3333
interactions // the Set of interactions belonging to this update
3434
) =>
3535
performance.measure(id, {
36-
start: performance.timeOrigin + startTime,
36+
start: startTime,
3737
duration: actualDuration,
3838
});
3939

examples/vanilla/ios/Example/AppDelegate.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ @implementation AppDelegate
3131

3232
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
3333
{
34-
[RNPerformance.sharedInstance mark:@"appDelegateStart" ephemeral:NO];
3534
RCTAppSetupPrepareApp(application);
3635

3736
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
@@ -58,9 +57,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5857
self.window.rootViewController = rootViewController;
5958
[self.window makeKeyAndVisible];
6059
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
61-
[RNPerformance.sharedInstance metric:@"slowCustomMetric" value:@(420.69) detail:@{ @"unit": @"$DOGE" }];
60+
[RNPerformance.sharedInstance metric:@"slowCustomMetric" value:@(420.69) detail:@{ @"unit": @"$DOGE" } ephemeral:NO];
6261
});
63-
[RNPerformance.sharedInstance mark:@"appDelegateEnd" ephemeral:NO];
6462
return YES;
6563
}
6664

packages/react-native-performance/ios/RNPerformanceManager.mm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,22 @@ - (void)setBridge:(RCTBridge *)bridge
4747
[super setBridge:bridge];
4848
[RNPerformance.sharedInstance clearEphemeralEntries];
4949
[[NSNotificationCenter defaultCenter] addObserver:self
50-
selector:@selector(contentDidAppear)
50+
selector:@selector(emitIfReady)
5151
name:RCTContentDidAppearNotification
5252
object:nil];
53+
[[NSNotificationCenter defaultCenter] addObserver:self
54+
selector:@selector(emitIfReady)
55+
name:RCTJavaScriptDidLoadNotification
56+
object:nil];
5357
[[NSNotificationCenter defaultCenter] addObserver:self
5458
selector:@selector(customEntryWasAdded:)
5559
name:RNPerformanceEntryWasAddedNotification
5660
object:nil];
5761
}
5862

59-
- (void)contentDidAppear
63+
- (void)emitIfReady
6064
{
61-
if(didEmit != YES) {
65+
if (!didEmit && hasListeners && [self.bridge.performanceLogger valueForTag:RCTPLTTI] != 0 && [self.bridge.performanceLogger valueForTag:RCTPLScriptExecution] != 0) {
6266
[self emitEntries];
6367
}
6468
}
@@ -114,7 +118,7 @@ - (void)invalidate
114118
- (void)startObserving
115119
{
116120
hasListeners = YES;
117-
if (didEmit != YES && [self.bridge.performanceLogger valueForTag:RCTPLTTI] != 0) {
121+
if (didEmit != YES && [self.bridge.performanceLogger valueForTag:RCTPLTTI] != 0 && [self.bridge.performanceLogger valueForTag:RCTPLScriptExecution] != 0) {
118122
[self emitEntries];
119123
}
120124
}

0 commit comments

Comments
 (0)