import * as Network from 'expo-network'; import { type NetworkStatusResult, normalizeHostBridgeConnectionType, } from '../../../packages/shared/src/contracts/hostBridge'; export function normalizeMobileNetworkStatus( state: Network.NetworkState, ): NetworkStatusResult { const nativeType = state.type; const connectionType = normalizeHostBridgeConnectionType(nativeType); return { isConnected: typeof state.isConnected === 'boolean' ? state.isConnected : connectionType !== 'none' && connectionType !== 'unknown', isInternetReachable: typeof state.isInternetReachable === 'boolean' ? state.isInternetReachable : null, connectionType, ...(nativeType ? { nativeType } : {}), }; } export async function getMobileNetworkStatus() { return normalizeMobileNetworkStatus(await Network.getNetworkStateAsync()); } export function subscribeMobileNetworkStatus( listener: (status: NetworkStatusResult) => void, ) { const subscription = Network.addNetworkStateListener((state) => { listener(normalizeMobileNetworkStatus(state)); }); return () => subscription.remove(); }