Open Grandiz opened 8 years ago
if i call noble.on('stateChange', console.log); i will get an error
Illegal invocation Noble.EventEmitter.emit events.js @77:0
here is full code. could anyone help?
import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, TouchableHighlight, DeviceEventEmitter } from 'react-native'; import Orientation from 'react-native-orientation'; import { Accelerometer } from 'NativeModules'; var noble = require('react-native-ble'); Accelerometer.setAccelerometerUpdateInterval(5); class arduinoCar extends Component { handlePressIn(){ Accelerometer.startAccelerometerUpdates(); } handlePressOut(){ Accelerometer.stopAccelerometerUpdates(); } componentWillMount(){ noble.on('stateChange', console.log); //noble.on('discover', console.log); } componentDidMount(){ Orientation.lockToLandscape(); DeviceEventEmitter.addListener('AccelerationData', function (data) { console.log('acceleration data ', data.acceleration); }); } render() { return ( <View style={styles.container}> <TouchableHighlight underlayColor='#A74040' style={styles.button} onPressIn={this.handlePressIn} onPressOut={this.handlePressOut}> <Text style={styles.buttonText}>Start</Text> </TouchableHighlight> </View> ); } } AppRegistry.registerComponent('arduinoCar', () => arduinoCar);
It's norman, you should give a handler. What you can do is noble.on('stateChange', function(state) { // Your code here });
noble.on('stateChange', function(state) { // Your code here });
but console.log is a handler !
if i call noble.on('stateChange', console.log); i will get an error
Illegal invocation Noble.EventEmitter.emit events.js @77:0
here is full code. could anyone help?