diff --git a/DialogAndroid.js b/DialogAndroid.js
index 4e8370a..fb84788 100644
--- a/DialogAndroid.js
+++ b/DialogAndroid.js
@@ -8,6 +8,16 @@ type IdKey = string | 'id';
type LabelKey = string | 'label';
type ListItem = { label:string, id?:any };
+type OptionsAlert = {|
+ ...OptionsCheckbox,
+ ...OptionsCommon
+|}
+
+type OptionsCheckbox = {|
+ checkboxLabel?: string,
+ checkboxDefaultValue?: boolean
+|}
+
type OptionsCommon = {|
title?: null | string,
titleColor?: ColorValue,
@@ -222,10 +232,9 @@ class DialogAndroid {
Object.assign(DialogAndroid.defaults, defaults);
}
- static alert(title: Title, content: Content, options?: OptionsCommon = {}): Promise<
- {|
- action: typeof DialogAndroid.actionPositive | typeof DialogAndroid.actionNegative | typeof DialogAndroid.actionNeutral | typeof DialogAndroid.actionDismiss
- |}
+ static alert(title: Title, content: Content, options?: OptionsAlert = {}): Promise<
+ {| action: typeof DialogAndroid.actionPositive | typeof DialogAndroid.actionNegative | typeof DialogAndroid.actionNeutral | typeof DialogAndroid.actionDismiss |} |
+ {| action: typeof DialogAndroid.actionPositive | typeof DialogAndroid.actionNegative | typeof DialogAndroid.actionNeutral, checked: boolean |}
> {
return new Promise((resolve, reject) => {
const nativeConfig: NativeConfig = {
@@ -249,11 +258,11 @@ class DialogAndroid {
return resolve({ action:DialogAndroid.actionDismiss });
}
case 'onAny': {
- const [ dialogAction ] = rest;
+ const [ dialogAction, checked ] = rest;
switch (dialogAction) {
- case 0: return resolve({ action:DialogAndroid.actionPositive });
- case 1: return resolve({ action:DialogAndroid.actionNeutral });
- case 2: return resolve({ action:DialogAndroid.actionNegative });
+ case 0: return resolve({ action:DialogAndroid.actionPositive, ...getChecked(nativeConfig, checked) });
+ case 1: return resolve({ action:DialogAndroid.actionNeutral, ...getChecked(nativeConfig, checked) });
+ case 2: return resolve({ action:DialogAndroid.actionNegative, ...getChecked(nativeConfig, checked) });
}
}
default: {
@@ -265,15 +274,12 @@ class DialogAndroid {
}
static showPicker(title: Title, content: Content, options: OptionsPicker): Promise<
- {|
- action: typeof DialogAndroid.actionNegative | typeof DialogAndroid.actionNeutral | typeof DialogAndroid.actionDismiss
- |} | {|
- action: typeof DialogAndroid.actionSelect,
- selectedItem: ListItem
- |} | {|
- action: typeof DialogAndroid.actionSelect,
- selectedItems: ListItem[]
- |}
+ {| action: typeof DialogAndroid.actionNegative | typeof DialogAndroid.actionNeutral | typeof DialogAndroid.actionDismiss |} |
+ {| action: typeof DialogAndroid.actionNegative | typeof DialogAndroid.actionNeutral, checked: boolean |} |
+ {| action: typeof DialogAndroid.actionSelect, selectedItem: ListItem |} |
+ {| action: typeof DialogAndroid.actionSelect, selectedItem: ListItem, checked: boolean |} |
+ {| action: typeof DialogAndroid.actionSelect, selectedItems: ListItem[] |} |
+ {| action: typeof DialogAndroid.actionSelect, selectedItems: ListItem[], checked: boolean |}
> {
// options is required, must defined items
@@ -332,27 +338,23 @@ class DialogAndroid {
return reject(`DialogAndroid ${error}. nativeConfig: ${nativeConfig}`);
}
case 'itemsCallbackMultiChoice': {
- const selectedIndicesString = rest[0]; // blank string when nothing selected
+ const [selectedIndicesString, checked] = rest; // blank string when nothing selected
const selectedItems = selectedIndicesString === '' ? [] : selectedIndicesString.split(',').map(index => items[index]);
- return resolve({ action:DialogAndroid.actionPositive, selectedItems });
+ return resolve({ action:DialogAndroid.actionPositive, selectedItems, ...getChecked(nativeConfig, checked) });
}
case 'itemsCallback':
case 'itemsCallbackSingleChoice': {
- const [ selectedIndex, selectedLabel, isPromptCheckBoxChecked ] = rest;
+ const [ selectedIndex, checked ] = rest;
const selectedItem = items[selectedIndex];
- return resolve({
- action: DialogAndroid.actionSelect,
- selectedItem,
- isPromptCheckBoxChecked
- });
+ return resolve({ action:DialogAndroid.actionSelect, selectedItem, ...getChecked(nativeConfig, checked) });
}
case 'onAny': {
- const [ dialogAction ] = rest;
+ const [ dialogAction, checked ] = rest;
switch (dialogAction) {
- case 0: return resolve({ action:DialogAndroid.actionPositive });
- case 1: return resolve({ action:DialogAndroid.actionNeutral });
- case 2: return resolve({ action:DialogAndroid.actionNegative });
+ case 0: return resolve({ action:DialogAndroid.actionPositive, ...getChecked(nativeConfig, checked) });
+ case 1: return resolve({ action:DialogAndroid.actionNeutral, ...getChecked(nativeConfig, checked) });
+ case 2: return resolve({ action:DialogAndroid.actionNegative, ...getChecked(nativeConfig, checked) });
}
}
case 'dismissListener': {
@@ -416,12 +418,10 @@ class DialogAndroid {
}
static prompt(title: Title, content: Content, options?: OptionsPrompt = {}): Promise<
- {|
- action: typeof DialogAndroid.actionNegative | typeof DialogAndroid.actionNeutral | typeof DialogAndroid.actionDismiss
- |} | {|
- action: typeof DialogAndroid.actionPositive,
- text: string
- |}
+ {| action: typeof DialogAndroid.actionNegative | typeof DialogAndroid.actionNeutral | typeof DialogAndroid.actionDismiss |} |
+ {| action: typeof DialogAndroid.actionNegative | typeof DialogAndroid.actionNeutral, checked: boolean |} |
+ {| action: typeof DialogAndroid.actionPositive, text: string |} |
+ {| action: typeof DialogAndroid.actionPositive, text: string, checked: boolean |}
> {
return new Promise((resolve, reject) => {
@@ -462,15 +462,15 @@ class DialogAndroid {
return reject(`DialogAndroid ${error}. nativeConfig: ${nativeConfig}`);
}
case 'onAny': {
- const [ dialogAction ] = rest;
+ const [ dialogAction, checked ] = rest;
switch (dialogAction) {
- case 1: return resolve({ action:DialogAndroid.actionNeutral });
- case 2: return resolve({ action:DialogAndroid.actionNegative });
+ case 1: return resolve({ action:DialogAndroid.actionNeutral, ...getChecked(nativeConfig, checked) });
+ case 2: return resolve({ action:DialogAndroid.actionNegative, ...getChecked(nativeConfig, checked) });
}
}
case 'input': {
- const [ text ] = rest;
- return resolve({ action:DialogAndroid.actionPositive, text });
+ const [ text, checked ] = rest;
+ return resolve({ action:DialogAndroid.actionPositive, text, ...getChecked(nativeConfig, checked) });
}
case 'dismissListener': {
return resolve({ action:DialogAndroid.actionDismiss });
@@ -489,4 +489,8 @@ class DialogAndroid {
}
}
+function getChecked(nativeConfig, checked) {
+ return nativeConfig.checkboxLabel ? { checked } : {};
+}
+
export default DialogAndroid
diff --git a/README.md b/README.md
index df535b6..088bd77 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,8 @@ An Android only module for Material Design dialogs. This is a wrapper over [afol
- [`type ActionType`](#type-actiontype)
- [`type ListItem`](#type-listitem)
- [`type ListType`](#type-listtype)
+ - [`type OptionsAlert`](#type-optionsalert)
+ - [`type OptionsCheckbox`](#type-optionscheckbox)
- [`type OptionsCommon`](#type-optionscommon)
- [`type OptionsProgress`](#type-optionsprogress)
- [`type OptionsPicker`](#type-optionspicker)
@@ -216,16 +218,19 @@ The default options to be used by all methods. To modify this, either directly m
> static alert(
> title: Title,
> content: Content,
-> options: Options
-> ): Promise<{| action: "actionDismiss" | "actionNegative" | "actionNeutral" | "actionPositive" |}>
+> options: OptionsAlert
+> ): Promise<
+> {| action: "actionDismiss" | "actionNegative" | "actionNeutral" | "actionPositive" |} |
+> {| action: "actionDismiss" | "actionNegative" | "actionNeutral" | "actionPositive", checked: boolean |}
+> >
Shows a dialog.
-| Parameter | Type | Default | Required | Description |
-|-----------|----------------------------------------|---------|----------|--------------------------------------------|
-| title | `string, null, void` | | | Title of dialog |
-| content | `string, null, void` | | | Message of dialog |
-| options | [`OptionsCommon`](#type-optionscommon) | | | See [`OptionsCommon`](#type-optionscommon) |
+| Parameter | Type | Default | Required | Description |
+|-----------|--------------------------------------|---------|----------|------------------------------------------|
+| title | `string, null, void` | | | Title of dialog |
+| content | `string, null, void` | | | Message of dialog |
+| options | [`OptionsAlert`](#type-optionsalert) | | | See [`OptionsAlert`](#type-optionsalert) |
##### `assignDefaults`
@@ -254,7 +259,9 @@ Hides the currently showing dialog.
> options: OptionsPrompt
> ): Promise<
> {| action: "actionNegative" | "actionNeutral" | "actionDismiss" |} |
-> {| action: "actionPositive", text: string |}
+> {| action: "actionNegative" | "actionNeutral", checked: boolean |} |
+> {| action: "actionPositive", text: string |} |
+> {| action: "actionPositive", text: string, checked: boolean |}
> >
Shows a dialog with a text input field.
@@ -273,8 +280,11 @@ Shows a dialog with a text input field.
> options: OptionsPicker
> ): Promise<
> {| action: "actionNegative" | "actionNeutral" | "actionDismiss" |} |
+> {| action: "actionNegative" | "actionNeutral" | "actionDismiss", checked: boolean |} |
> {| action: "actionSelect", selectedItem: ListItem |} |
-> {| action: "actionSelect", selectedItems: ListItem[] |}
+> {| action: "actionSelect", selectedItem: ListItem, checked: boolean |} |
+> {| action: "actionSelect", selectedItems: ListItem[] |} |
+> {| action: "actionSelect", selectedItems: ListItem[], checked: boolean |}
> >
Shows a regular alert, but also with items that can be selected.
@@ -323,6 +333,30 @@ Shows a progress dialog. By default no buttons are shown, and hardware back butt
> "listCheckbox" | "listPlain" | "listRadio"
+##### `type OptionsAlert`
+
+> {
+> ...OptionsCommon,
+> ...OptionsAlert
+> }
+
+| Key | Type | Default | Required | Description |
+|--------------------|--------------------------------------------|---------|----------|------------------------------------------------|
+| ...OptionsCheckbox | [`OptionsCheckbox`](#type-optionscheckbox) | | | See [`OptionsCheckbox`](#type-optionscheckbox) |
+| ...OptionsCommon | [`OptionsCommon`](#type-optionscommon) | | | See [`OptionsCommon`](#type-optionscommon) |
+
+##### `type OptionsCheckbox`
+
+> {
+> checkboxLabel?: string,
+> checkboxDefaultValue?: boolean
+> }
+
+| Key | Type | Default | Required | Description |
+|----------------------|-----------|---------|----------|------------------------------------------------------------------------------------|
+| checkboxLabel | `string` | | | If set, then there is a checkbox shown at the bottom of the dialog with this label |
+| checkboxDefaultValue | `boolean` | `false` | | The initial state of the checkbox. Does nothing if `checkboxLabel` is not set |
+
##### `type OptionsCommon`
> {
@@ -342,21 +376,21 @@ Shows a progress dialog. By default no buttons are shown, and hardware back butt
> titleColor?: ColorValue,
> }
-| Key | Type | Default | Required | Description |
-|---------------|----------------------------------------------------------------------------|---------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------|
-| cancelable | `boolean` | | | If tapping outside of dialog area, or hardware back button, should dismiss dialog. |
-| content | `string` | | | Dialog message |
+| Key | Type | Default | Required | Description |
+|---------------|--------------------------------------------------------------------------|---------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------|
+| cancelable | `boolean` | | | If tapping outside of dialog area, or hardware back button, should dismiss dialog. |
+| content | `string` | | | Dialog message |
| contentColor | [`ColorValue`](https://facebook.github.io/react-native/docs/colors.html) | | | Color of dialog message |
-| contentIsHtml | `boolean` | | | If dialog message should be parsed as html. (supported tags include: ``, ``, etc) |
-| forceStacking | `boolean` | | | If you have multiple action buttons that together are too wide to fit on one line, the dialog will stack the buttons to be vertically oriented. |
+| contentIsHtml | `boolean` | | | If dialog message should be parsed as html. (supported tags include: ``, ``, etc) |
+| forceStacking | `boolean` | | | If you have multiple action buttons that together are too wide to fit on one line, the dialog will stack the buttons to be vertically oriented. |
| linkColor | [`ColorValue`](https://facebook.github.io/react-native/docs/colors.html) | | | If `contentIsHtml` is true, and `content` contains `` tags, these are colored with this color |
| negativeColor | [`ColorValue`](https://facebook.github.io/react-native/docs/colors.html) | | | |
-| negativeText | `string` | | | If falsy, button is not shown. |
+| negativeText | `string` | | | If falsy, button is not shown. |
| neutralColor | [`ColorValue`](https://facebook.github.io/react-native/docs/colors.html) | | | |
-| neutralText | `string` | | | Shows button in far left with this string as label. If falsy, button is not shown. |
+| neutralText | `string` | | | Shows button in far left with this string as label. If falsy, button is not shown. |
| positiveColor | [`ColorValue`](https://facebook.github.io/react-native/docs/colors.html) | | | |
-| positiveText | `string` | | | If falsy, button is not shown. |
-| title | `string` | | | Title of dialog |
+| positiveText | `string` | | | If falsy, button is not shown. |
+| title | `string` | | | Title of dialog |
| titleColor | [`ColorValue`](https://facebook.github.io/react-native/docs/colors.html) | | | Color of title |
##### `type OptionsProgress`
@@ -371,14 +405,14 @@ Shows a progress dialog. By default no buttons are shown, and hardware back butt
> widgetColor: $PropertyType
> }
-| Key | Type | Default | Required | Description |
-|---------------|----------------------------------------------------------------------------|---------|----------|----------------------------------------------------------|
-| contentColor | [`OptionsCommon#contentColor`](#type-optionscommon) | | | See [`OptionsCommon#contentColor`](#type-optionscommon) |
-| contentIsHtml | [`OptionsCommon#contentIsHtml`](#type-optionscommon) | | | See [`OptionsCommon#contentIsHtml`](#type-optionscommon) |
-| linkColor | [`OptionsCommon#linkColor`](#type-optionscommon) | | | See [`OptionsCommon#linkColor`](#type-optionscommon) |
-| style | [`ProgressStyle`](#type-ProgressStyle) | | | See [`ProgressStyle`](#type-progressstyle) |
-| title | [`OptionsCommon#title`](#type-optionscommon) | | | See [`OptionsCommon#title`](#type-optionscommon) |
-| titleColor | [`OptionsCommon#titleColor`](#type-optionscommon) | | | See [`OptionsCommon#titleColor`](#type-optionscommon) |
+| Key | Type | Default | Required | Description |
+|---------------|--------------------------------------------------------------------------|---------|----------|----------------------------------------------------------|
+| contentColor | [`OptionsCommon#contentColor`](#type-optionscommon) | | | See [`OptionsCommon#contentColor`](#type-optionscommon) |
+| contentIsHtml | [`OptionsCommon#contentIsHtml`](#type-optionscommon) | | | See [`OptionsCommon#contentIsHtml`](#type-optionscommon) |
+| linkColor | [`OptionsCommon#linkColor`](#type-optionscommon) | | | See [`OptionsCommon#linkColor`](#type-optionscommon) |
+| style | [`ProgressStyle`](#type-ProgressStyle) | | | See [`ProgressStyle`](#type-progressstyle) |
+| title | [`OptionsCommon#title`](#type-optionscommon) | | | See [`OptionsCommon#title`](#type-optionscommon) |
+| titleColor | [`OptionsCommon#titleColor`](#type-optionscommon) | | | See [`OptionsCommon#titleColor`](#type-optionscommon) |
| widgetColor | [`ColorValue`](https://facebook.github.io/react-native/docs/colors.html) | | | Color of progress indicator |
##### `type OptionsPicker`
@@ -395,17 +429,18 @@ Shows a progress dialog. By default no buttons are shown, and hardware back butt
> widgetColor?: ColorValue
> }
-| Key | Type | Default | Required | Description |
-|----------------|----------------------------------------------------------------------------|---------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| OptionsCommon | [`OptionsCommon`](#type-optionscommon) | | | See [`OptionsCommon`](#type-optionscommon) |
-| idKey | `string` | "id" | | |
-| items | [`ListItem`](#type-listitem)[] | | Yes | See [`ListItem`](#type-listitem) |
-| labelKey | `string` | "label" | | |
-| neutralIsClear | `boolean` | | | Pressing the neutral button causes the dialog to be closed and `selectedItems` to be an empty array. Only works if `neutralText` is also supplied. |
-| selectedId | `any` | | | The respective radio will be selected on dialog show. If no such id is found, then nothing is selected. Only applicable if `type` is `DialogAndroid.listRadio`. Requires that `items[]` contain key described by `idKey`. |
-| selectedIds | `any[]` | | | The respective checkbox will be selected on dialog show. If no such id is found, nothing is selected for that id. Only applicable if `type` is `DialogAndroid.listCheckbox`. Requires that `items[]` contain key described by `idKey`. |
-| type | [`ListType`](#type-listtype) | `DialogAndroid.listPlain` | | See [`ListType`](#type-listtype) |
-| widgetColor | [`ColorValue`](https://facebook.github.io/react-native/docs/colors.html) | | | Color of radio or checkbox |
+| Key | Type | Default | Required | Description |
+|-----------------|--------------------------------------------------------------------------|---------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| OptionsCheckbox | [`OptionsCheckbox`](#type-optionscheckbox) | | | See [`OptionsCheckbox`](#type-optionscheckbox) |
+| OptionsCommon | [`OptionsCommon`](#type-optionscommon) | | | See [`OptionsCommon`](#type-optionscommon) |
+| idKey | `string` | "id" | | |
+| items | [`ListItem`](#type-listitem)[] | | Yes | See [`ListItem`](#type-listitem) |
+| labelKey | `string` | "label" | | |
+| neutralIsClear | `boolean` | | | Pressing the neutral button causes the dialog to be closed and `selectedItems` to be an empty array. Only works if `neutralText` is also supplied. |
+| selectedId | `any` | | | The respective radio will be selected on dialog show. If no such id is found, then nothing is selected. Only applicable if `type` is `DialogAndroid.listRadio`. Requires that `items[]` contain key described by `idKey`. |
+| selectedIds | `any[]` | | | The respective checkbox will be selected on dialog show. If no such id is found, nothing is selected for that id. Only applicable if `type` is `DialogAndroid.listCheckbox`. Requires that `items[]` contain key described by `idKey`. |
+| type | [`ListType`](#type-listtype) | `DialogAndroid.listPlain` | | See [`ListType`](#type-listtype) |
+| widgetColor | [`ColorValue`](https://facebook.github.io/react-native/docs/colors.html) | | | Color of radio or checkbox |
##### `type OptionsPrompt`
@@ -414,10 +449,11 @@ Shows a progress dialog. By default no buttons are shown, and hardware back butt
> widgetColor?: ColorValue
> }
-| Key | Type | Default | Required | Description |
-|---------------|----------------------------------------------------------------------------|---------|----------|--------------------------------------------|
-| OptionsCommon | [`OptionsCommon`](#type-optionscommon) | | | See [`OptionsCommon`](#type-optionscommon) |
-| widgetColor | [`ColorValue`](https://facebook.github.io/react-native/docs/colors.html) | | | Color of field underline and cursor |
+| Key | Type | Default | Required | Description |
+|-----------------|--------------------------------------------------------------------------|---------|----------|------------------------------------------------|
+| OptionsCheckbox | [`OptionsCheckbox`](#type-optionscheckbox) | | | See [`OptionsCheckbox`](#type-optionscheckbox) |
+| OptionsCommon | [`OptionsCommon`](#type-optionscommon) | | | See [`OptionsCommon`](#type-optionscommon) |
+| widgetColor | [`ColorValue`](https://facebook.github.io/react-native/docs/colors.html) | | | Color of field underline and cursor |
##### `type ProgressStyle`
@@ -425,6 +461,8 @@ Shows a progress dialog. By default no buttons are shown, and hardware back butt
### Examples
+To see the examples redone with `checkboxLabel` see this PR - [Github :: aakashns/react-native-dialogs - #86](https://github.com/aakashns/react-native-dialogs/pull/86#issuecomment-393408317)
+
#### Progress Dialog
![](https://github.com/aakashns/react-native-dialogs/blob/master/screenshots/progress-bar.png)
@@ -602,11 +640,11 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
-| [
Vojtech Novak](https://github.com/vonovak)
[đŹ](#question-vonovak "Answering Questions") [đť](https://github.com/aakashns/react-native-dialogs/commits?author=vonovak "Code") [đ¤](#ideas-vonovak "Ideas, Planning, & Feedback") [đ](#review-vonovak "Reviewed Pull Requests") | [
Noitidart](http://noitidart.github.io/)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=Noitidart "Code") [đ](https://github.com/aakashns/react-native-dialogs/commits?author=Noitidart "Documentation") [đĄ](#example-Noitidart "Examples") [đ¤](#ideas-Noitidart "Ideas, Planning, & Feedback") | [
Alisson Carvalho](http://alissoncs.com)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=alissoncs "Code") | [
Anthony Ou](https://github.com/Anthonyzou)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=Anthonyzou "Code") | [
Ashley White](http://ashleyd.ws)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=ashleydw "Code") | [
Bee](https://github.com/1ne8ight7even)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=1ne8ight7even "Code") | [
BrianSo](https://github.com/BrianSo)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=BrianSo "Code") |
-| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
-| [
Byron Wang](https://github.com/byronpc)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=byronpc "Code") | [
Farzad Abdolhosseini](https://github.com/farzadab)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=farzadab "Code") | [
Geoffrey Goh](https://github.com/geof90)
[đ](https://github.com/aakashns/react-native-dialogs/issues?q=author%3Ageof90 "Bug reports") [đť](https://github.com/aakashns/react-native-dialogs/commits?author=geof90 "Code") | [
Gustavo FĂŁo Valvassori](http://gustavofao.com/)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=faogustavo "Code") [đ¤](#ideas-faogustavo "Ideas, Planning, & Feedback") | [
Henrik](https://github.com/Henreich)
[đ](https://github.com/aakashns/react-native-dialogs/commits?author=Henreich "Documentation") | [
heydabop](https://github.com/heydabop)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=heydabop "Code") | [
Huang Yu](https://github.com/hyugit)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=hyugit "Code") |
-| [
Iragne](http://pcdn.jairagne.ovh)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=Iragne "Code") | [
Janic Duplessis](https://medium.com/@janicduplessis)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=janicduplessis "Code") | [
jeffchienzabinet](https://github.com/jeffchienzabinet)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=jeffchienzabinet "Code") | [
Jeremy Dagorn](http://www.jeremydagorn.com)
[đ](https://github.com/aakashns/react-native-dialogs/commits?author=jrm2k6 "Documentation") | [
jykun](https://github.com/jykun)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=jykun "Code") | [
Mattias Pfeiffer](http://pfeiffer.dk)
[đ](https://github.com/aakashns/react-native-dialogs/commits?author=pfeiffer "Documentation") | [
pureday](https://github.com/lakeoffaith)
[đ](https://github.com/aakashns/react-native-dialogs/commits?author=lakeoffaith "Documentation") |
-| [
Radek Czemerys](https://twitter.com/radko93)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=radko93 "Code") | [
Ricardo Fuhrmann](https://github.com/Fuhrmann)
[đ](https://github.com/aakashns/react-native-dialogs/commits?author=Fuhrmann "Documentation") | [
Ross](https://thebhwgroup.com/)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=rdixonbhw "Code") | [
Vinicius Zaramella](http://programei.com)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=vzaramel "Code") |
+| [
Vojtech Novak](https://github.com/vonovak)
[đŹ](#question-vonovak "Answering Questions") [đť](https://github.com/aakashns/react-native-dialogs/commits?author=vonovak "Code") [đ¤](#ideas-vonovak "Ideas, Planning, & Feedback") [đ](#review-vonovak "Reviewed Pull Requests") | [
Noitidart](http://noitidart.github.io/)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=Noitidart "Code") [đ](https://github.com/aakashns/react-native-dialogs/commits?author=Noitidart "Documentation") [đĄ](#example-Noitidart "Examples") [đ¤](#ideas-Noitidart "Ideas, Planning, & Feedback") | [
Alisson Carvalho](http://alissoncs.com)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=alissoncs "Code") | [
Anthony Ou](https://github.com/Anthonyzou)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=Anthonyzou "Code") | [
Ashley White](http://ashleyd.ws)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=ashleydw "Code") | [
Bee](https://github.com/1ne8ight7even)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=1ne8ight7even "Code") | [
BrianSo](https://github.com/BrianSo)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=BrianSo "Code") |
+|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
+| [
Byron Wang](https://github.com/byronpc)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=byronpc "Code") | [
Farzad Abdolhosseini](https://github.com/farzadab)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=farzadab "Code") | [
Geoffrey Goh](https://github.com/geof90)
[đ](https://github.com/aakashns/react-native-dialogs/issues?q=author%3Ageof90 "Bug reports") [đť](https://github.com/aakashns/react-native-dialogs/commits?author=geof90 "Code") | [
Gustavo FĂŁo Valvassori](http://gustavofao.com/)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=faogustavo "Code") [đ¤](#ideas-faogustavo "Ideas, Planning, & Feedback") | [
Henrik](https://github.com/Henreich)
[đ](https://github.com/aakashns/react-native-dialogs/commits?author=Henreich "Documentation") | [
heydabop](https://github.com/heydabop)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=heydabop "Code") | [
Huang Yu](https://github.com/hyugit)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=hyugit "Code") |
+| [
Iragne](http://pcdn.jairagne.ovh)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=Iragne "Code") | [
Janic Duplessis](https://medium.com/@janicduplessis)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=janicduplessis "Code") | [
jeffchienzabinet](https://github.com/jeffchienzabinet)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=jeffchienzabinet "Code") | [
Jeremy Dagorn](http://www.jeremydagorn.com)
[đ](https://github.com/aakashns/react-native-dialogs/commits?author=jrm2k6 "Documentation") | [
jykun](https://github.com/jykun)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=jykun "Code") | [
Mattias Pfeiffer](http://pfeiffer.dk)
[đ](https://github.com/aakashns/react-native-dialogs/commits?author=pfeiffer "Documentation") | [
pureday](https://github.com/lakeoffaith)
[đ](https://github.com/aakashns/react-native-dialogs/commits?author=lakeoffaith "Documentation") |
+| [
Radek Czemerys](https://twitter.com/radko93)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=radko93 "Code") | [
Ricardo Fuhrmann](https://github.com/Fuhrmann)
[đ](https://github.com/aakashns/react-native-dialogs/commits?author=Fuhrmann "Documentation") | [
Ross](https://thebhwgroup.com/)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=rdixonbhw "Code") | [
Vinicius Zaramella](http://programei.com)
[đť](https://github.com/aakashns/react-native-dialogs/commits?author=vzaramel "Code") | | | |
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
diff --git a/android/build.gradle b/android/build.gradle
index ae9e302..df6cfc2 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -31,5 +31,5 @@ dependencies {
compile 'com.facebook.react:react-native:+'
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
- compile 'com.afollestad.material-dialogs:commons:0.8.6.2'
+ compile 'com.afollestad.material-dialogs:commons:0.9.0.1'
}
diff --git a/android/src/main/java/com/aakashns/reactnativedialogs/modules/DialogAndroid.java b/android/src/main/java/com/aakashns/reactnativedialogs/modules/DialogAndroid.java
index 329c19f..ed2d14b 100644
--- a/android/src/main/java/com/aakashns/reactnativedialogs/modules/DialogAndroid.java
+++ b/android/src/main/java/com/aakashns/reactnativedialogs/modules/DialogAndroid.java
@@ -29,16 +29,12 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
return "DialogAndroid";
}
-
public DialogAndroid(ReactApplicationContext reactContext) {
super(reactContext);
}
/* Apply the options to the provided builder */
- private MaterialDialog.Builder applyOptions(
- MaterialDialog.Builder builder,
- ReadableMap options
- ) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
+ private MaterialDialog.Builder applyOptions(MaterialDialog.Builder builder, ReadableMap options) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
ReadableMapKeySetIterator iterator = options.keySetIterator();
while(iterator.hasNextKey()) {
String key = iterator.nextKey();
@@ -103,6 +99,7 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
builder.autoDismiss(options.getBoolean("autoDismiss"));
break;
case "forceStacking":
+ // should change to StackingBehavior? forceStacking is deprecated?
builder.forceStacking(options.getBoolean("forceStacking"));
break;
case "alwaysCallSingleChoiceCallback":
@@ -124,8 +121,7 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
builder.cancelable(options.getBoolean("cancelable"));
break;
case "progressIndeterminateStyle": // true for horizontal, DO NOT USE
- builder.progressIndeterminateStyle(
- options.getBoolean("progressIndeterminateStyle"));
+ builder.progressIndeterminateStyle(options.getBoolean("progressIndeterminateStyle"));
break;
case "buttonsGravity":
String bg = options.getString("buttonsGravity");
@@ -163,15 +159,17 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
builder.btnStackedGravity(GravityEnum.START);
}
break;
+ case "checkboxLabel":
+ boolean defaultValue = options.hasKey("checkboxDefaultValue") && options.getBoolean("checkboxDefaultValue");
+ builder.checkBoxPrompt(options.getString("checkboxLabel"), defaultValue, null);
+ break;
case "progress":
ReadableMap progress = options.getMap("progress");
- boolean indeterminate = progress.hasKey("indeterminate") &&
- progress.getBoolean("indeterminate");
+ boolean indeterminate = progress.hasKey("indeterminate") && progress.getBoolean("indeterminate");
if (indeterminate) {
builder.progress(true, 0);
- boolean horizontal = progress.hasKey("style") &&
- progress.getString("style").equals("horizontal");
+ boolean horizontal = progress.hasKey("style") && progress.getString("style").equals("horizontal");
if (horizontal) builder.progressIndeterminateStyle(horizontal);
} else {
// Determinate progress bar not supported currently
@@ -239,11 +237,11 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
if (!mCallbackConsumed) {
mCallbackConsumed = true;
if (dialogAction == DialogAction.POSITIVE) {
- callback.invoke("onAny", 0);
+ callback.invoke("onAny", 0, materialDialog.isPromptCheckBoxChecked());
} else if (dialogAction == DialogAction.NEUTRAL) {
- callback.invoke("onAny", 1);
+ callback.invoke("onAny", 1, materialDialog.isPromptCheckBoxChecked());
} else {
- callback.invoke("onAny", 2);
+ callback.invoke("onAny", 2, materialDialog.isPromptCheckBoxChecked());
}
}
}
@@ -253,11 +251,10 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
if (options.hasKey("itemsCallback")) {
mBuilder.itemsCallback(new MaterialDialog.ListCallback() {
@Override
- public void onSelection(MaterialDialog materialDialog, View view, int i,
- CharSequence charSequence) {
+ public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
if (!mCallbackConsumed) {
mCallbackConsumed = true;
- callback.invoke("itemsCallback", i, charSequence == null ? null : charSequence.toString());
+ callback.invoke("itemsCallback", i, materialDialog.isPromptCheckBoxChecked());
}
}
});
@@ -265,21 +262,18 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
if (options.hasKey("itemsCallbackSingleChoice")) {
// Check if there is a preselected index
- int selectedIndex = options.hasKey("selectedIndex") ?
- options.getInt("selectedIndex") : -1;
- mBuilder.itemsCallbackSingleChoice(selectedIndex,
- new MaterialDialog.ListCallbackSingleChoice() {
- @Override
- public boolean onSelection(MaterialDialog materialDialog, View view, int i,
- CharSequence charSequence) {
- if (!mCallbackConsumed) {
- mCallbackConsumed = true;
- charSequence = charSequence == null ? "" : charSequence;
- callback.invoke("itemsCallbackSingleChoice", i, charSequence.toString());
- }
- return true;
- }
- });
+ int selectedIndex = options.hasKey("selectedIndex") ? options.getInt("selectedIndex") : -1;
+ mBuilder.itemsCallbackSingleChoice(selectedIndex, new MaterialDialog.ListCallbackSingleChoice() {
+ @Override
+ public boolean onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
+ if (!mCallbackConsumed) {
+ mCallbackConsumed = true;
+ charSequence = charSequence == null ? "" : charSequence;
+ callback.invoke("itemsCallbackSingleChoice", i, materialDialog.isPromptCheckBoxChecked());
+ }
+ return true;
+ }
+ });
}
if (options.hasKey("itemsCallbackMultiChoice")) {
@@ -293,32 +287,29 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
}
}
- mBuilder.itemsCallbackMultiChoice(selectedIndices,
- new MaterialDialog.ListCallbackMultiChoice() {
- @Override
- public boolean onSelection(MaterialDialog materialDialog,
- Integer[] integers, CharSequence[] charSequences) {
+ mBuilder.itemsCallbackMultiChoice(selectedIndices, new MaterialDialog.ListCallbackMultiChoice() {
+ @Override
+ public boolean onSelection(MaterialDialog materialDialog, Integer[] integers, CharSequence[] charSequences) {
- // Concatenate selected IDs into a string
- StringBuilder selected = new StringBuilder("");
- for (int i = 0; i < integers.length - 1; i++) {
- selected.append(integers[i]).append(",");
- }
- if (integers.length > 0) {
- selected.append(integers[integers.length - 1]);
- }
+ // Concatenate selected IDs into a string
+ StringBuilder selected = new StringBuilder("");
+ for (int i = 0; i < integers.length - 1; i++) {
+ selected.append(integers[i]).append(",");
+ }
+ if (integers.length > 0) {
+ selected.append(integers[integers.length - 1]);
+ }
- if (!mCallbackConsumed) {
- mCallbackConsumed = true;
- callback.invoke("itemsCallbackMultiChoice", selected.toString());
- }
- return true;
- }
- });
+ if (!mCallbackConsumed) {
+ mCallbackConsumed = true;
+ callback.invoke("itemsCallbackMultiChoice", selected.toString(), materialDialog.isPromptCheckBoxChecked());
+ }
+ return true;
+ }
+ });
// Provide a 'Clear' button to unselect all choices
- if (options.hasKey("multiChoiceClearButton") &&
- options.getBoolean("multiChoiceClearButton")) {
+ if (options.hasKey("multiChoiceClearButton") && options.getBoolean("multiChoiceClearButton")) {
mBuilder.onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
@@ -371,8 +362,7 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
String prefill = input.hasKey("prefill") ? input.getString("prefill") : null;
// Check if empty input is allowed
- boolean allowEmptyInput = !input.hasKey("allowEmptyInput") ||
- input.getBoolean("allowEmptyInput");
+ boolean allowEmptyInput = !input.hasKey("allowEmptyInput") || input.getBoolean("allowEmptyInput");
// TODO : Provide pre-selected input types in Javascript
if (input.hasKey("type")) {
@@ -389,7 +379,7 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
if (!mCallbackConsumed) {
mCallbackConsumed = true;
- callback.invoke("input", charSequence.toString());
+ callback.invoke("input", charSequence.toString(), materialDialog.isPromptCheckBoxChecked());
}
}
});
@@ -407,7 +397,18 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
MaterialDialog simple;
@ReactMethod
public void list(ReadableMap options, final Callback callback) {
- final MaterialSimpleListAdapter simpleListAdapter = new MaterialSimpleListAdapter(getCurrentActivity());
+ final MaterialSimpleListAdapter simpleListAdapter = new MaterialSimpleListAdapter(new MaterialSimpleListAdapter.Callback() {
+ @Override
+ public void onMaterialListItemSelected(int index, MaterialSimpleListItem item) {
+ if (!mCallbackConsumed) {
+ mCallbackConsumed = true;
+ callback.invoke(index, item.getContent());
+ }
+ if (simple != null) {
+ simple.dismiss();
+ }
+ }
+ });
ReadableArray arr = options.getArray("items");
for(int i = 0; i < arr.size(); i++){
@@ -418,18 +419,7 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
final MaterialDialog.Builder adapter = new MaterialDialog.Builder(getCurrentActivity())
.title(options.hasKey("title") ? options.getString("title") : "")
- .adapter(simpleListAdapter, new MaterialDialog.ListCallback() {
- @Override
- public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
- if (!mCallbackConsumed) {
- mCallbackConsumed = true;
- callback.invoke(which, text);
- }
- if (simple != null) {
- simple.dismiss();
- }
- }
- })
+ .adapter(simpleListAdapter, null)
.autoDismiss(true);
UiThreadUtil.runOnUiThread(new Runnable() {