Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): Fix non UIKit builds #3784

Merged
merged 5 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Fix Apple non UIKit builds ([#3784](https://github.com/getsentry/sentry-react-native/pull/3784))

## 5.22.1

### Dependencies
Expand Down
15 changes: 13 additions & 2 deletions ios/RNSentry.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@

#import "RNSentryEvents.h"
#import "RNSentryDependencyContainer.h"
#import "RNSentryFramesTrackerListener.h"

#if SENTRY_HAS_UIKIT
#import "RNSentryRNSScreen.h"
#import "RNSentryFramesTrackerListener.h"
#endif

@interface SentryTraceContext : NSObject
- (nullable instancetype)initWithDict:(NSDictionary<NSString *, id> *)dictionary;
Expand Down Expand Up @@ -192,6 +195,7 @@ - (void)setEventEnvironmentTag:(SentryEvent *)event
RCT_EXPORT_METHOD(initNativeReactNavigationNewFrameTracking:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
#if SENTRY_HAS_UIKIT
if ([[NSThread currentThread] isMainThread]) {
[RNSentryRNSScreen swizzleViewDidAppear];
} else {
Expand All @@ -201,16 +205,20 @@ - (void)setEventEnvironmentTag:(SentryEvent *)event
}

[self initFramesTracking];
#endif
resolve(nil);
}

- (void)initFramesTracking {
#if SENTRY_HAS_UIKIT

RNSentryEmitNewFrameEvent emitNewFrameEvent = ^(NSNumber *newFrameTimestampInSeconds) {
if (self->hasListeners) {
[self sendEventWithName:RNSentryNewFrameEvent body:@{ @"newFrameTimestampInSeconds": newFrameTimestampInSeconds }];
}
};
[[RNSentryDependencyContainer sharedInstance] initializeFramesTrackerListenerWith: emitNewFrameEvent];
#endif
}

// Will be called when this module's first listener is added.
Expand Down Expand Up @@ -370,7 +378,7 @@ - (NSDictionary*) fetchNativeStackFramesBy: (NSArray<NSNumber*>*)instructionsAdd
RCT_EXPORT_METHOD(fetchNativeAppStart:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{

#if SENTRY_HAS_UIKIT
SentryAppStartMeasurement *appStartMeasurement = PrivateSentrySDKOnly.appStartMeasurement;

if (appStartMeasurement == nil) {
Expand All @@ -389,6 +397,9 @@ - (NSDictionary*) fetchNativeStackFramesBy: (NSArray<NSNumber*>*)instructionsAdd
// This is always set to true, as we would only allow an app start fetch to only happen once
// in the case of a JS bundle reload, we do not want it to be instrumented again.
didFetchAppStart = true;
#else
resolve(nil);
#endif
}

RCT_EXPORT_METHOD(fetchNativeFrames:(RCTPromiseResolveBlock)resolve
Expand Down
5 changes: 4 additions & 1 deletion ios/RNSentryDependencyContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ SENTRY_NO_INIT

@property (class, readonly, strong) RNSentryDependencyContainer* sharedInstance;

#if SENTRY_HAS_UIKIT

@property (nonatomic, strong) RNSentryFramesTrackerListener *framesTrackerListener;

- (void)initializeFramesTrackerListenerWith:(RNSentryEmitNewFrameEvent) eventEmitter;

@end
#endif

@end
4 changes: 4 additions & 0 deletions ios/RNSentryDependencyContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ - (instancetype)init
return self;
}

#if SENTRY_HAS_UIKIT

- (void)initializeFramesTrackerListenerWith:(RNSentryEmitNewFrameEvent)eventEmitter
{
@synchronized(sentryDependencyContainerLock) {
Expand All @@ -29,4 +31,6 @@ - (void)initializeFramesTrackerListenerWith:(RNSentryEmitNewFrameEvent)eventEmit
}
}

#endif

@end
6 changes: 6 additions & 0 deletions ios/RNSentryFramesTrackerListener.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#import <Sentry/SentryDefines.h>

#if SENTRY_HAS_UIKIT

#import <Foundation/Foundation.h>
#import <React/RCTEventEmitter.h>
#import <Sentry/SentryFramesTracker.h>
Expand All @@ -15,3 +19,5 @@ typedef void (^RNSentryEmitNewFrameEvent)(NSNumber *newFrameTimestampInSeconds);
@property (strong, nonatomic) RNSentryEmitNewFrameEvent emitNewFrameEvent;

@end

#endif
4 changes: 4 additions & 0 deletions ios/RNSentryFramesTrackerListener.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import "RNSentryFramesTrackerListener.h"

#if SENTRY_HAS_UIKIT

@implementation RNSentryFramesTrackerListener

- (instancetype)initWithSentryFramesTracker:(SentryFramesTracker *)framesTracker
Expand Down Expand Up @@ -28,3 +30,5 @@ - (void)startListening {
}

@end

#endif
4 changes: 4 additions & 0 deletions ios/RNSentryOnDrawReporter.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if SENTRY_HAS_UIKIT

#import <UIKit/UIKit.h>
#import <React/RCTViewManager.h>
#import "RNSentryFramesTrackerListener.h"
Expand Down Expand Up @@ -68,3 +70,5 @@ - (void)didSetProps:(NSArray<NSString *> *)changedProps
}

@end

#endif
6 changes: 6 additions & 0 deletions ios/RNSentryRNSScreen.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#import <Sentry/SentryDefines.h>

#if SENTRY_HAS_UIKIT

#import <Foundation/Foundation.h>

@interface RNSentryRNSScreen : NSObject

+ (void)swizzleViewDidAppear;

@end

#endif
7 changes: 6 additions & 1 deletion ios/RNSentryRNSScreen.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#import "RNSentryRNSScreen.h"

#if SENTRY_HAS_UIKIT

#import <Sentry/SentryFramesTracker.h>
#import <Sentry/SentryDependencyContainer.h>
#import <Sentry/SentrySwizzle.h>

#import "RNSentryRNSScreen.h"
#import "RNSentryDependencyContainer.h"

@implementation RNSentryRNSScreen
Expand All @@ -24,3 +27,5 @@ + (void)swizzleViewDidAppear {
}

@end

#endif