import React from 'react';
import { View, Text, StyleSheet, ScrollView } from 'react-native';
import {
useBatteryLevel,
usePowerState,
useBatteryLevelIsLow,
useIsHeadphonesConnected,
useIsWiredHeadphonesConnected,
useIsBluetoothHeadphonesConnected,
useBrightness,
} from 'react-native-nitro-device-info';
export function DeviceMonitorDashboard() {
// Battery hooks
const batteryLevel = useBatteryLevel();
const powerState = usePowerState();
const lowBattery = useBatteryLevelIsLow();
// Headphone hooks
const headphones = useIsHeadphonesConnected();
const wiredHeadphones = useIsWiredHeadphonesConnected();
const bluetoothHeadphones = useIsBluetoothHeadphonesConnected();
// Display hooks
const brightness = useBrightness();
return (
<ScrollView style={styles.container}>
<Text style={styles.title}>Device Monitor</Text>
{/* Battery Section */}
<View style={styles.section}>
<Text style={styles.sectionTitle}>🔋 Battery</Text>
<Row label="Level" value={formatPercent(batteryLevel)} />
<Row label="State" value={powerState.batteryState ?? 'unknown'} />
<Row label="Low Power Mode" value={powerState.lowPowerMode ? 'Yes' : 'No'} />
{lowBattery !== null && (
<View style={styles.warning}>
<Text style={styles.warningText}>⚠️ Low Battery!</Text>
</View>
)}
</View>
{/* Audio Section */}
<View style={styles.section}>
<Text style={styles.sectionTitle}>🎧 Audio Output</Text>
<Row label="Any Headphones" value={headphones ? 'Connected' : 'Disconnected'} />
<Row label="Wired" value={wiredHeadphones ? 'Yes' : 'No'} />
<Row label="Bluetooth" value={bluetoothHeadphones ? 'Yes' : 'No'} />
</View>
{/* Display Section */}
<View style={styles.section}>
<Text style={styles.sectionTitle}>📱 Display</Text>
<Row
label="Brightness"
value={brightness !== null && brightness >= 0
? formatPercent(brightness)
: 'N/A'
}
/>
</View>
</ScrollView>
);
}
function Row({ label, value }: { label: string; value: string }) {
return (
<View style={styles.row}>
<Text style={styles.label}>{label}</Text>
<Text style={styles.value}>{value}</Text>
</View>
);
}
function formatPercent(value: number | null): string {
if (value === null) return 'Loading...';
return `${Math.round(value * 100)}%`;
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
backgroundColor: '#fff',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 16,
},
section: {
marginBottom: 20,
padding: 12,
backgroundColor: '#f5f5f5',
borderRadius: 8,
},
sectionTitle: {
fontSize: 18,
fontWeight: '600',
marginBottom: 8,
},
row: {
flexDirection: 'row',
justifyContent: 'space-between',
paddingVertical: 4,
},
label: {
fontWeight: '500',
},
value: {
color: '#666',
},
warning: {
backgroundColor: '#fff3cd',
padding: 8,
borderRadius: 4,
marginTop: 8,
},
warningText: {
color: '#856404',
},
});