Skip to content

feat(android): add shouldShowRequestPermissionRationale() - #90

Closed
pinpong wants to merge 2 commits into
marcocrupi:mainfrom
pinpong:feat/should-show-request-permission-rationale
Closed

pinpong wants to merge 2 commits into
marcocrupi:mainfrom
pinpong:feat/should-show-request-permission-rationale

Conversation

@pinpong

@pinpong pinpong commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

What

Adds shouldShowRequestPermissionRationale(): Promise<boolean>. On Android 13+ it wraps Activity.shouldShowRequestPermissionRationale(POST_NOTIFICATIONS). Below API 33, without a current Activity and on iOS it resolves false.

Why

After the first denial getNotificationSettings() says DENIED both when Android would show the dialog once more and when only the system settings can help. With this check an app can follow the Android guidelines: explain first and call requestPermission() while the dialog can still come, and offer openNotificationSettings() once it can't.

Changes

All in the bridge, NotifeeCore is untouched.

  • src/specs/NativeNotifeeModule.ts: new spec method
  • src/NotifeeApiModule.ts, src/types/Module.ts: public API with docs
  • android/.../NotifeeApiModule.kt: native implementation
  • ios/RNNotifee/NotifeeApiModule.mm: stub that resolves NO, like the other Android only methods
  • jest-mock.js, src/__mocks__/NotifeeNativeModule.ts: mocks
  • __tests__/NotifeeApiModule.test.ts: iOS and Android cases
  • docs/react-native/android/permissions.mdx: new "Asking again after a denial" section
  • docs/react-native/reference/Interface.ModuleWithStatics.mdx: regenerated with yarn gen:reference
  • README.md, packages/react-native/README.md: short entry under "New APIs"
  • CHANGELOG.md: entry under Unreleased

Testing

Same change as a Yarn patch on 10.9.1 in a production app (RN 0.88, new architecture):

  • Android 17 emulator (API 37, Pixel 7 profile)
    • fresh install, first request, deny: rationale true
    • second request from our own explanation UI, deny: rationale false, the dialog doesn't come back
    • allow from the explanation UI: permission granted
  • iOS: builds for iOS 26.5 simulator and an iPhone XR on iOS 18. JS resolves false without a native call.

On this branch:

  • yarn validate:all: no errors
  • yarn test:core:android (JDK 21): build successful, 806/806 tests passed
  • yarn tests_rn:test: the new tests pass. __tests__/validators/assetResolution.test.ts fails in my local install with Cannot find module 'react' from '@react-native/jest-preset/jest/mockComponent.js', the same on main, so it is not related to this change.

@marcocrupi

Copy link
Copy Markdown
Owner

Hi @pinpong,

First of all, thank you for taking the time to contribute! You identified a genuine gap in the library's notification permission API, and I really appreciate both the suggestion and the testing you performed.

After reviewing the PR, I decided to implement the feature independently rather than merge the proposed changes.

The main concern was the public API contract, not the underlying idea. Android's shouldShowRequestPermissionRationale() indicates whether displaying an explanatory UI is recommended, but it doesn't reliably tell us whether another permission dialog will appear. The proposed documentation made stronger guarantees than Android actually provides, particularly regarding repeated denials.

I also wanted to handle the missing Activity case explicitly rather than returning false, which could be mistaken for a valid platform response.

The feature has now been implemented and released in react-native-notify-kit@10.10.0, with these refinements, additional native regression tests, and successful validation on physical Android and iOS devices.

Since the functionality is now available in v10.10.0, I'll close this PR without merging it.

Thanks again for bringing this improvement to my attention. Your suggestion helped make the library better, and I really appreciate your contribution!

@marcocrupi marcocrupi closed this Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants