forked from rescript-react-native/rescript-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.re
More file actions
53 lines (43 loc) · 1.1 KB
/
Copy pathplatform.re
File metadata and controls
53 lines (43 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
type iosIdiom =
| Phone
| Pad
| TV;
[@bs.module "react-native"] [@bs.scope "Platform"]
external _ios_isPad: bool = "isPad";
[@bs.module "react-native"] [@bs.scope "Platform"]
external _ios_isTVOS: bool = "isTVOS";
type os =
| IOS(iosIdiom)
| Android;
[@bs.module "react-native"] [@bs.scope "Platform"] external _os: string = "OS";
exception UnknownPlatform(string);
let os = () =>
switch (_os) {
| "ios" =>
switch (_ios_isPad) {
| true => IOS(Pad)
| _ =>
switch (_ios_isTVOS) {
| true => IOS(TV)
| _ => IOS(Phone)
}
}
| "android" => Android
| x => raise(UnknownPlatform(x))
};
let equals = targetOs =>
switch (os(), targetOs) {
| (IOS(_), IOS(_)) => true
| (Android, Android) => true
| (Android, IOS(_)) => false
| (IOS(_), Android) => false
| exception (UnknownPlatform(_)) => false
};
[@bs.module "react-native"] [@bs.scope "Platform"]
external _version: Js.undefined(int) = "Version";
exception UnknownVersion;
let version = () =>
switch (Js.Undefined.toOption(_version)) {
| Some(v) => v
| None => raise(UnknownVersion)
};