import React from 'react'; import { View, Text, TouchableOpacity, StyleSheet, Alert } from 'react-native'; import { useToneDetection } from '../hooks/useToneDetection'; import { ToneListenReactNativeConfig } from '../types/ToneTypes'; interface ToneDetectionComponentProps { config?: ToneListenReactNativeConfig; onSequenceDetected?: (sequence: string) => void; } /** * Example React Native component for tone detection */ export const ToneDetectionComponent: React.FC = ({ config = {}, onSequenceDetected }) => { const { isListening, isInitialized, error, lastSequence, lastDualTone, lastBridgeTone, startListening, stopListening } = useToneDetection({ ...config, onSequence: (event) => { onSequenceDetected?.(event.sequence); } }); const handleStartPress = async () => { const started = await startListening(); if (!started) { Alert.alert('Error', 'Failed to start tone detection'); } }; const handleStopPress = () => { stopListening(); }; if (error) { return ( Error: {error.message} ); } if (!isInitialized) { return ( Initializing tone detection... ); } return ( Tone Detection Status: {isListening ? 'Listening' : 'Stopped'} {isListening ? 'Stop Listening' : 'Start Listening'} {lastSequence && ( Last Sequence: {lastSequence} )} {lastDualTone?.ok && ( Last Dual Tone: {lastDualTone.tag} ({lastDualTone.lowFreq}Hz, {lastDualTone.highFreq}Hz) )} {lastBridgeTone?.bridge && ( Last Bridge Tone: {lastBridgeTone.bridge}Hz (wide: {lastBridgeTone.wide}) )} ); }; const styles = StyleSheet.create({ container: { flex: 1, padding: 20, backgroundColor: '#f5f5f5', }, title: { fontSize: 24, fontWeight: 'bold', textAlign: 'center', marginBottom: 20, color: '#333', }, statusContainer: { marginBottom: 20, }, statusText: { fontSize: 16, textAlign: 'center', color: '#666', }, errorText: { fontSize: 16, textAlign: 'center', color: '#ff0000', }, buttonContainer: { marginBottom: 20, }, button: { padding: 15, borderRadius: 8, alignItems: 'center', }, startButton: { backgroundColor: '#4CAF50', }, stopButton: { backgroundColor: '#f44336', }, buttonText: { color: 'white', fontSize: 16, fontWeight: 'bold', }, resultContainer: { marginBottom: 10, padding: 10, backgroundColor: 'white', borderRadius: 8, borderWidth: 1, borderColor: '#ddd', }, resultTitle: { fontSize: 14, fontWeight: 'bold', color: '#333', marginBottom: 5, }, resultText: { fontSize: 16, color: '#666', }, });