UNPKG

1.13 kBPlain TextView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10import {NetInfoState} from './types';
11
12export const DEVICE_CONNECTIVITY_EVENT = 'netInfo.networkStatusDidChange';
13
14// Certain properties are optional when sent by the native module and are handled by the JS code
15export type NetInfoNativeModuleState = Pick<
16 NetInfoState,
17 Exclude<keyof NetInfoState, 'isInternetReachable'>
18> & {isInternetReachable?: boolean};
19
20export interface Events {
21 [DEVICE_CONNECTIVITY_EVENT]: NetInfoNativeModuleState;
22}
23
24export interface NetInfoNativeModule {
25 getCurrentState: (
26 requestedInterface?: string,
27 ) => Promise<NetInfoNativeModuleState>;
28 addListener<K extends keyof Events>(
29 type: K,
30 listener: (event: Events[K]) => void,
31 ): void;
32 removeListeners<K extends keyof Events>(
33 type: K,
34 listener: (event: Events[K]) => void,
35 ): void;
36}
37
38export type NetInfoInternetReachabilityChangeListener = (
39 isInternetReachable: boolean | null | undefined,
40) => void;