com.app.MainActivity cannot be cast to com.facebook.react.ReactActivity

Viewed 623

Getting this Android error when using a React Native third party library, did some debug and narrow down to the following Kotlin code

class GModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {

    val activity = reactContext.currentActivity as ReactActivity

tried to debug it myself but have no idea where to start as I am not familiar with Kotlin, any help or guidance is much appreciated :) thankssssss

1 Answers

figure it out myself, so my React Native app is using React Native Navigation, and MainActivity class is extends to NavigationActivity instead of ReactActivity. The solution for this is to cast reactContext.currentActivity as AppCompatActivity since NavigationActivity extends AppCompatActivity.

Related