-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement usePreventRemove hook #10682
feat: implement usePreventRemove hook #10682
Conversation
✅ Deploy Preview for react-navigation-example ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
The Expo app for the example from this branch is ready! expo.dev/@react-navigation/react-navigation-example?release-channel=pr-10682 |
Codecov Report
@@ Coverage Diff @@
## main #10682 +/- ##
==========================================
+ Coverage 74.60% 74.85% +0.24%
==========================================
Files 161 167 +6
Lines 5025 5122 +97
Branches 1962 1981 +19
==========================================
+ Hits 3749 3834 +85
- Misses 1239 1250 +11
- Partials 37 38 +1
Continue to review full report at Codecov.
|
Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
Thank you very much for this feature! @kacperkapusciak :) Do you have an approximate release date in the next version @satya164 ? Thanks you :) |
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
how to use this function in class component???? |
I create new component like this
then i called like this
|
does it work for both android and ios? |
This issue is iOS only, because for Android you can use BackHandler in react native with more flexible functionality. |
As we still polishing the API we're marking the hook for now as
UNSTABLE_usePreventRemove
.Motivation
This PR intruduces a new hook -
usePreventRemove
- used for preventing going back inreact-navigation
. This hook would allow to support preventing of screen removal in@react-navigation/native-stack
which is one of the limitations of current API.The
usePreventRemove
hook would take two arguments:preventRemove
- boolean indicating whether to prevent screen from being removedcallback
- optional function which is executed when screen was prevented from being removedExample use case
Example code to test the change