Skip to content

Commit

Permalink
Merge pull request facebook#98 from tonyhb/feature/datepicker-android
Browse files Browse the repository at this point in the history
Add DatePickerAndroid API
  • Loading branch information
arnarthor authored Dec 20, 2017
2 parents 612b2e0 + fb18089 commit b1721fc
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ node_js:
- "7"

script:
- npm run build
- npm run clean-build

cache:
directories:
Expand Down
2 changes: 1 addition & 1 deletion STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
- [x] BackHandler
- [ ] CameraRoll
- [ ] Clipboard
- [ ] DatePickerAndroid
- [x] DatePickerAndroid
- [x] Dimensions
- [ ] Easing
- [ ] Geolocation
Expand Down
2 changes: 1 addition & 1 deletion lib/js/src/components/sectionList.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions lib/js/src/datePickerAndroid.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"build": "bsb -make-world",
"start": "bsb -make-world -w",
"clean": "bsb -clean-world",
"clean-build": "bsb -clean-world -make-world",
"test": "exit 0"
},
"license": "MIT",
Expand Down
59 changes: 59 additions & 0 deletions src/datePickerAndroid.re
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);
18 changes: 18 additions & 0 deletions src/datePickerAndroid.rei
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);

0 comments on commit b1721fc

Please sign in to comment.