Skip to content

Commit fe8cf89

Browse files
committed
fix: update react context check
1 parent 1fc0bdb commit fe8cf89

File tree

2 files changed

+9
-41
lines changed

2 files changed

+9
-41
lines changed

example/android/.project

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/core/android/src/main/java/com/segmentanalyticsreactnative/AnalyticsReactNativeModule.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,24 +223,20 @@ class AnalyticsReactNativeModule : ReactContextBaseJavaModule, ActivityEventList
223223
?.currentReactContext
224224
?.getNativeModule(SovranModule::class.java)
225225
sovran?.dispatch("add-deepLink-data", properties)
226+
227+
226228
}
227229

228-
fun setAnonymousId(anonymousId: String) {
229-
val properties = Hashtable<String, String>()
230-
properties["anonymousId"] = anonymousId
230+
fun setAnonymousId(anonymousId: String) {
231+
val properties = Hashtable<String, String>()
232+
properties["anonymousId"] = anonymousId
231233

232-
if (currentActivity == null) {
233-
Log.d(name, "No activity found")
234-
return
235-
}
236-
237-
val sovran = (currentActivity?.application as ReactApplication)
238-
?.reactNativeHost
239-
?.reactInstanceManager
240-
?.currentReactContext
241-
?.getNativeModule(SovranModule::class.java)
234+
val currentContext = getReactApplicationContext()
242235

236+
if (currentContext != null) {
237+
val sovran = currentContext.getNativeModule(SovranModule::class.java)
243238
sovran?.dispatch("add-anonymous-id", properties)
239+
}
244240
}
245241

246242
override fun onActivityResult(activity: Activity?, requestCode: Int, resultCode: Int, data: Intent?) {

0 commit comments

Comments
 (0)