mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Fix request permission is not always resolving in Android 16 (#53898)
Summary: Fixes: https://github.com/facebook/react-native/issues/53887 Fixes: https://github.com/expo/expo/issues/39480 In the latest Android 16 update, requesting permissions does not always change the app's state (the `onPause` and `onResume` functions aren't called). For instance, when you deny permission 3 times, the last promise won't resolve until you move the app to the background. The current logic inside the `ReactActivityDelegate` assumes that Android will call `onResume` after receiving permission state information from the system, which is no longer the case. Probably connected with [this commit](https://android.googlesource.com/platform/packages/modules/Permission/%2B/5dca0ccb26f2b99d706a1d3e9402f851e849c913) ## Changelog: [ANDROID] [FIXED] - Fix request permission not always resolving in Android 16 Pull Request resolved: https://github.com/facebook/react-native/pull/53898 Test Plan: - I've tested it in the RNTester by denying the camera permission three times. - I've also checked if the patch works with the Expo permissions code. Reviewed By: javache Differential Revision: D83059478 Pulled By: cortinico fbshipit-source-id: 7bf33b379a1b6606ad2da2f75d337bf951e3986b
This commit is contained in:
1 parent
4106d54a6d
commit
447a7a3527
1 file changed
+25
-1
+25
-1
@@ -21,6 +21,7 @@ import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.common.LifecycleState;
|
||||
import com.facebook.react.interfaces.fabric.ReactSurface;
|
||||
import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlags;
|
||||
import com.facebook.react.modules.core.PermissionListener;
|
||||
@@ -247,7 +248,7 @@ public class ReactActivityDelegate {
|
||||
|
||||
public void onRequestPermissionsResult(
|
||||
final int requestCode, final String[] permissions, final int[] grantResults) {
|
||||
mPermissionsCallback =
|
||||
Callback permissionsCallback =
|
||||
args -> {
|
||||
if (mPermissionListener != null
|
||||
&& mPermissionListener.onRequestPermissionsResult(
|
||||
@@ -255,6 +256,29 @@ public class ReactActivityDelegate {
|
||||
mPermissionListener = null;
|
||||
}
|
||||
};
|
||||
|
||||
LifecycleState lifecycle;
|
||||
if (isFabricEnabled()) {
|
||||
ReactHost reactHost = getReactHost();
|
||||
lifecycle = reactHost != null ? reactHost.getLifecycleState() : LifecycleState.BEFORE_CREATE;
|
||||
} else {
|
||||
ReactNativeHost reactNativeHost = getReactNativeHost();
|
||||
if (!reactNativeHost.hasInstance()) {
|
||||
lifecycle = LifecycleState.BEFORE_CREATE;
|
||||
} else {
|
||||
lifecycle = reactNativeHost.getReactInstanceManager().getLifecycleState();
|
||||
}
|
||||
}
|
||||
|
||||
// If the permission request didn't show a dialog to the user, we can call the callback
|
||||
// immediately.
|
||||
// Otherwise, we need to wait until onResume to call it.
|
||||
if (lifecycle == LifecycleState.RESUMED) {
|
||||
permissionsCallback.invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
mPermissionsCallback = permissionsCallback;
|
||||
}
|
||||
|
||||
protected Context getContext() {
|
||||
|
||||
Reference in new issue
Block a user