react-native-modal: BackHandler.removeEventListener is not a function in React Native 0.77
π Bug Report Since updating to React Native 0.77, BackHandler.removeEventListener is no longer available. The new API uses BackHandler.remove(), which causes an error in react-native-modal when attempting to remove the event listener.
β οΈ Error Message:
TypeError: _reactNative.BackHandler.removeEventListener is not a function (it is undefined)
π Affected Version: React Native: 0.77+ react-native-modal: 13.0.1
π‘ Steps to Reproduce: Install react-native-modal in a React Native 0.77 project. Open a modal that listens for the back button. Close the modal or navigate away. The app crashes with the error.
π Expected Behavior: The modal should correctly remove the BackHandler event listener without crashing.
π οΈ Suggested Fix:
Replace:
BackHandler.removeEventListener("hardwareBackPress", this.handleBackButton);
With:
BackHandler.remove("hardwareBackPress", this.handleBackButton);
A similar fix was applied in PR #761 after React Native removed removeEventListener.
π References: React Native 0.77 Breaking Changes GitHub PR with Fix Would appreciate a fix or official workaround. Thanks! π
CC: @ancyrweb @mmazzarolo
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 21
- Comments: 18 (3 by maintainers)
react-native-modal+13.0.1.patch
Just one version that was published by mistake. Iβm considering rewriting this package from scratch for v15.0.0 because the code as it is today is so difficult to maintain.
I would love to avoid a patch if possible - can https://github.com/react-native-modal/react-native-modal/pull/784 get merged?
@codeion landing in
14.0.0-rc.1πI targetted 0.76 instead of 77+ because in the following versions,
removeEventListenerhas been removed from the BackHandler interface.And it seems Expo is still targetting 0.76 anyway.
not possible, this package is no longer mantained. just patch.
Is there any reason this bug is closed with an awaiting open PR required by the react-native folks for Android 15?
Since the library works fine on the web, would you consider removing the unnecessary error log from react-native-web? The error message βBackHandler is not supported on web and should not be used.β clutters the console, but it doesnβt affect functionality.
A simple fix would be to conditionally import BackHandler only on native platforms:
This prevents the warning while maintaining expected behavior on all platforms. Thank you for considering this improvement!
Sorry the for inconvenience, I took back the package and upgraded it to the latest version. Please upgrade to
14.0.0-rc.0see if it works correctly.@maksymhcode-care Just saw this the minute you posted it, tested it now and it works like a charm! Thank you!