react-native icon indicating copy to clipboard operation
react-native copied to clipboard

this.onMainScreen() is not defined

Open MikeChongCan opened this issue 10 years ago • 8 comments

  • [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 screenshot_2016-07-16-09-44-37

  • [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

MikeChongCan avatar Jul 16 '16 01:07 MikeChongCan

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.

DanielMSchmidt avatar Jul 16 '16 05:07 DanielMSchmidt

@facebook-github-bot stack-overflow

DanielMSchmidt avatar Jul 16 '16 05:07 DanielMSchmidt

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.

ghost avatar Jul 16 '16 05:07 ghost

@DanielMSchmidt But there is no component or module which has 'onMainScreen' method. So what does it mean?

MikeChongCan avatar Jul 16 '16 06:07 MikeChongCan

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)

nihgwu avatar Jul 16 '16 07:07 nihgwu

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.

mateoKaradza avatar Jul 16 '16 10:07 mateoKaradza

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

DanielMSchmidt avatar Jul 16 '16 10:07 DanielMSchmidt

@mateoKaradza Please ask this on StackOverflow, so that others may find the answer later. Github Issues should be used for bugs only

DanielMSchmidt avatar Jul 16 '16 10:07 DanielMSchmidt