-
-
Notifications
You must be signed in to change notification settings - Fork 365
Expand file tree
/
Copy pathRNSentryOnDrawReporter.m
More file actions
99 lines (81 loc) · 2.61 KB
/
Copy pathRNSentryOnDrawReporter.m
File metadata and controls
99 lines (81 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#import "RNSentryOnDrawReporter.h"
#import "RNSentryEmitNewFrameEvent.h"
#import "RNSentryFramesTrackerListener.h"
#import "RNSentryTimeToDisplay.h"
@import Sentry;
#if SENTRY_HAS_UIKIT
@implementation RNSentryOnDrawReporter
RCT_EXPORT_MODULE(RNSentryOnDrawReporter)
RCT_EXPORT_VIEW_PROPERTY(initialDisplay, BOOL)
RCT_EXPORT_VIEW_PROPERTY(fullDisplay, BOOL)
RCT_EXPORT_VIEW_PROPERTY(parentSpanId, NSString)
- (UIView *)view
{
RNSentryOnDrawReporterView *view = [[RNSentryOnDrawReporterView alloc] init];
return view;
}
@end
@implementation RNSentryOnDrawReporterView {
BOOL isListening;
}
- (instancetype)init
{
self = [super init];
if (self) {
_spanIdUsed = NO;
RNSentryEmitNewFrameEvent emitNewFrameEvent = [self createEmitNewFrameEvent];
_framesListener = [[RNSentryFramesTrackerListener alloc]
initWithSentryFramesTracker:[[SentryDependencyContainer sharedInstance] framesTracker]
andEventEmitter:emitNewFrameEvent];
}
return self;
}
- (RNSentryEmitNewFrameEvent)createEmitNewFrameEvent
{
__weak __typeof__(self) weakSelf = self;
return ^(NSNumber *newFrameTimestampInSeconds) {
__strong __typeof__(weakSelf) strongSelf = weakSelf;
if (strongSelf == nil) {
return;
}
strongSelf->isListening = NO;
if (![strongSelf->_parentSpanId isKindOfClass:[NSString class]]) {
return;
}
if (strongSelf->_fullDisplay) {
[RNSentryTimeToDisplay
putTimeToDisplayFor:[@"ttfd-" stringByAppendingString:strongSelf->_parentSpanId]
value:newFrameTimestampInSeconds];
return;
}
if (strongSelf->_initialDisplay) {
[RNSentryTimeToDisplay
putTimeToDisplayFor:[@"ttid-" stringByAppendingString:strongSelf->_parentSpanId]
value:newFrameTimestampInSeconds];
return;
}
};
}
- (void)didSetProps:(NSArray<NSString *> *)changedProps
{
if (![_parentSpanId isKindOfClass:[NSString class]]) {
_previousParentSpanId = nil;
return;
}
if ([_parentSpanId isEqualToString:_previousParentSpanId] && _spanIdUsed) {
_previousInitialDisplay = _initialDisplay;
_previousFullDisplay = _fullDisplay;
return;
}
_previousParentSpanId = _parentSpanId;
_spanIdUsed = NO;
if (_fullDisplay || _initialDisplay) {
if (!isListening && !_spanIdUsed) {
_spanIdUsed = YES;
isListening = YES;
[_framesListener startListening];
}
}
}
@end
#endif