Handling device back button in react native












1















I am handling the Android back button in React-Native using BackHandler in home page its working fine, when i navigate to home page from login page. But when i go to page 2 from home page and came back to home page by clicking the device back button, now when i click device back button in home page its taking me to login page, this should not happen.
Navigation used in home page is a drawer navigation.
I am removing the backpress event handler when i am navigating to page2, because it is disabling the back button in page 2 also.










share|improve this question

























  • You should have two stacks, one for login, the other for you app, and reset the stack to the app stack upon login. That way you don't have to worry about swiping back either, and you can program your back button to actually work, and not disable functionality.

    – AnonymousSB
    Nov 20 '18 at 9:49











  • can u provide a sample example for above

    – Sreedhar L
    Nov 26 '18 at 11:22











  • Here's a stripped down version of what I use. I'm using redux and redux-saga. This particular snippet is from an app using react-navigation ^1.0.0-beta.15

    – AnonymousSB
    Nov 26 '18 at 11:44













  • how to load images from a resources folders like drawable/mipmap in react native app

    – Sreedhar L
    Nov 29 '18 at 6:59











  • You really should post that as a separate question. To the best of my knowledge you don't. Even if you could, that would be a very bad programming practice. Theoretically you could create a Native Module to do this, or maybe someone has already made one.

    – AnonymousSB
    Nov 29 '18 at 7:13


















1















I am handling the Android back button in React-Native using BackHandler in home page its working fine, when i navigate to home page from login page. But when i go to page 2 from home page and came back to home page by clicking the device back button, now when i click device back button in home page its taking me to login page, this should not happen.
Navigation used in home page is a drawer navigation.
I am removing the backpress event handler when i am navigating to page2, because it is disabling the back button in page 2 also.










share|improve this question

























  • You should have two stacks, one for login, the other for you app, and reset the stack to the app stack upon login. That way you don't have to worry about swiping back either, and you can program your back button to actually work, and not disable functionality.

    – AnonymousSB
    Nov 20 '18 at 9:49











  • can u provide a sample example for above

    – Sreedhar L
    Nov 26 '18 at 11:22











  • Here's a stripped down version of what I use. I'm using redux and redux-saga. This particular snippet is from an app using react-navigation ^1.0.0-beta.15

    – AnonymousSB
    Nov 26 '18 at 11:44













  • how to load images from a resources folders like drawable/mipmap in react native app

    – Sreedhar L
    Nov 29 '18 at 6:59











  • You really should post that as a separate question. To the best of my knowledge you don't. Even if you could, that would be a very bad programming practice. Theoretically you could create a Native Module to do this, or maybe someone has already made one.

    – AnonymousSB
    Nov 29 '18 at 7:13
















1












1








1








I am handling the Android back button in React-Native using BackHandler in home page its working fine, when i navigate to home page from login page. But when i go to page 2 from home page and came back to home page by clicking the device back button, now when i click device back button in home page its taking me to login page, this should not happen.
Navigation used in home page is a drawer navigation.
I am removing the backpress event handler when i am navigating to page2, because it is disabling the back button in page 2 also.










share|improve this question
















I am handling the Android back button in React-Native using BackHandler in home page its working fine, when i navigate to home page from login page. But when i go to page 2 from home page and came back to home page by clicking the device back button, now when i click device back button in home page its taking me to login page, this should not happen.
Navigation used in home page is a drawer navigation.
I am removing the backpress event handler when i am navigating to page2, because it is disabling the back button in page 2 also.







react-native






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 8:49









Nirmalsinh

3,24331437




3,24331437










asked Nov 20 '18 at 8:46









Sreedhar LSreedhar L

62




62













  • You should have two stacks, one for login, the other for you app, and reset the stack to the app stack upon login. That way you don't have to worry about swiping back either, and you can program your back button to actually work, and not disable functionality.

    – AnonymousSB
    Nov 20 '18 at 9:49











  • can u provide a sample example for above

    – Sreedhar L
    Nov 26 '18 at 11:22











  • Here's a stripped down version of what I use. I'm using redux and redux-saga. This particular snippet is from an app using react-navigation ^1.0.0-beta.15

    – AnonymousSB
    Nov 26 '18 at 11:44













  • how to load images from a resources folders like drawable/mipmap in react native app

    – Sreedhar L
    Nov 29 '18 at 6:59











  • You really should post that as a separate question. To the best of my knowledge you don't. Even if you could, that would be a very bad programming practice. Theoretically you could create a Native Module to do this, or maybe someone has already made one.

    – AnonymousSB
    Nov 29 '18 at 7:13





















  • You should have two stacks, one for login, the other for you app, and reset the stack to the app stack upon login. That way you don't have to worry about swiping back either, and you can program your back button to actually work, and not disable functionality.

    – AnonymousSB
    Nov 20 '18 at 9:49











  • can u provide a sample example for above

    – Sreedhar L
    Nov 26 '18 at 11:22











  • Here's a stripped down version of what I use. I'm using redux and redux-saga. This particular snippet is from an app using react-navigation ^1.0.0-beta.15

    – AnonymousSB
    Nov 26 '18 at 11:44













  • how to load images from a resources folders like drawable/mipmap in react native app

    – Sreedhar L
    Nov 29 '18 at 6:59











  • You really should post that as a separate question. To the best of my knowledge you don't. Even if you could, that would be a very bad programming practice. Theoretically you could create a Native Module to do this, or maybe someone has already made one.

    – AnonymousSB
    Nov 29 '18 at 7:13



















