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#98 from tonyhb/feature/datepicker-android
Add DatePickerAndroid API
- Loading branch information
Showing
7 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ node_js: | |
- "7" | ||
|
||
script: | ||
- npm run build | ||
- npm run clean-build | ||
|
||
cache: | ||
directories: | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
[@bs.scope "DatePickerAndroid"] [@bs.module "react-native"] external dateSet : string = | ||
"dateSetAction"; | ||
|
||
[@bs.scope "DatePickerAndroid"] [@bs.module "react-native"] external dismissed : string = | ||
"dismissedAction"; | ||
|
||
type mode = | ||
| Calendar | ||
| Spinner | ||
| Default; | ||
|
||
type response = { | ||
year: int, | ||
month: int, | ||
day: int | ||
}; | ||
|
||
type action = | ||
| Dismissed | ||
| Set(response); | ||
|
||
let action = (resp) => | ||
if (resp##action == dateSet) { | ||
Set({year: resp##year, month: resp##month, day: resp##day}) | ||
} else if (resp##action == dismissed) { | ||
Dismissed | ||
} else { | ||
failwith( | ||
"Unknown action received from DatePickerAndroid. Please report this in the bs-react-native repository" | ||
) | ||
}; | ||
|
||
type responseJs = {. "action": string, "year": int, "month": int, "day": int}; | ||
|
||
type optsJs = { | ||
. | ||
"date": Js.Date.t, | ||
"minDate": Js.Nullable.t(Js.Date.t), | ||
"maxDate": Js.Nullable.t(Js.Date.t), | ||
"mode": string | ||
}; | ||
|
||
[@bs.scope "DatePickerAndroid"] [@bs.module "react-native"] | ||
external _open : optsJs => Js.Promise.t(responseJs) = | ||
"open"; | ||
|
||
let open_ = (~date: Js.Date.t, ~minDate=?, ~maxDate=?, ~mode=Default, ()) => | ||
_open({ | ||
"date": date, | ||
"minDate": Js.Nullable.from_opt(minDate), | ||
"maxDate": Js.Nullable.from_opt(maxDate), | ||
"mode": | ||
switch mode { | ||
| Default => "default" | ||
| Calendar => "calendar" | ||
| Spinner => "spinner" | ||
} | ||
}) | ||
|> Js.Promise.then_((resp: responseJs) => resp |> action |> Js.Promise.resolve); |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
type response = { | ||
year: int, | ||
month: int, | ||
day: int | ||
}; | ||
|
||
type action = | ||
| Dismissed | ||
| Set(response); | ||
|
||
type mode = | ||
| Calendar | ||
| Spinner | ||
| Default; | ||
|
||
let open_: | ||
(~date: Js.Date.t, ~minDate: Js.Date.t=?, ~maxDate: Js.Date.t=?, ~mode: mode=?, unit) => | ||
Js.Promise.t(action); |