2

I'm new to React-Native and building my first application. I am trying to use this library to build a simple Step Counting App. I did the npm install and also the react-natvie link. I am trying to copy the same way that the owner of the library mentioned on the page.

But still I am getting the following error:

TypeError: undefined is not an object (evaluating 
'BMDPedometer.isStepCountingAvailable')
: This error is located at:
in StepsCounter (at App.js:26)
in App (at renderApplication.js:32)
in RCTView (at View.js:43)
in RCTView (at View.js:43)
in AppContainer (at renderApplication.js:31)
TypeError: undefined is not an object (evaluating'BMDPedometer.isStepCountingAvailable')

Here is my StepsCounter.android.js

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import Pedometer from '@asserdata/react-native-universal-pedometer';

export default class StepsCounter extends Component{

constructor(){
    Pedometer.isStepCountingAvailable((error,isAvailable)=>{
if(error) throw error;
        console.log("Working");
    })
}

render()
{
    return(
    <View>
        <Text> Brooooo</Text>
    </View>
    );
}
    }

And here is my App.js

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,AppRegistry} from 'react-native';
import ReactNative from 'react-native';
import Pedometer from '@asserdata/react-native-universal-pedometer';
import StepsCounter from './components/stepscounter';

const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component<Props> {
render() {
return (
  <StepsCounter/>
);
}
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});

// ReactNative.AppRegistry.registerComponent('StepsCounter',()=> App);
ChiggyB
  • 21
  • 4

1 Answers1

1

First, one issue there is that you are using an unmaintained fork of the actual package, react-native-universal-pedometer. You will need to remove the links it added and remove it:

react-native unlink @asserdata/react-native-universal-pedometer
yarn remove @asserdata/react-native-universal-pedometer

Next, because react-native-universal-pedometer also has an issue since they included react-native as a dependency of the package rather than a peer dep you will most likely end up with a version conflict.

While waiting for the maintainer to publish a new npm version that would include this fix, what you can do is install the package directly from Github:

yarn add smekalka/react-native-universal-pedometer
react-native link

This will take the master version of the repo where the dependency is not present anymore.

I've made an example repository you can have a look at where I'm successfully able to call isStepCountingAvailable without any error here.

Note that I am using yarn to manage my deps, but you can use npm instead obviously

Preview
  • 35,317
  • 10
  • 92
  • 112