You should have two stacks, one for login, the other for you app, and reset the stack to the app stack upon login. That way you don't have to worry about swiping back either, and you can program your back button to actually work, and not disable functionality.

– AnonymousSB
Nov 20 '18 at 9:49





You should have two stacks, one for login, the other for you app, and reset the stack to the app stack upon login. That way you don't have to worry about swiping back either, and you can program your back button to actually work, and not disable functionality.

– AnonymousSB
Nov 20 '18 at 9:49













can u provide a sample example for above

– Sreedhar L
Nov 26 '18 at 11:22





can u provide a sample example for above

– Sreedhar L
Nov 26 '18 at 11:22













Here's a stripped down version of what I use. I'm using redux and redux-saga. This particular snippet is from an app using react-navigation ^1.0.0-beta.15

– AnonymousSB
Nov 26 '18 at 11:44







Here's a stripped down version of what I use. I'm using redux and redux-saga. This particular snippet is from an app using react-navigation ^1.0.0-beta.15

– AnonymousSB
Nov 26 '18 at 11:44















how to load images from a resources folders like drawable/mipmap in react native app

– Sreedhar L
Nov 29 '18 at 6:59





how to load images from a resources folders like drawable/mipmap in react native app

– Sreedhar L
Nov 29 '18 at 6:59













You really should post that as a separate question. To the best of my knowledge you don't. Even if you could, that would be a very bad programming practice. Theoretically you could create a Native Module to do this, or maybe someone has already made one.

– AnonymousSB
Nov 29 '18 at 7:13







You really should post that as a separate question. To the best of my knowledge you don't. Even if you could, that would be a very bad programming practice. Theoretically you could create a Native Module to do this, or maybe someone has already made one.

– AnonymousSB
Nov 29 '18 at 7:13














1 Answer
1






active

oldest

votes


















2














You just have to implement the Backhandler in your home page, and don't perform any action on it.



  BackHandler.addEventListener('hardwareBackPress', () => {
return false
});


Just return false. So It won't navigation to Login screen again.






share|improve this answer
























  • how to load images from a resources folders like drawable/mipmap in react native app

    – Sreedhar L
    Nov 29 '18 at 6:58











  • You need to give path of your image. You need to add image on one of your folder, not in particular iOS and Android folder.

    – Nirmalsinh
    Nov 29 '18 at 7:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389183%2fhandling-device-back-button-in-react-native%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You just have to implement the Backhandler in your home page, and don't perform any action on it.



  BackHandler.addEventListener('hardwareBackPress', () => {
return false
});


Just return false. So It won't navigation to Login screen again.






share|improve this answer
























  • how to load images from a resources folders like drawable/mipmap in react native app

    – Sreedhar L
    Nov 29 '18 at 6:58











  • You need to give path of your image. You need to add image on one of your folder, not in particular iOS and Android folder.

    – Nirmalsinh
    Nov 29 '18 at 7:00
















2














You just have to implement the Backhandler in your home page, and don't perform any action on it.



  BackHandler.addEventListener('hardwareBackPress', () => {
return false
});


Just return false. So It won't navigation to Login screen again.






share|improve this answer
























  • how to load images from a resources folders like drawable/mipmap in react native app

    – Sreedhar L
    Nov 29 '18 at 6:58











  • You need to give path of your image. You need to add image on one of your folder, not in particular iOS and Android folder.

    – Nirmalsinh
    Nov 29 '18 at 7:00














2












2








2







You just have to implement the Backhandler in your home page, and don't perform any action on it.



  BackHandler.addEventListener('hardwareBackPress', () => {
return false
});


Just return false. So It won't navigation to Login screen again.






share|improve this answer













You just have to implement the Backhandler in your home page, and don't perform any action on it.



  BackHandler.addEventListener('hardwareBackPress', () => {
return false
});


Just return false. So It won't navigation to Login screen again.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 8:51









NirmalsinhNirmalsinh

3,24331437




3,24331437













  • how to load images from a resources folders like drawable/mipmap in react native app

    – Sreedhar L
    Nov 29 '18 at 6:58











  • You need to give path of your image. You need to add image on one of your folder, not in particular iOS and Android folder.

    – Nirmalsinh
    Nov 29 '18 at 7:00



















  • how to load images from a resources folders like drawable/mipmap in react native app

    – Sreedhar L
    Nov 29 '18 at 6:58











  • You need to give path of your image. You need to add image on one of your folder, not in particular iOS and Android folder.

    – Nirmalsinh
    Nov 29 '18 at 7:00

















how to load images from a resources folders like drawable/mipmap in react native app

– Sreedhar L
Nov 29 '18 at 6:58





how to load images from a resources folders like drawable/mipmap in react native app

– Sreedhar L
Nov 29 '18 at 6:58













You need to give path of your image. You need to add image on one of your folder, not in particular iOS and Android folder.

– Nirmalsinh
Nov 29 '18 at 7:00





You need to give path of your image. You need to add image on one of your folder, not in particular iOS and Android folder.

– Nirmalsinh
Nov 29 '18 at 7:00




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389183%2fhandling-device-back-button-in-react-native%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Hercules Kyvelos

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud