forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request facebook#123 from ryanartecona/feature/non-standar…
…d-platform-os Support non-standard Platform.OS identifiers & iOS idioms
- Loading branch information
Showing
3 changed files
with
129 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,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 | ||
| IOS(iosIdiom) | ||
| Android; | ||
|
||
[@bs.scope "Platform"] [@bs.module "react-native"] external _os : string = "OS"; | ||
[@bs.module "react-native"] [@bs.scope "Platform"] | ||
external _os : string = "OS"; | ||
|
||
let os = | ||
exception UnknownPlatform(string); | ||
|
||
let os = () => | ||
switch _os { | ||
| "ios" => IOS | ||
| _ => Android | ||
| "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 | ||
let equals = targetOs => | ||
switch (os(), targetOs) { | ||
| (IOS(_), IOS(_)) => true | ||
| (Android, Android) => true | ||
| (IOS, Android) => false | ||
| (Android, IOS) => false | ||
| exception (UnknownPlatform(_)) => false | ||
| _ => false | ||
}; | ||
|
||
[@bs.scope "Platform"] [@bs.module "react-native"] external version : int = "Version"; | ||
[@bs.module "react-native"] [@bs.scope "Platform"] | ||
external _version : Js.undefined(int) = "Version"; | ||
|
||
[@bs.scope "Platform"] [@bs.module "react-native"] | ||
external _select : {. "ios": 'a, "android": 'a} => 'a = | ||
"select"; | ||
exception UnknownVersion; | ||
|
||
let select = (~ios, ~android) => _select({"ios": ios, "android": android}); | ||
let version = () => | ||
switch (Js.Undefined.to_opt(_version)) { | ||
| Some(v) => v | ||
| None => raise(UnknownVersion) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
type iosIdiom = | ||
| Phone | ||
| Pad | ||
| TV; | ||
|
||
type os = | ||
| IOS | ||
| IOS(iosIdiom) | ||
| Android; | ||
|
||
let os: os; | ||
exception UnknownPlatform(string); | ||
|
||
/** | ||
Raises UnknownPlatform for non-standard platforms such as "web" | ||
from react-native-web | ||
*/ | ||
let os: unit => os; | ||
|
||
let equals: os => bool; | ||
|
||
[@bs.scope "Platform"] [@bs.module "react-native"] external version : int = "Version"; | ||
exception UnknownVersion; | ||
|
||
let select: (~ios: 'a, ~android: 'a) => 'a; | ||
/** | ||
Raises UnknownVersion if version is undefined, i.e. in react-native-web | ||
*/ | ||
let version: unit => int; |