Skip to content
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

BackHandler.removeEventListener #17341

Closed
RowgerGo opened this issue Dec 25, 2017 · 2 comments
Closed

BackHandler.removeEventListener #17341

RowgerGo opened this issue Dec 25, 2017 · 2 comments
Labels
Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@RowgerGo
Copy link

RowgerGo commented Dec 25, 2017

Is this a bug report?

when I use BackHandler.removeEventListener,it is error "subscriptions[i] is not a function"

Environment:
windows 7 64
"react": "16.0.0",
"react-native": "0.50.3",

componentWillMount() {
    if (Platform.OS === 'android') {
      BackHandler.addEventListener('hardwareBackPress', this.onBackClicked());
    } else {

    }
  }
  componentWillUnmount() {
    if (Platform.OS === 'android') {
      BackHandler.removeEventListener("hardwareBackPress", this.onBackClicked());
    } else {
      // this.propstManger.addLengeData(this.props.navigator.getCurrentRoutes().length);
    }
  }
  onBackClicked = () => {
    alert('back')
    return true;
  } 
@dogbutcat
Copy link

The right version:

  constructor(props){
    super(props);
    this.onBackClicked = this._onBackClicked.bind(this);
  }
  componentWillMount() {
    if (Platform.OS === 'android') {
      BackHandler.addEventListener('hardwareBackPress', this.onBackClicked);
    }
  }
  componentWillUnmount() {
    if (Platform.OS === 'android') {
      BackHandler.removeEventListener("hardwareBackPress", this.onBackClicked);
    } else {
      // this.propstManger.addLengeData(this.props.navigator.getCurrentRoutes().length);
    }
  }
  _onBackClicked = () => {
    alert('back')
    return true;
  } 

@react-native-bot
Copy link
Collaborator

Thanks for posting this! It looks like you may not be using the latest version of React Native, v0.53.0, released on January 2018. Can you make sure this issue can still be reproduced in the latest version?

I am going to close this, but please feel free to open a new issue if you are able to confirm that this is still a problem in v0.53.0 or newer.

How to ContributeWhat to Expect from Maintainers

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon. labels Feb 24, 2018
@facebook facebook locked and limited conversation to collaborators May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants