Skip to content

Commit 4b241a6

Browse files
sgnycknitt
authored andcommitted
NetInfo bindings (#403)
* NetInfo bindings * Revise NetInfo types * define addEventListener return type, move types * Move types into NetInfo module, define interface
1 parent a0a6a55 commit 4b241a6

4 files changed

Lines changed: 250 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
4+
var ConnectionType = /* module */[];
5+
6+
var EffectiveConnectionType = /* module */[];
7+
8+
var IsConnected = /* module */[];
9+
10+
exports.ConnectionType = ConnectionType;
11+
exports.EffectiveConnectionType = EffectiveConnectionType;
12+
exports.IsConnected = IsConnected;
13+
/* No side effect */
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
```
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
module ConnectionType = {
2+
type t = string;
3+
4+
[@bs.inline]
5+
let bluetooth = "bluetooth";
6+
7+
[@bs.inline]
8+
let cellular = "cellular";
9+
10+
[@bs.inline]
11+
let ethernet = "ethernet";
12+
13+
[@bs.inline]
14+
let unknown = "unknown";
15+
16+
[@bs.inline]
17+
let wifi = "wifi";
18+
19+
[@bs.inline]
20+
let wimax = "wimax";
21+
};
22+
23+
module EffectiveConnectionType = {
24+
type t = string;
25+
26+
[@bs.inline]
27+
let net2G = "2g";
28+
29+
[@bs.inline]
30+
let net3G = "3g";
31+
32+
[@bs.inline]
33+
let net4G = "4g";
34+
35+
[@bs.inline]
36+
let unknown = "unknown";
37+
};
38+
39+
type info = {
40+
.
41+
"_type": ConnectionType.t,
42+
"effectiveType": EffectiveConnectionType.t,
43+
};
44+
45+
type remove = {. "remove": unit => unit};
46+
47+
[@bs.module "react-native"] [@bs.scope "NetInfo"]
48+
external addEventListener:
49+
([@bs.string] [ | `connectionChange], info => unit) => remove =
50+
"";
51+
52+
[@bs.module "react-native"] [@bs.scope "NetInfo"]
53+
external removeEventListener:
54+
([@bs.string] [ | `connectionChange], info => unit) => unit =
55+
"";
56+
57+
[@bs.module "react-native"] [@bs.scope "NetInfo"]
58+
external isConnectionExpensive: unit => Js.Promise.t(bool) = "";
59+
60+
[@bs.module "react-native"] [@bs.scope "NetInfo"]
61+
external getConnectionInfo: unit => Js.Promise.t(info) = "";
62+
63+
module IsConnected = {
64+
[@bs.module "react-native"] [@bs.scope ("NetInfo", "isConnected")]
65+
external addEventListener:
66+
([@bs.string] [ | `connectionChange], bool => unit) => remove =
67+
"";
68+
69+
[@bs.module "react-native"] [@bs.scope ("NetInfo", "isConnected")]
70+
external removeEventListener:
71+
([@bs.string] [ | `connectionChange], bool => unit) => unit =
72+
"";
73+
74+
[@bs.module "react-native"] [@bs.scope ("NetInfo", "isConnected")]
75+
external fetch: unit => Js.Promise.t(bool) = "";
76+
};
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
module ConnectionType: {
2+
type t;
3+
4+
[@bs.inline "bluetooth"]
5+
let bluetooth: t;
6+
7+
[@bs.inline "cellular"]
8+
let cellular: t;
9+
10+
[@bs.inline "ethernet"]
11+
let ethernet: t;
12+
13+
[@bs.inline "unknown"]
14+
let unknown: t;
15+
16+
[@bs.inline "wifi"]
17+
let wifi: t;
18+
19+
[@bs.inline "wimax"]
20+
let wimax: t;
21+
};
22+
23+
module EffectiveConnectionType: {
24+
type t;
25+
26+
[@bs.inline "2g"]
27+
let net2G: t;
28+
29+
[@bs.inline "3g"]
30+
let net3G: t;
31+
32+
[@bs.inline "4g"]
33+
let net4G: t;
34+
35+
[@bs.inline "unknown"]
36+
let unknown: t;
37+
};
38+
39+
type info = {
40+
.
41+
"effectiveType": EffectiveConnectionType.t,
42+
"_type": ConnectionType.t,
43+
};
44+
45+
type remove = {. "remove": unit => unit};
46+
47+
[@bs.module "react-native"] [@bs.scope "NetInfo"]
48+
external addEventListener:
49+
([@bs.string] [ | `connectionChange], info => unit) => remove =
50+
"";
51+
52+
[@bs.module "react-native"] [@bs.scope "NetInfo"]
53+
external removeEventListener:
54+
([@bs.string] [ | `connectionChange], info => unit) => unit =
55+
"";
56+
57+
[@bs.module "react-native"] [@bs.scope "NetInfo"]
58+
external isConnectionExpensive: unit => Js.Promise.t(bool) = "";
59+
60+
[@bs.module "react-native"] [@bs.scope "NetInfo"]
61+
external getConnectionInfo: unit => Js.Promise.t(info) = "";
62+
63+
module IsConnected: {
64+
[@bs.module "react-native"] [@bs.scope ("NetInfo", "isConnected")]
65+
external addEventListener:
66+
([@bs.string] [ | `connectionChange], bool => unit) => remove =
67+
"";
68+
69+
[@bs.module "react-native"] [@bs.scope ("NetInfo", "isConnected")]
70+
external removeEventListener:
71+
([@bs.string] [ | `connectionChange], bool => unit) => unit =
72+
"";
73+
74+
[@bs.module "react-native"] [@bs.scope ("NetInfo", "isConnected")]
75+
external fetch: unit => Js.Promise.t(bool) = "";
76+
};

0 commit comments

Comments
 (0)