index.ios.js
We already saw how we can access the method we exposed from the native module FrequencyDetector
. Let's now see how we can use it within our components tree to update the state of our app:
/*** index.ios.js ***/ ... var FrequencyDetector = NativeModules.FrequencyDetector; export default class guitarTuner extends Component { ... componentWillMount() { FrequencyDetector.initialise(); setInterval(() => { FrequencyDetector.getFrequency((res, freq) => { let stringData = getClosestString(parseInt(freq)); if(!stringData) { this.setState({ delta: null, activeString: null }); } else { this.setState({ delta: stringData.delta, activeString: stringData.number }); } }); }, 500); } ... }); AppRegistry.registerComponent('guitarTuner', () => guitarTuner);
Most of the logic will be placed in the componentWillMount
method of our...