Skip to content

Commit cd9da63

Browse files
littlehome-eugeneEugene Kim
and
Eugene Kim
authored
allow native and RN to share singleton instance (#120)
Co-authored-by: Eugene Kim <[email protected]>
1 parent 5b90ce2 commit cd9da63

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/core/android/src/main/java/com/segment/analytics/reactnative/core/RNAnalyticsModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ class RNAnalyticsModule(context: ReactApplicationContext): ReactContextBaseJavaM
171171
Analytics.setSingletonInstance(
172172
RNAnalytics.buildWithIntegrations(builder)
173173
)
174+
} catch(e2: IllegalStateException) {
175+
// pass if the error is due to calling setSingletonInstance multiple times
176+
177+
// if you created singleton in native code already,
178+
// you need to promise.resolve for RN to properly operate
174179
} catch(e: Exception) {
175180
return promise.reject("E_SEGMENT_ERROR", e)
176181
}

0 commit comments

Comments
 (0)