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

Warning: BackAndroid is deprecated. Please use BackHandler instead. #1597

Closed
Lizhooh opened this issue May 19, 2017 · 11 comments
Closed

Warning: BackAndroid is deprecated. Please use BackHandler instead. #1597

Lizhooh opened this issue May 19, 2017 · 11 comments

Comments

@Lizhooh
Copy link

Lizhooh commented May 19, 2017

There is a warning after the upgrade of react-navigation.
Warning: BackAndroid is deprecated. Please use BackHandler instead.

software version
react-navigation 1.00--beta.9
react-native 0.44
node 7.10
npm or yarn 4.12
@kelset
Copy link

kelset commented May 19, 2017

This is not strictly an error related to the react-navigation, you just need to change the physical android handler to:

import { BackHandler } from 'react-native';

  // code

  componentDidMount() {
    BackHandler.addEventListener('backPress');
  }

  // some more code

  componentWillUnmount() {
    BackHandler.removeEventListener('backPress');
  }

@acomito
Copy link

acomito commented May 19, 2017

@kelset would you put this in your top-level component? I'm not using BackHandler myself so it must be used somewhere in react-navigation? I just upgraded to 44 and see this now.

@chrischenyc
Copy link

same here, after I started using StackNavigator...
also not sure where shall I apply @kelset 's solution, tried put it in navigation related component, warning stays

@kelset
Copy link

kelset commented May 19, 2017

@acomito yes I've added those lines to the top-level component.

I am running the same React Native version (0.44) but I'm pointing react-navigation to master, maybe it's a fix not yet in a release?

@acomito
Copy link

acomito commented May 19, 2017

@kelset I'm also using 44 (but via expo 17) and I believe I'm pointing to master. But I am still seeing the error.

I feel like this has to do something with react-navigation and maybe navigation.goBack() or BackAndroid being used somewhere in the library?

{
  "dependencies": {
    "antd-mobile": "^1.1.3",
    "apollo-client": "^1.1.1",
    "expo": "^17.0.0",
    "graphql-tag": "^2.0.0",
    "lodash": "^4.17.4",
    "meteor-apollo-accounts": "^2.0.1",
    "moment": "^2.18.1",
    "react": "16.0.0-alpha.6",
    "react-apollo": "^1.2.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-17.0.0.tar.gz",
    "react-native-aws3": "0.0.8",
    "react-native-elements": "^0.11.2",
    "react-navigation": "git+https://github.com/react-community/react-navigation.git",
    "react-redux": "^5.0.4",
    "redux": "^3.6.0",
    "redux-devtools-extension": "^2.13.0",
    "redux-form": "^6.6.3",
    "redux-persist": "^4.6.0",
    "redux-thunk": "^2.2.0",
    "sentry-expo": "^1.0.0",
    "uuid": "^3.0.1"
  },
}
// TOP LEVEL IMPORTS
import Expo from 'expo';
import React from 'react';
import AppRoutes from './routes';
import { BackHandler } from 'react-native';
// APOLLO
import { ApolloProvider } from 'react-apollo';
import client from './ApolloClient';
// REDUX
import { store } from './store'
// ANTD
import enUS from 'antd-mobile/lib/locale-provider/en_US';
import { LocaleProvider } from 'antd-mobile';
// OTHER
import Sentry from 'sentry-expo';
import { SENTRY_DSN } from './modules/config'



// INITIALIZE SENTRY ERROR LOGGING: https://sentry.io/
// ===================================================
Sentry.config(SENTRY_DSN).install();



  // code

  
// ROOT COMPONENT TO ENTIRE RN APP
// ===================================================
class App extends React.Component {
	componentDidMount() {
	    BackHandler.addEventListener('backPress');
	  }

	  // some more code

	  componentWillUnmount() {
	    BackHandler.removeEventListener('backPress');
  	}
	render() {
		return (
			<ApolloProvider store={store} client={client}>
				<LocaleProvider locale={enUS}>
					<AppRoutes />
				</LocaleProvider>
			</ApolloProvider>
		);
	}
}


// REGISTER ROOT COMPONENT WITH EXPO HELPER
// ===================================================
Expo.registerRootComponent(App);

@kelset
Copy link

kelset commented May 20, 2017

Ok, apparently it will be fixed soon, they merged a fix: #1520

@zaro
Copy link

zaro commented May 20, 2017

1.0.0-beta.10 fixes it for me.

@Lizhooh
Copy link
Author

Lizhooh commented May 20, 2017

ok, good

@skevy
Copy link
Member

skevy commented May 20, 2017

Fixed in 9027e1a

@skevy skevy closed this as completed May 20, 2017
@macs03
Copy link

macs03 commented Oct 13, 2017

I could fix it with this aksonov/react-native-router-flux#1842 (comment)

@ospfranco
Copy link

ospfranco commented Feb 6, 2019

I'm now getting this issue after updating to react-native 0.58.3

EDIT: as it turns out the problem was a different package, react-native-modal-box, sorry :)

@react-navigation react-navigation locked as resolved and limited conversation to collaborators Feb 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants