2020
2121#if __has_include(<Firebase/Firebase.h>)
2222#import < Firebase/Firebase.h>
23+ #define RNFB_PERF_SDK_AVAILABLE 1
2324#elif __has_include(<FirebasePerformance/FirebasePerformance.h>)
2425#import < FirebaseCore/FirebaseCore.h>
2526#import < FirebasePerformance/FirebasePerformance.h>
27+ #define RNFB_PERF_SDK_AVAILABLE 1
2628#else
27- @import FirebaseCore;
28- @import FirebasePerformance;
29+ // Product headers absent (typical Mac Catalyst + SPM). Upstream Package.swift
30+ // omits .macCatalyst from FirebasePerformanceTarget; CocoaPods historically
31+ // masked this via the Firebase umbrella. Temporary stubs pending
32+ // https://github.com/firebase/firebase-ios-sdk/pull/16468 (or permanent if
33+ // upstream declines). Never fall through to @import in this .mm — that
34+ // requires -fcxx-modules and breaks RN C++/JSI.
35+ #define RNFB_PERF_SDK_AVAILABLE 0
2936#endif
37+ #import " RNFBApp/RNFBSharedUtils.h"
3038#import " RNFBPerfModule.h"
3139
3240static __strong NSMutableDictionary *traces;
@@ -64,12 +72,28 @@ - (void)invalidate {
6472 }
6573}
6674
75+ #if !RNFB_PERF_SDK_AVAILABLE
76+ - (void )rejectUnavailable : (RCTPromiseRejectBlock)reject {
77+ [RNFBSharedUtils rejectPromiseWithUserInfo: reject
78+ userInfo: (NSMutableDictionary *)@{
79+ @" code" : @" unsupported" ,
80+ @" message" : @" Firebase Performance is not available on "
81+ @" this platform or dependency configuration." ,
82+ }];
83+ }
84+ #endif
85+
6786- (NSDictionary *)perfConstantsDictionary {
6887 NSMutableDictionary *constants = [NSMutableDictionary new ];
88+ #if RNFB_PERF_SDK_AVAILABLE
6989 constants[@" isPerformanceCollectionEnabled" ] =
7090 @([RCTConvert BOOL: @([FIRPerformance sharedInstance ].dataCollectionEnabled)]);
7191 constants[@" isInstrumentationEnabled" ] =
7292 @([RCTConvert BOOL: @([FIRPerformance sharedInstance ].instrumentationEnabled)]);
93+ #else
94+ constants[@" isPerformanceCollectionEnabled" ] = @(NO );
95+ constants[@" isInstrumentationEnabled" ] = @(NO );
96+ #endif
7397 return constants;
7498}
7599
@@ -89,27 +113,45 @@ - (NSDictionary *)perfConstantsDictionary {
89113- (void )setPerformanceCollectionEnabled : (BOOL )enabled
90114 resolve : (RCTPromiseResolveBlock)resolve
91115 reject : (RCTPromiseRejectBlock)reject {
116+ #if RNFB_PERF_SDK_AVAILABLE
92117 [FIRPerformance sharedInstance ].dataCollectionEnabled = (BOOL )enabled;
93118 resolve ([NSNull null ]);
119+ #else
120+ (void )enabled;
121+ (void )resolve;
122+ [self rejectUnavailable: reject];
123+ #endif
94124}
95125
96126- (void )instrumentationEnabled : (BOOL )enabled
97127 resolve : (RCTPromiseResolveBlock)resolve
98128 reject : (RCTPromiseRejectBlock)reject {
129+ #if RNFB_PERF_SDK_AVAILABLE
99130 [FIRPerformance sharedInstance ].instrumentationEnabled = (BOOL )enabled;
100131 resolve ([NSNull null ]);
132+ #else
133+ (void )enabled;
134+ (void )resolve;
135+ [self rejectUnavailable: reject];
136+ #endif
101137}
102138
103139- (void )startTrace : (double )id identifier : (NSString *)identifier {
140+ #if RNFB_PERF_SDK_AVAILABLE
104141 FIRTrace *trace = [[FIRPerformance sharedInstance ] traceWithName: identifier];
105142 [trace start ];
106143
107144 @synchronized ([self class ]) {
108145 traces[@((int )id )] = trace;
109146 }
147+ #else
148+ (void )id ;
149+ (void )identifier;
150+ #endif
110151}
111152
112153- (void )stopTrace : (double )id traceData : (JS ::NativeRNFBTurboPerf::TraceData &)traceData {
154+ #if RNFB_PERF_SDK_AVAILABLE
113155 FIRTrace *trace;
114156 @synchronized ([self class ]) {
115157 trace = traces[@((int )id )];
@@ -132,17 +174,25 @@ - (void)stopTrace:(double)id traceData:(JS::NativeRNFBTurboPerf::TraceData &)tra
132174 @synchronized ([self class ]) {
133175 [traces removeObjectForKey: @((int )id )];
134176 }
177+ #else
178+ (void )id ;
179+ (void )traceData;
180+ #endif
135181}
136182
137183- (void )startScreenTrace : (double )id identifier : (NSString *)identifier {
138184 // Custom screen traces are not supported on iOS.
185+ (void )id ;
186+ (void )identifier;
139187}
140188
141189- (void )stopScreenTrace : (double )id {
142190 // Custom screen traces are not supported on iOS.
191+ (void )id ;
143192}
144193
145194- (void )startHttpMetric : (double )id url : (NSString *)url httpMethod : (NSString *)httpMethod {
195+ #if RNFB_PERF_SDK_AVAILABLE
146196 FIRHTTPMethod method = FIRHTTPMethodGET;
147197 NSURL *toNSURL = [NSURL URLWithString: url];
148198 if ([httpMethod compare: @" put" options: NSCaseInsensitiveSearch] == NSOrderedSame)
@@ -168,9 +218,15 @@ - (void)startHttpMetric:(double)id url:(NSString *)url httpMethod:(NSString *)ht
168218 @synchronized ([self class ]) {
169219 httpMetrics[@((int )id )] = httpMetric;
170220 }
221+ #else
222+ (void )id ;
223+ (void )url;
224+ (void )httpMethod;
225+ #endif
171226}
172227
173228- (void )stopHttpMetric : (double )id metricData : (JS ::NativeRNFBTurboPerf::HttpMetricData &)metricData {
229+ #if RNFB_PERF_SDK_AVAILABLE
174230 FIRHTTPMetric *httpMetric;
175231 @synchronized ([self class ]) {
176232 httpMetric = httpMetrics[@((int )id )];
@@ -203,6 +259,10 @@ - (void)stopHttpMetric:(double)id metricData:(JS::NativeRNFBTurboPerf::HttpMetri
203259 @synchronized ([self class ]) {
204260 [httpMetrics removeObjectForKey: @((int )id )];
205261 }
262+ #else
263+ (void )id ;
264+ (void )metricData;
265+ #endif
206266}
207267
208268@end
0 commit comments