import React, { useEffect, useRef, useState } from 'react'; import { Keyboard, Platform, Pressable, Text, View, StyleSheet, StatusBar } from 'react-native'; import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context'; import { KeyboardVisibleContext } from './components/keyboardLayout'; import { TabBar, TabKey } from './components/TabBar'; import { CustomMentraLiveOtaFlow } from './ota/CustomMentraLiveOtaFlow'; import { DeviceScreen } from './screens/DeviceScreen'; import { CameraScreen } from './screens/CameraScreen'; import { StreamScreen } from './screens/StreamScreen'; import { SystemScreen } from './screens/SystemScreen'; import { ConsoleScreen } from './screens/ConsoleScreen'; import { otaFlowAdmission } from './otaFlowAdmission'; import { connectedWifiStatus } from './sdkFormat'; import { colors } from './components/theme'; import { isMentraLiveRuntime, useBluetoothSdkExample } from './useBluetoothSdkExample'; export default function App() { const [tab, setTab] = useState('device'); const [keyboardVisible, setKeyboardVisible] = useState(false); const [otaVisible, setOtaVisible] = useState(false); const [waitingForWifi, setWaitingForWifi] = useState(false); const otaCompletedGenerationRef = useRef(null); const sdk = useBluetoothSdkExample({activeTab: tab}); const currentWifi = connectedWifiStatus(sdk.glasses); // A failed attempt to join another network must not block the current one. const otaWifiSetupComplete = currentWifi !== null && sdk.wifiConnectingSsid === null; const mentraLiveConnected = isMentraLiveRuntime(sdk.glasses); const connectionGeneration = mentraLiveConnected && sdk.glasses.connected ? sdk.glassesConnectionGeneration : null; useEffect(() => { const admission = otaFlowAdmission({ completedConnectionGeneration: otaCompletedGenerationRef.current, connectionGeneration, waitingForWifi, }); if (admission === 'idle') { if (!otaVisible) { otaCompletedGenerationRef.current = null; setWaitingForWifi(false); } return; } if (admission === 'wait_for_wifi' || admission === 'done') { return; } setWaitingForWifi(false); setOtaVisible(true); }, [connectionGeneration, mentraLiveConnected, otaVisible, sdk.glasses, waitingForWifi]); useEffect(() => { const showEvent = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow'; const hideEvent = Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide'; const showSub = Keyboard.addListener(showEvent, () => setKeyboardVisible(true)); const hideSub = Keyboard.addListener(hideEvent, () => setKeyboardVisible(false)); return () => { showSub.remove(); hideSub.remove(); }; }, []); const finishOta = () => { otaCompletedGenerationRef.current = connectionGeneration; setOtaVisible(false); }; const openWifiSetup = () => { setWaitingForWifi(true); setOtaVisible(false); setTab('system'); }; const openOta = () => { otaCompletedGenerationRef.current = null; setWaitingForWifi(false); setOtaVisible(true); }; return ( {otaVisible ? ( ) : ( {waitingForWifi && tab === 'system' && ( {otaWifiSetupComplete ? `Connected to ${currentWifi?.ssid}` : 'Connect to a Wi-Fi network to continue the update.'} {otaWifiSetupComplete && ( Continue update )} )} {tab === 'device' && } {tab === 'camera' && } {tab === 'stream' && } {tab === 'system' && } {tab === 'console' && } {!keyboardVisible && } )} ); } const styles = StyleSheet.create({ root: { flex: 1, backgroundColor: '#fff' }, screen: { flex: 1 }, otaResume: { padding: 16, gap: 12, borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: colors.hairline }, otaResumeText: { color: colors.ink, fontSize: 14 }, otaResumeButton: { backgroundColor: colors.greenInk, borderRadius: 14, minHeight: 48, alignItems: 'center', justifyContent: 'center' }, otaResumeLabel: { color: colors.bg, fontSize: 14, fontWeight: '700' }, });