this.onMainScreen() is not defined
-
[x] Provide a minimal code snippet / rnplay example that reproduces the bug.
As http://facebook.github.io/react-native/docs/backandroid.html goes:
BackAndroid.addEventListener('hardwareBackPress', function() {
if (!this.onMainScreen()) {
// Do something
return true;
}
return false;
});
-
[x] Provide screenshots where appropriate

-
[x] What's the version of React Native you're using?
0.29
-
[x] Does this occur on iOS, Android or both?
Android
-
[x] Are you using Mac, Linux or Windows?
Mac
The problem is, that this is not defined, where you are executing the this.onMainScreen() command. You need to use .bind on the outer function, for more details on this topic see here. Next time, please ask this kind of questions on StackOverflow.
@facebook-github-bot stack-overflow
Hey @imWildCat and thanks for posting this! @DanielMSchmidt tells me this issue looks like a question that would be best asked on StackOverflow. StackOverflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only. Will close this as this is really a question that should be asked on SO.
@DanielMSchmidt But there is no component or module which has 'onMainScreen' method. So what does it mean?
That's not the bind stuff but onMainScreen is undefined, perhaps the sample code should be improved to tell that it's just a pseudo one, you have to define your own onMainScreen (or even goBack method in the example)
To check if you are on the mainScreen, just check length of current route: https://github.com/mateoKaradza/Crystal-Lexicon-App/blob/master/app/components/NavBar.js#L12
However, is there any way to tell this event listener to just do this once? Tried everything, searched for hours but nothing - I event tried using state but it doesn't change fast enough.
Oh, I see the problem: You took the example from the docs, correct? In the docs they simply show what is possible with the module described. As @nihgwu said, you need to implement your own code there.
I did a PR to clairify
@mateoKaradza Please ask this on StackOverflow, so that others may find the answer later. Github Issues should be used for bugs only