Custom component of sensors

I would like to get access to mobile device sensors in my Adalo app. So I need to create a custom component with GitHub - kprimice/react-native-sensor-manager: Native sensors access for react-native. So I have created my “pedometer” component with

npx create-adalo-component pedometer

After that I have a folder “pedometer” and “pedometer” component in Adalo development tab: enter image description here

Then I’m adding the external lib, I would like to use:

npm i react-native-sensor-manager --save

If I go to file: …\pedometer\src\components\Pedometer\index.js I see the following code:

import React from 'react'
import { Text, View, StyleSheet } from 'react-native'


const Pedometer = (props) => {
    const { color, text } = props

    return(
        <View style={styles.wrapper}>
            <Text style={{ color }}>{text}</Text>
        </View>
    )
}

const styles = StyleSheet.create({
    wrapper: {
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
    }
})

export default Pedometer

which works fine until I’m trying to import the sensors lib:

import { SensorManager } from 'NativeModules'

That brings me an error: Module not found: Error: Can’t resolve ‘NativeModules’. As I understand “NativeModules” should be included into “react-native-sensor-manager”. If I add something like:

import * as All from 'react-native-sensor-manager'

I’m getting the same error “Can’t resolve”.

pachage.json contains:

{
  "name": "pedometerlib",
  "description": "",
  "version": "1.0.0",
  "main": "index.js",
  "license": "ISC",
  "author": "",
  "scripts": {
    "start": "adalo dev",
    "login": "adalo login",
    "publish": "adalo publish"
  },
  "devDependencies": {
    "@adalo/cli": "^0.0.54",
    "react": "^16.14.0",
    "react-art": "^16.13.1",
    "react-dom": "^16.14.0",
    "react-native-web": "^0.9.13"
  },
  "dependencies": {
    "react-native-sensor-manager": "^0.1.10"
  }
}

I’m new in Adalo and React, could you please advise what step I missed to add “react-native-sensor-manager” correctly to my custom component?

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.