"react-native-pager-view": "^5.1.2"
OnePlus 8T
Android 11 (SDK 30)
com.reactnativepagerview.PagerViewViewManager.createViewInstance
kotlin.KotlinNullPointerException:
at com.reactnativepagerview.PagerViewViewManager.createViewInstance (PagerViewViewManager.kt:30)
at com.reactnativepagerview.PagerViewViewManager.createViewInstance (PagerViewViewManager.kt:21)
at com.facebook.react.uimanager.ViewManager.createViewInstance (ViewManager.java:139)
at com.facebook.react.uimanager.ViewManager.createView (ViewManager.java:82)
at com.facebook.react.uimanager.NativeViewHierarchyManager.createView (NativeViewHierarchyManager.java:269)
at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute (UIViewOperationQueue.java:179)
at com.facebook.react.uimanager.UIViewOperationQueue$1.run (UIViewOperationQueue.java:773)
at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches (UIViewOperationQueue.java:888)
at com.facebook.react.uimanager.UIViewOperationQueue.access$2200 (UIViewOperationQueue.java:42)
at com.facebook.react.uimanager.UIViewOperationQueue$2.runGuarded (UIViewOperationQueue.java:846)
at com.facebook.react.bridge.GuardedRunnable.run (GuardedRunnable.java:29)
at android.os.Handler.handleCallback (Handler.java:883)
at android.os.Handler.dispatchMessage (Handler.java:100)
at android.os.Looper.loop (Looper.java:214)
at android.app.ActivityThread.main (ActivityThread.java:7710)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950)
This is the error I'm getting from the google play console
Same here, it occured in several SDKs from 7 up to 11 and in several devices
Hello 馃憢
Could you provide a reproducible example ? I am not able to reproduce it using a local example

same here
Can anyone debug in your own code using android studio, why reactContext.currentActivity is not FragmentActivity ? and what kind of Activity is reactContext.currentActivity ?
@troZee I found one reliable way to replicate this bug.
Have the pager render behind the Android permission request popup.
For me, when I start my app, it requests for an Android permission immediately. Behind the popup, I see my app rendering and it crashes as soon as it tries to render the pager stuff. If I dismiss it (i.e. Allow or deny the permission) quick enough, it will not crash
@cojj90 thank you for an explanation. Could you provide a reproducible repository ? Or you can just clone this repo and add this case into an example.
Maybe you should request permission using useEffect ? Maybe that will fix above issue ?
Having same crashes, I do not have any permission requests on my app.
@venkatpantham-mi Did you find any prior version that prevents this crash?
also getting this - but dont know how to replicate :/
I've also seen this issue in the Google Play Console on a few devices on Android 9 and 10.

I resolve this problem. it's happened when i close the container of react native and jump to a component that contain pagerView(logical error). It's all my faults , so i suggest check the react native code whether contains that case.
Can anyone debug in your own code using android studio, why
reactContext.currentActivityis notFragmentActivity? and what kind ofActivityisreactContext.currentActivity?
currentActivity is null :s
Seems to happen when app is rendering pager-view in the background. Is there a way to do createViewInstance without using the activity?
Can anyone debug in your own code using android studio, why
reactContext.currentActivityis notFragmentActivity? and what kind ofActivityisreactContext.currentActivity?
Line affected:
https://github.com/callstack/react-native-pager-view/blob/master/android/src/main/java/com/reactnativepagerview/PagerViewViewManager.kt#L30currentActivity is null :s
Thank you for investigation @cojj90. It is impossible to create view without activity, bc adapter needs this activity as a dependency in the constructor.
Probably it is related to this issue:
https://stackoverflow.com/questions/45435450/getcurrentactivity-in-reactcontextbasejavamodule-returns-null
Hi @troZee,
So it is like you are saying using Activity is a hard wall then.
According to the doc, would other available constructors work?
For example, the one below seems promising as it has "LifeCycle" as one of parameters?
FragmentStateAdapter(@NonNull fragmentManager: FragmentManager, @NonNull lifecycle: Lifecycle)
Hi @troZee,
So it is like you are saying using Activity is a hard wall then.
According to the doc, would other available constructors work?
For example, the one below seems promising as it has "LifeCycle" as one of parameters?FragmentStateAdapter(@NonNull fragmentManager: FragmentManager, @NonNull lifecycle: Lifecycle)
Thank you for an investigation @thanakij. I think, it wont work, bc both parameters need an Activity, which is null. I don't know, why activity can be null ? @cojj90 said Seems to happen when app is rendering pager-view in the background., but I was not able to reproduce that case. The second thing is, why activity is null, when app is in the background ?
As you can see, there is lots of questions and without any reproducible code, I am not able to fix it.
As you can see, there is lots of questions and without any reproducible code, I am not able to fix it.
@troZee I'll provide a reproducible code when I get around to it!
For now, as a workaround, we added an explicit check in JS to check for Android activity before rendering pager-view
@cojj90 I am glad that this gets moving. :) By the way @troZee, if we can actually check null for Android activity from JS as prevention, then wouldn't this mean we can simply check null just right before L30 and quickly return from the method?
This can be done in one simple pull request and would prevent the crash reported by many for now.
Then we can move to think the next step which is "Will this actually be the proper way to handle the null case?"
What we know:
What I think:
onCreate, ... and onDestroy would be called accordingly.Next interesting thing to know:
createViewInstance) as well?Just received a report for this bug from a device running Android 6.0.1.
Happened directly on app launch (my main screen is a ViewPager). No permission check.
@cojj90
For now, as a workaround, we added an explicit check in JS to check for Android activity before rendering pager-view
Could you provide a code snippet of that solution ? I would like to take a look on it.
the fix has been released here:
https://github.com/callstack/react-native-pager-view/releases/tag/v5.2.1
Please let me know, if everything is fine
Hi @troZee, thank you for this 馃憤
I am going to build an app update and publish it to Play Store. After majority of the users have updated the version, I will let you know if we actually see less number of crashes reported by Crashlytics.
Good news! It has been about one week after I pushed an app update.
So far we longer see the crash!
We still have the crash on production.
Packages versions:
"react-native": "0.64.0"
"react-native-pager-view": "5.2.1"
"react-native-tab-view": "3.0.1"
Hermes: true

We still have the crash on production.
Packages versions:
"react-native": "0.64.0" "react-native-pager-view": "5.2.1" "react-native-tab-view": "3.0.1"Hermes: true
@YanisKondakov i think do you have two different version react-native-pager-view please try use resolution in your package.json for react-native-tab-view and @react-navigation/material-top-tabs maybe something else
Hi @troZee @zabutok,
Although it is no longer crashing, now it sometimes renders nothing.
I have created a new issue #389.
Most helpful comment
We still have the crash on production.
Packages versions:
Hermes: true