@@ -57,12 +57,9 @@ public void setFullDisplay(RNSentryOnDrawReporterView view, boolean fullDisplay)
57
57
view .setFullDisplay (fullDisplay );
58
58
}
59
59
60
- public Map getExportedCustomBubblingEventTypeConstants () {
61
- return MapBuilder .builder ()
62
- .put (
63
- "onDrawNextFrameView" ,
64
- MapBuilder .of ("phasedRegistrationNames" , MapBuilder .of ("bubbled" , "onDrawNextFrame" )))
65
- .build ();
60
+ @ ReactProp (name = "parentSpanId" )
61
+ public void setParentSpanId (RNSentryOnDrawReporterView view , String parentSpanId ) {
62
+ view .setParentSpanId (parentSpanId );
66
63
}
67
64
68
65
public static class RNSentryOnDrawReporterView extends View {
@@ -71,52 +68,54 @@ public static class RNSentryOnDrawReporterView extends View {
71
68
72
69
private final @ Nullable ReactApplicationContext reactContext ;
73
70
private final @ NotNull SentryDateProvider dateProvider = new SentryAndroidDateProvider ();
74
- private final @ Nullable Runnable emitInitialDisplayEvent ;
75
- private final @ Nullable Runnable emitFullDisplayEvent ;
76
71
private final @ Nullable BuildInfoProvider buildInfo ;
77
72
73
+ private boolean isInitialDisplay = false ;
74
+ private boolean isFullDisplay = false ;
75
+ private @ Nullable String parentSpanId = null ;
76
+
78
77
public RNSentryOnDrawReporterView (@ NotNull Context context ) {
79
78
super (context );
80
79
reactContext = null ;
81
80
buildInfo = null ;
82
- emitInitialDisplayEvent = null ;
83
- emitFullDisplayEvent = null ;
84
81
}
85
82
86
83
public RNSentryOnDrawReporterView (
87
84
@ NotNull ReactApplicationContext context , @ NotNull BuildInfoProvider buildInfoProvider ) {
88
85
super (context );
89
86
reactContext = context ;
90
87
buildInfo = buildInfoProvider ;
91
- emitInitialDisplayEvent = () -> emitDisplayEvent ("initialDisplay" );
92
- emitFullDisplayEvent = () -> emitDisplayEvent ("fullDisplay" );
93
88
}
94
89
95
90
public void setFullDisplay (boolean fullDisplay ) {
96
- if (!fullDisplay ) {
97
- return ;
98
- }
99
-
100
- logger .log (SentryLevel .DEBUG , "[TimeToDisplay] Register full display event emitter." );
101
- registerForNextDraw (emitFullDisplayEvent );
91
+ isFullDisplay = fullDisplay ;
92
+ registerForNextDraw ();
102
93
}
103
94
104
95
public void setInitialDisplay (boolean initialDisplay ) {
105
- if (! initialDisplay ) {
106
- return ;
107
- }
96
+ isInitialDisplay = initialDisplay ;
97
+ registerForNextDraw () ;
98
+ }
108
99
109
- logger .log (SentryLevel .DEBUG , "[TimeToDisplay] Register initial display event emitter." );
110
- registerForNextDraw (emitInitialDisplayEvent );
100
+ public void setParentSpanId (@ Nullable String parentSpanId ) {
101
+ this .parentSpanId = parentSpanId ;
102
+ registerForNextDraw ();
111
103
}
112
104
113
- private void registerForNextDraw (@ Nullable Runnable emitter ) {
114
- if (emitter == null ) {
115
- logger .log (
116
- SentryLevel .ERROR ,
117
- "[TimeToDisplay] Won't emit next frame drawn event, emitter is null." );
105
+ private void registerForNextDraw () {
106
+ if (parentSpanId == null ) {
107
+ return ;
108
+ }
109
+
110
+ if (isInitialDisplay ) {
111
+ logger .log (SentryLevel .DEBUG , "[TimeToDisplay] Register initial display event emitter." );
112
+ } else if (isFullDisplay ) {
113
+ logger .log (SentryLevel .DEBUG , "[TimeToDisplay] Register full display event emitter." );
114
+ } else {
115
+ logger .log (SentryLevel .DEBUG , "[TimeToDisplay] Not ready, missing displayType prop." );
118
116
return ;
119
117
}
118
+
120
119
if (buildInfo == null ) {
121
120
logger .log (
122
121
SentryLevel .ERROR ,
@@ -138,26 +137,23 @@ private void registerForNextDraw(@Nullable Runnable emitter) {
138
137
return ;
139
138
}
140
139
141
- FirstDrawDoneListener .registerForNextDraw (activity , emitter , buildInfo );
142
- }
143
-
144
- private void emitDisplayEvent (String type ) {
145
- final SentryDate endDate = dateProvider .now ();
146
-
147
- WritableMap event = Arguments .createMap ();
148
- event .putString ("type" , type );
149
- event .putDouble ("newFrameTimestampInSeconds" , endDate .nanoTimestamp () / 1e9 );
150
-
151
- if (reactContext == null ) {
152
- logger .log (
153
- SentryLevel .ERROR ,
154
- "[TimeToDisplay] Recorded next frame draw but can't emit the event, reactContext is"
155
- + " null." );
156
- return ;
157
- }
158
- reactContext
159
- .getJSModule (RCTEventEmitter .class )
160
- .receiveEvent (getId (), "onDrawNextFrameView" , event );
140
+ FirstDrawDoneListener .registerForNextDraw (activity , () -> {
141
+ final Double now = dateProvider .now ().nanoTimestamp () / 1e9 ;
142
+ if (parentSpanId == null ) {
143
+ logger .log (
144
+ SentryLevel .ERROR ,
145
+ "[TimeToDisplay] parentSpanId removed before frame was rendered." );
146
+ return ;
147
+ }
148
+
149
+ if (isInitialDisplay ) {
150
+ RNSentryTimeToDisplay .putTimeToDisplayFor ("ttid-" + parentSpanId , now );
151
+ } else if (isFullDisplay ) {
152
+ RNSentryTimeToDisplay .putTimeToDisplayFor ("ttfd-" + parentSpanId , now );
153
+ } else {
154
+ logger .log (SentryLevel .DEBUG , "[TimeToDisplay] display type removed before frame was rendered." );
155
+ }
156
+ }, buildInfo );
161
157
}
162
158
}
163
159
}
0 commit comments