web-dev-qa-db-fra.com

Réaction native crash sur iOS avec tiroir Réact-navigation

Je reçois une erreur sur iOS uniquement:

TypeError: undefined is not an object (evaluating 'this._callListeners.bind')

This error is located at:
  in DrawerLayout (at DrawerView.js:161)
  ...

Dépendances du projet:

"dependencies": {
    "@babel/runtime": "7.2.0",
    "@babel/plugin-proposal-async-generator-functions": "7.2.0",
    "@babel/plugin-proposal-class-properties": "7.2.1",
    "@babel/plugin-proposal-object-rest-spread": "7.2.0",
    "babel-preset-expo": "5.0.0",
    "expo": "31.0.2",
    "expo-cli": "2.5.0",
    "native-base": "2.8.1",
    "react": "16.6.3",
    "react-native": "0.57.8",
    "react-redux": "6.0.0",
    "react-navigation": "3.0.8",
    "react-native-vector-icons": "6.1.0",
    "redux": "4.0.1"
  }

Cela a commencé lorsque j'ai commencé à utiliser react-navigation; mais fonctionne bien sur Android.

Voici le code où nous utilisons react-navigation, voici l'application principale dont les importations comprennent les écrans d'accueil et de paramètres:

//imports...

const routes = {
  Home: Home,
  Settings: Settings
};

const AppNavigator = createDrawerNavigator(routes);

const AppContainer = createAppContainer(AppNavigator);

export default class App extends React.Component {
  state = {}

  render() {
    if (this.state.isReady) {
      return (
        <AppContainer/>
      );
      }
      else {
        return (<Container><Spinner/></Container>);
      }
  }

  componentWillMount() {
    this._loadAssets();
  }

  async _loadAssets() {
    await Expo.Font.loadAsync({
      Roboto: require("native-base/Fonts/Roboto.ttf"),
      Roboto_medium: require("native-base/Fonts/Roboto_medium.ttf")
    });

    this.setState({ isReady: true });
  }
}
5
Patrick Dench

J'ai finalement réussi à faire en sorte que cela fonctionne après de nombreuses itérations parmi les solutions possibles.

Il semble que j'ai eu quelques problèmes - avec des conflits de version de paquet et la configuration de .babelrc.

Avec ceux-ci j'ai pu me lever et courir ..

package.json deps:

"dependencies": {
    "@babel/plugin-proposal-async-generator-functions": "7.2.0",
    "@babel/plugin-proposal-class-properties": "7.2.1",
    "@babel/plugin-proposal-decorators": "7.2.0",
    "@babel/plugin-proposal-object-rest-spread": "7.2.0",
    "@babel/plugin-transform-runtime": "7.2.0",
    "@babel/runtime": "7.2.0",
    "@react-navigation/core": "3.0.2",
    "@react-navigation/native": "3.1.0",
    "babel-preset-expo": "5.0.0",
    "expo": "31.0.6",
    "native-base": "2.10.0",
    "react": "16.5.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz",
    "react-native-vector-icons": "6.1.0",
    "react-navigation": "3.0.9",
    "react-navigation-drawer": "1.0.5",
    "react-redux": "6.0.0",
    "redux": "4.0.1"
  }

Et .babelrc dans mon répertoire racine:

{
  "presets": ["babel-preset-expo"],
  "plugins": [
    ["module-resolver", {
      "root": ["./"],
      "alias": {
        "_framework": "./framework",
        "_apps": "./apps"
      }
    }]
  ]
}
0
Patrick Dench

J'ai corrigé cette erreur en apportant la modification suivante à mon .babelrc

{
  "presets": ["module:metro-react-native-babel-preset"],
  "plugins": [
-    ["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true }]
+    ["@babel/plugin-proposal-decorators", { "legacy": true }]
  ]
}

Mon package.json:

"dependencies": {
    "axios": "^0.18.0",
    "mobx": "^5.8.0",
    "mobx-react": "^5.4.3",
    "react": "16.6.3",
    "react-native": "0.57.8",
    "react-native-device-info": "^0.24.3",
    "react-native-elements": "^1.0.0-beta5",
    "react-native-haptic-feedback": "^1.3.0",
    "react-native-svg": "^8.0.10",
    "react-native-vector-icons": "^6.0.2",
    "react-navigation": "^3.0.9",
    "rollbar-react-native": "^0.4.0"
  },
"devDependencies": {
    "@babel/core": "^7.2.2",
    "@babel/plugin-proposal-decorators": "^7.2.3",
    "babel-eslint": "^10.0.1",
    "babel-jest": "23.6.0",
    "eslint": "^5.12.0",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-jsx-a11y": "^6.1.2",
    "eslint-plugin-react": "^7.12.3",
    "eslint-plugin-react-native": "^3.5.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
  }
0
Jasdeep Singh