Skip to content

Commit dfc90a7

Browse files
FENCE-2697: Fix TurboModule event emitter crash on iOS startup (#433)
* add _jsEventEmitterReady check * cleanup whitespace * match naming convention * prep for release
1 parent 4aadf21 commit dfc90a7

7 files changed

Lines changed: 53 additions & 25 deletions

File tree

android/src/newarch/java/com/radar/RadarModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class RadarModule(reactContext: ReactApplicationContext) :
143143
override fun initialize(publishableKey: String, fraud: Boolean): Unit {
144144
val editor = reactApplicationContext.getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit()
145145
editor.putString("x_platform_sdk_type", "ReactNative")
146-
editor.putString("x_platform_sdk_version", "3.30.0")
146+
editor.putString("x_platform_sdk_version", "3.31.0")
147147
editor.apply()
148148

149149
Radar.initialize(reactApplicationContext, publishableKey, radarReceiver, Radar.RadarLocationServicesProvider.GOOGLE, fraud, null, radarInAppMessageReceiver, currentActivity)

android/src/oldarch/java/com/radar/RadarModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void initialize(String publishableKey, boolean fraud) {
102102
this.fraud = fraud;
103103
SharedPreferences.Editor editor = getReactApplicationContext().getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit();
104104
editor.putString("x_platform_sdk_type", "ReactNative");
105-
editor.putString("x_platform_sdk_version", "3.30.0");
105+
editor.putString("x_platform_sdk_version", "3.31.0");
106106
editor.apply();
107107
Radar.initialize(getReactApplicationContext(), publishableKey, receiver, Radar.RadarLocationServicesProvider.GOOGLE, fraud, null, inAppMessageReceiver, getCurrentActivity());
108108
if (fraud) {

example/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/RNRadar.mm

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ @implementation RNRadar {
99
CLLocationManager *locationManager;
1010
RCTPromiseResolveBlock permissionsRequestResolver;
1111
bool hasListeners;
12+
#ifdef RCT_NEW_ARCH_ENABLED
13+
bool jsEventEmitterReady;
14+
#endif
1215
}
1316

1417
RCT_EXPORT_MODULE()
@@ -52,12 +55,21 @@ - (void)stopObserving {
5255
hasListeners = NO;
5356
}
5457

58+
#ifdef RCT_NEW_ARCH_ENABLED
59+
- (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper {
60+
[super setEventEmitterCallback:eventEmitterCallbackWrapper];
61+
jsEventEmitterReady = YES;
62+
}
63+
#endif
64+
5565
- (void)onNewInAppMessage:(RadarInAppMessage *)inAppMessage {
5666

5767
NSMutableDictionary *body = [NSMutableDictionary new];
5868
[body setValue:[Radar dictionaryForInAppMessage:inAppMessage] forKey:@"inAppMessage"];
5969
#ifdef RCT_NEW_ARCH_ENABLED
60-
[self emitNewInAppMessageEmitter:body];
70+
if (jsEventEmitterReady) {
71+
[self emitNewInAppMessageEmitter:body];
72+
}
6173
#else
6274
if (hasListeners) {
6375
[self sendEventWithName:@"newInAppMessageEmitter" body:body];
@@ -69,7 +81,9 @@ - (void)onInAppMessageDismissed:(RadarInAppMessage *)inAppMessage {
6981
NSMutableDictionary *body = [NSMutableDictionary new];
7082
[body setValue:[Radar dictionaryForInAppMessage:inAppMessage] forKey:@"inAppMessage"];
7183
#ifdef RCT_NEW_ARCH_ENABLED
72-
[self emitInAppMessageDismissedEmitter:body];
84+
if (jsEventEmitterReady) {
85+
[self emitInAppMessageDismissedEmitter:body];
86+
}
7387
#else
7488
if (hasListeners) {
7589
[self sendEventWithName:@"inAppMessageDismissedEmitter" body:body];
@@ -81,7 +95,9 @@ - (void)onInAppMessageButtonClicked:(RadarInAppMessage *)inAppMessage {
8195
NSMutableDictionary *body = [NSMutableDictionary new];
8296
[body setValue:[Radar dictionaryForInAppMessage:inAppMessage] forKey:@"inAppMessage"];
8397
#ifdef RCT_NEW_ARCH_ENABLED
84-
[self emitInAppMessageClickedEmitter:body];
98+
if (jsEventEmitterReady) {
99+
[self emitInAppMessageClickedEmitter:body];
100+
}
85101
#else
86102
if (hasListeners) {
87103
[self sendEventWithName:@"inAppMessageClickedEmitter" body:body];
@@ -105,7 +121,9 @@ - (void)didReceiveEvents:(NSArray<RadarEvent *> *)events user:(RadarUser * _Null
105121
[body setValue:[user dictionaryValue] forKey:@"user"];
106122
}
107123
#ifdef RCT_NEW_ARCH_ENABLED
108-
[self emitEventsEmitter:body];
124+
if (jsEventEmitterReady) {
125+
[self emitEventsEmitter:body];
126+
}
109127
#else
110128
if (hasListeners) {
111129
[self sendEventWithName:@"eventsEmitter" body:body];
@@ -115,10 +133,12 @@ - (void)didReceiveEvents:(NSArray<RadarEvent *> *)events user:(RadarUser * _Null
115133

116134
- (void)didUpdateLocation:(CLLocation *)location user:(RadarUser *)user {
117135
#ifdef RCT_NEW_ARCH_ENABLED
118-
[self emitLocationEmitter:@{
119-
@"location": [Radar dictionaryForLocation:location],
120-
@"user": [user dictionaryValue]
121-
}];
136+
if (jsEventEmitterReady) {
137+
[self emitLocationEmitter:@{
138+
@"location": [Radar dictionaryForLocation:location],
139+
@"user": [user dictionaryValue]
140+
}];
141+
}
122142
#else
123143
if (hasListeners) {
124144
[self sendEventWithName:@"locationEmitter" body:@{
@@ -131,11 +151,13 @@ - (void)didUpdateLocation:(CLLocation *)location user:(RadarUser *)user {
131151

132152
- (void)didUpdateClientLocation:(CLLocation *)location stopped:(BOOL)stopped source:(RadarLocationSource)source {
133153
#ifdef RCT_NEW_ARCH_ENABLED
134-
[self emitClientLocationEmitter:@{
135-
@"location": [Radar dictionaryForLocation:location],
136-
@"stopped": @(stopped),
137-
@"source": [Radar stringForLocationSource:source]
138-
}];
154+
if (jsEventEmitterReady) {
155+
[self emitClientLocationEmitter:@{
156+
@"location": [Radar dictionaryForLocation:location],
157+
@"stopped": @(stopped),
158+
@"source": [Radar stringForLocationSource:source]
159+
}];
160+
}
139161
#else
140162
if (hasListeners) {
141163
[self sendEventWithName:@"clientLocationEmitter" body:@{
@@ -152,7 +174,9 @@ - (void)didFailWithStatus:(RadarStatus)status {
152174
@"status": [Radar stringForStatus:status]
153175
};
154176
#ifdef RCT_NEW_ARCH_ENABLED
155-
[self emitErrorEmitter:body];
177+
if (jsEventEmitterReady) {
178+
[self emitErrorEmitter:body];
179+
}
156180
#else
157181
if (hasListeners) {
158182
[self sendEventWithName:@"errorEmitter" body:body];
@@ -165,7 +189,9 @@ - (void)didLogMessage:(NSString *)message {
165189
@"message": message
166190
};
167191
#ifdef RCT_NEW_ARCH_ENABLED
168-
[self emitLogEmitter:body];
192+
if (jsEventEmitterReady) {
193+
[self emitLogEmitter:body];
194+
}
169195
#else
170196
if (hasListeners) {
171197
[self sendEventWithName:@"logEmitter" body:body];
@@ -178,7 +204,9 @@ - (void)didUpdateToken:(RadarVerifiedLocationToken *)token {
178204
@"token": [token dictionaryValue]
179205
};
180206
#ifdef RCT_NEW_ARCH_ENABLED
181-
[self emitTokenEmitter:body];
207+
if (jsEventEmitterReady) {
208+
[self emitTokenEmitter:body];
209+
}
182210
#else
183211
if (hasListeners) {
184212
[self sendEventWithName:@"tokenEmitter" body:body];
@@ -189,7 +217,7 @@ - (void)didUpdateToken:(RadarVerifiedLocationToken *)token {
189217
RCT_EXPORT_METHOD(initialize:(NSString *)publishableKey fraud:(BOOL)fraud) {
190218
_publishableKey = publishableKey;
191219
[[NSUserDefaults standardUserDefaults] setObject:@"ReactNative" forKey:@"radar-xPlatformSDKType"];
192-
[[NSUserDefaults standardUserDefaults] setObject:@"3.30.0" forKey:@"radar-xPlatformSDKVersion"];
220+
[[NSUserDefaults standardUserDefaults] setObject:@"3.31.0" forKey:@"radar-xPlatformSDKVersion"];
193221
[Radar initializeWithPublishableKey:publishableKey];
194222
}
195223

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "React Native module for Radar, the leading geofencing and location tracking platform",
44
"homepage": "https://radar.com",
55
"license": "Apache-2.0",
6-
"version": "3.30.0",
6+
"version": "3.31.0",
77
"main": "dist/index.js",
88
"files": [
99
"dist",

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file contains the version of the react-native-radar package
22
// It should be updated to match the version in package.json
3-
export const VERSION = '3.30.0';
3+
export const VERSION = '3.31.0';

0 commit comments

Comments
 (0)