-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tracing-ttd): Implement fallback system to screens that aren't re…
…porting on the native layer the time to display. (#4042)
- Loading branch information
1 parent
ac41368
commit e630bf9
Showing
18 changed files
with
516 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,5 +55,4 @@ public List<ViewManager> createViewManagers( | |
new RNSentryOnDrawReporterManager(reactContext) | ||
); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
android/src/main/java/io/sentry/react/RNSentryTimeToDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.sentry.react; | ||
|
||
import com.facebook.react.bridge.Promise; | ||
|
||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.view.Choreographer; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import io.sentry.SentryDate; | ||
import io.sentry.SentryDateProvider; | ||
import io.sentry.android.core.SentryAndroidDateProvider; | ||
|
||
public class RNSentryTimeToDisplay { | ||
public static void GetTimeToDisplay(Promise promise, SentryDateProvider dateProvider) { | ||
Looper mainLooper = Looper.getMainLooper(); | ||
|
||
if (mainLooper == null) { | ||
promise.reject("GetTimeToDisplay is not able to measure the time to display: Main looper not available."); | ||
return; | ||
} | ||
|
||
// Ensure the code runs on the main thread | ||
new Handler(mainLooper) | ||
.post(() -> { | ||
try { | ||
Choreographer choreographer = Choreographer.getInstance(); | ||
|
||
// Invoke the callback after the frame is rendered | ||
choreographer.postFrameCallback(frameTimeNanos -> { | ||
final SentryDate endDate = dateProvider.now(); | ||
promise.resolve(endDate.nanoTimestamp() / 1e9); | ||
}); | ||
} catch (Exception exception) { | ||
promise.reject("Failed to receive the instance of Choreographer", exception); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface RNSentryTimeToDisplay : NSObject | ||
|
||
- (void)getTimeToDisplay:(RCTResponseSenderBlock)callback; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#import "RNSentryTimeToDisplay.h" | ||
#import <QuartzCore/QuartzCore.h> | ||
#import <React/RCTLog.h> | ||
|
||
@implementation RNSentryTimeToDisplay | ||
{ | ||
CADisplayLink *displayLink; | ||
RCTResponseSenderBlock resolveBlock; | ||
} | ||
|
||
// Rename requestAnimationFrame to getTimeToDisplay | ||
- (void)getTimeToDisplay:(RCTResponseSenderBlock)callback | ||
{ | ||
// Store the resolve block to use in the callback. | ||
resolveBlock = callback; | ||
|
||
#if TARGET_OS_IOS | ||
// Create and add a display link to get the callback after the screen is rendered. | ||
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(handleDisplayLink:)]; | ||
[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; | ||
#else | ||
resolveBlock(@[]); // Return nothing if not iOS. | ||
#endif | ||
} | ||
|
||
#if TARGET_OS_IOS | ||
- (void)handleDisplayLink:(CADisplayLink *)link { | ||
// Get the current time | ||
NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970] * 1000.0; // Convert to milliseconds | ||
|
||
// Ensure the callback is valid and pass the current time back | ||
if (resolveBlock) { | ||
resolveBlock(@[@(currentTime)]); // Call the callback with the current time | ||
resolveBlock = nil; // Clear the block after it's called | ||
} | ||
|
||
// Invalidate the display link to stop future callbacks | ||
[displayLink invalidate]; | ||
displayLink = nil; | ||
} | ||
#endif | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.