Richou / react-native-android-location-enabler

Display a GoogleMap like android popup to ask for user to enable location services if disabled
MIT License
209 stars 52 forks source link

err [TypeError: null is not an object #49

Closed pk936 closed 4 years ago

pk936 commented 4 years ago

I added this line

RNAndroidLocationEnabler.promptForEnableLocationIfNeeded( ... ) on press event and useeffect. Both sides it says

err [TypeError: null is not an object (evaluating '_reactNativeAndroidLocationEnabler.default.promptForEnableLocationIfNeeded')]

shahanshah87 commented 4 years ago

did you find solution for this?

pk936 commented 4 years ago

No. At the end I had to remove this package.

Richou commented 4 years ago

I don't get it, it worked for me :

import React from 'react';

import RNAndroidLocationEnabler from 'react-native-android-location-enabler';

const App = () => {
  React.useEffect(() => {
    RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({interval: 10000, fastInterval: 5000})
      .then((data) => {
        console.log('data', data)
      }).catch((err) => {
        console.log('error', err)
      });
  }, [])

  return ()
};

export default App;
{
  "name": "EnableLocation",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "16.13.1",
    "react-native": "0.63.2",
    "react-native-android-location-enabler": "^1.2.1"
  },
  "devDependencies": {
    "@babel/core": "^7.8.4",
    "@babel/runtime": "^7.8.4",
    "@react-native-community/eslint-config": "^1.1.0",
    "babel-jest": "^25.1.0",
    "eslint": "^6.5.1",
    "jest": "^25.1.0",
    "metro-react-native-babel-preset": "^0.59.0",
    "react-test-renderer": "16.13.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

Device : Nexus 5X API 29.