|
| 1 | +--- |
| 2 | +id: apis/NetInfo |
| 3 | +title: NetInfo |
| 4 | +wip: true |
| 5 | +--- |
| 6 | + |
| 7 | +```reason |
| 8 | +module ConnectionType = { |
| 9 | + type t = string; |
| 10 | +
|
| 11 | + [@bs.inline] |
| 12 | + let bluetooth = "bluetooth"; |
| 13 | +
|
| 14 | + [@bs.inline] |
| 15 | + let cellular = "cellular"; |
| 16 | +
|
| 17 | + [@bs.inline] |
| 18 | + let ethernet = "ethernet"; |
| 19 | +
|
| 20 | + [@bs.inline] |
| 21 | + let unknown = "unknown"; |
| 22 | +
|
| 23 | + [@bs.inline] |
| 24 | + let wifi = "wifi"; |
| 25 | +
|
| 26 | + [@bs.inline] |
| 27 | + let wimax = "wimax"; |
| 28 | +}; |
| 29 | +
|
| 30 | +module EffectiveConnectionType = { |
| 31 | + type t = string; |
| 32 | +
|
| 33 | + [@bs.inline] |
| 34 | + let net2G = "2g"; |
| 35 | +
|
| 36 | + [@bs.inline] |
| 37 | + let net3G = "3g"; |
| 38 | +
|
| 39 | + [@bs.inline] |
| 40 | + let net4G = "4g"; |
| 41 | +
|
| 42 | + [@bs.inline] |
| 43 | + let unknown = "unknown"; |
| 44 | +}; |
| 45 | +
|
| 46 | +type info = { |
| 47 | + . |
| 48 | + "_type": ConnectionType.t, |
| 49 | + "effectiveType": EffectiveConnectionType.t, |
| 50 | +}; |
| 51 | +
|
| 52 | +type remove = {. "remove": unit => unit}; |
| 53 | +
|
| 54 | +[@bs.module "react-native"] [@bs.scope "NetInfo"] |
| 55 | +external addEventListener: |
| 56 | + ([@bs.string] [ | `connectionChange], info => unit) => remove = |
| 57 | + ""; |
| 58 | +
|
| 59 | +[@bs.module "react-native"] [@bs.scope "NetInfo"] |
| 60 | +external removeEventListener: |
| 61 | + ([@bs.string] [ | `connectionChange], info => unit) => unit = |
| 62 | + ""; |
| 63 | +
|
| 64 | +[@bs.module "react-native"] [@bs.scope "NetInfo"] |
| 65 | +external isConnectionExpensive: unit => Js.Promise.t(bool) = ""; |
| 66 | +
|
| 67 | +[@bs.module "react-native"] [@bs.scope "NetInfo"] |
| 68 | +external getConnectionInfo: unit => Js.Promise.t(info) = ""; |
| 69 | +
|
| 70 | +module IsConnected = { |
| 71 | + [@bs.module "react-native"] [@bs.scope ("NetInfo", "isConnected")] |
| 72 | + external addEventListener: |
| 73 | + ([@bs.string] [ | `connectionChange], bool => unit) => remove = |
| 74 | + ""; |
| 75 | +
|
| 76 | + [@bs.module "react-native"] [@bs.scope ("NetInfo", "isConnected")] |
| 77 | + external removeEventListener: |
| 78 | + ([@bs.string] [ | `connectionChange], bool => unit) => unit = |
| 79 | + ""; |
| 80 | +
|
| 81 | + [@bs.module "react-native"] [@bs.scope ("NetInfo", "isConnected")] |
| 82 | + external fetch: unit => Js.Promise.t(bool) = ""; |
| 83 | +}; |
| 84 | +
|
| 85 | +``` |
0 commit comments