Merge pull request #86 from felipemartim/checkbox-prompt2

Checkbox prompt support for picker
This commit is contained in:
Noitidart 2018-05-31 09:13:07 -07:00 committed by GitHub
commit f633163e3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 190 additions and 158 deletions

View File

@ -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

132
README.md
View File

@ -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: `<a>`, `<img>`, 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: `<a>`, `<img>`, 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 `<a>` 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<OptionsCommon, 'widgetColor'>
> }
| 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
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
| [<img src="https://avatars1.githubusercontent.com/u/1566403?v=4" width="100px;"/><br /><sub><b>Vojtech Novak</b></sub>](https://github.com/vonovak)<br />[💬](#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") | [<img src="https://avatars0.githubusercontent.com/u/6372489?v=4" width="100px;"/><br /><sub><b>Noitidart</b></sub>](http://noitidart.github.io/)<br />[💻](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") | [<img src="https://avatars3.githubusercontent.com/u/6080124?v=4" width="100px;"/><br /><sub><b>Alisson Carvalho</b></sub>](http://alissoncs.com)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=alissoncs "Code") | [<img src="https://avatars1.githubusercontent.com/u/1567160?v=4" width="100px;"/><br /><sub><b>Anthony Ou</b></sub>](https://github.com/Anthonyzou)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=Anthonyzou "Code") | [<img src="https://avatars0.githubusercontent.com/u/844437?v=4" width="100px;"/><br /><sub><b>Ashley White</b></sub>](http://ashleyd.ws)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=ashleydw "Code") | [<img src="https://avatars0.githubusercontent.com/u/239360?v=4" width="100px;"/><br /><sub><b>Bee</b></sub>](https://github.com/1ne8ight7even)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=1ne8ight7even "Code") | [<img src="https://avatars3.githubusercontent.com/u/6874216?v=4" width="100px;"/><br /><sub><b>BrianSo</b></sub>](https://github.com/BrianSo)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=BrianSo "Code") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars3.githubusercontent.com/u/1411784?v=4" width="100px;"/><br /><sub><b>Byron Wang</b></sub>](https://github.com/byronpc)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=byronpc "Code") | [<img src="https://avatars3.githubusercontent.com/u/5062458?v=4" width="100px;"/><br /><sub><b>Farzad Abdolhosseini</b></sub>](https://github.com/farzadab)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=farzadab "Code") | [<img src="https://avatars3.githubusercontent.com/u/8598682?v=4" width="100px;"/><br /><sub><b>Geoffrey Goh</b></sub>](https://github.com/geof90)<br />[🐛](https://github.com/aakashns/react-native-dialogs/issues?q=author%3Ageof90 "Bug reports") [💻](https://github.com/aakashns/react-native-dialogs/commits?author=geof90 "Code") | [<img src="https://avatars3.githubusercontent.com/u/7588480?v=4" width="100px;"/><br /><sub><b>Gustavo Fão Valvassori</b></sub>](http://gustavofao.com/)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=faogustavo "Code") [🤔](#ideas-faogustavo "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/16625347?v=4" width="100px;"/><br /><sub><b>Henrik</b></sub>](https://github.com/Henreich)<br />[📖](https://github.com/aakashns/react-native-dialogs/commits?author=Henreich "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/1103539?v=4" width="100px;"/><br /><sub><b>heydabop</b></sub>](https://github.com/heydabop)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=heydabop "Code") | [<img src="https://avatars0.githubusercontent.com/u/13056774?v=4" width="100px;"/><br /><sub><b>Huang Yu</b></sub>](https://github.com/hyugit)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=hyugit "Code") |
| [<img src="https://avatars0.githubusercontent.com/u/1516807?v=4" width="100px;"/><br /><sub><b>Iragne</b></sub>](http://pcdn.jairagne.ovh)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=Iragne "Code") | [<img src="https://avatars2.githubusercontent.com/u/2677334?v=4" width="100px;"/><br /><sub><b>Janic Duplessis</b></sub>](https://medium.com/@janicduplessis)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=janicduplessis "Code") | [<img src="https://avatars2.githubusercontent.com/u/7968613?v=4" width="100px;"/><br /><sub><b>jeffchienzabinet</b></sub>](https://github.com/jeffchienzabinet)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=jeffchienzabinet "Code") | [<img src="https://avatars3.githubusercontent.com/u/1088099?v=4" width="100px;"/><br /><sub><b>Jeremy Dagorn</b></sub>](http://www.jeremydagorn.com)<br />[📖](https://github.com/aakashns/react-native-dialogs/commits?author=jrm2k6 "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/13287601?v=4" width="100px;"/><br /><sub><b>jykun</b></sub>](https://github.com/jykun)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=jykun "Code") | [<img src="https://avatars2.githubusercontent.com/u/195925?v=4" width="100px;"/><br /><sub><b>Mattias Pfeiffer</b></sub>](http://pfeiffer.dk)<br />[📖](https://github.com/aakashns/react-native-dialogs/commits?author=pfeiffer "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/14799874?v=4" width="100px;"/><br /><sub><b>pureday</b></sub>](https://github.com/lakeoffaith)<br />[📖](https://github.com/aakashns/react-native-dialogs/commits?author=lakeoffaith "Documentation") |
| [<img src="https://avatars0.githubusercontent.com/u/7029942?v=4" width="100px;"/><br /><sub><b>Radek Czemerys</b></sub>](https://twitter.com/radko93)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=radko93 "Code") | [<img src="https://avatars3.githubusercontent.com/u/1160365?v=4" width="100px;"/><br /><sub><b>Ricardo Fuhrmann</b></sub>](https://github.com/Fuhrmann)<br />[📖](https://github.com/aakashns/react-native-dialogs/commits?author=Fuhrmann "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/22330398?v=4" width="100px;"/><br /><sub><b>Ross</b></sub>](https://thebhwgroup.com/)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=rdixonbhw "Code") | [<img src="https://avatars2.githubusercontent.com/u/5407363?v=4" width="100px;"/><br /><sub><b>Vinicius Zaramella</b></sub>](http://programei.com)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=vzaramel "Code") |
| [<img src="https://avatars1.githubusercontent.com/u/1566403?v=4" width="100px;"/><br /><sub><b>Vojtech Novak</b></sub>](https://github.com/vonovak)<br />[💬](#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") | [<img src="https://avatars0.githubusercontent.com/u/6372489?v=4" width="100px;"/><br /><sub><b>Noitidart</b></sub>](http://noitidart.github.io/)<br />[💻](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") | [<img src="https://avatars3.githubusercontent.com/u/6080124?v=4" width="100px;"/><br /><sub><b>Alisson Carvalho</b></sub>](http://alissoncs.com)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=alissoncs "Code") | [<img src="https://avatars1.githubusercontent.com/u/1567160?v=4" width="100px;"/><br /><sub><b>Anthony Ou</b></sub>](https://github.com/Anthonyzou)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=Anthonyzou "Code") | [<img src="https://avatars0.githubusercontent.com/u/844437?v=4" width="100px;"/><br /><sub><b>Ashley White</b></sub>](http://ashleyd.ws)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=ashleydw "Code") | [<img src="https://avatars0.githubusercontent.com/u/239360?v=4" width="100px;"/><br /><sub><b>Bee</b></sub>](https://github.com/1ne8ight7even)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=1ne8ight7even "Code") | [<img src="https://avatars3.githubusercontent.com/u/6874216?v=4" width="100px;"/><br /><sub><b>BrianSo</b></sub>](https://github.com/BrianSo)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=BrianSo "Code") |
|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| [<img src="https://avatars3.githubusercontent.com/u/1411784?v=4" width="100px;"/><br /><sub><b>Byron Wang</b></sub>](https://github.com/byronpc)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=byronpc "Code") | [<img src="https://avatars3.githubusercontent.com/u/5062458?v=4" width="100px;"/><br /><sub><b>Farzad Abdolhosseini</b></sub>](https://github.com/farzadab)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=farzadab "Code") | [<img src="https://avatars3.githubusercontent.com/u/8598682?v=4" width="100px;"/><br /><sub><b>Geoffrey Goh</b></sub>](https://github.com/geof90)<br />[🐛](https://github.com/aakashns/react-native-dialogs/issues?q=author%3Ageof90 "Bug reports") [💻](https://github.com/aakashns/react-native-dialogs/commits?author=geof90 "Code") | [<img src="https://avatars3.githubusercontent.com/u/7588480?v=4" width="100px;"/><br /><sub><b>Gustavo Fão Valvassori</b></sub>](http://gustavofao.com/)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=faogustavo "Code") [🤔](#ideas-faogustavo "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/16625347?v=4" width="100px;"/><br /><sub><b>Henrik</b></sub>](https://github.com/Henreich)<br />[📖](https://github.com/aakashns/react-native-dialogs/commits?author=Henreich "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/1103539?v=4" width="100px;"/><br /><sub><b>heydabop</b></sub>](https://github.com/heydabop)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=heydabop "Code") | [<img src="https://avatars0.githubusercontent.com/u/13056774?v=4" width="100px;"/><br /><sub><b>Huang Yu</b></sub>](https://github.com/hyugit)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=hyugit "Code") |
| [<img src="https://avatars0.githubusercontent.com/u/1516807?v=4" width="100px;"/><br /><sub><b>Iragne</b></sub>](http://pcdn.jairagne.ovh)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=Iragne "Code") | [<img src="https://avatars2.githubusercontent.com/u/2677334?v=4" width="100px;"/><br /><sub><b>Janic Duplessis</b></sub>](https://medium.com/@janicduplessis)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=janicduplessis "Code") | [<img src="https://avatars2.githubusercontent.com/u/7968613?v=4" width="100px;"/><br /><sub><b>jeffchienzabinet</b></sub>](https://github.com/jeffchienzabinet)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=jeffchienzabinet "Code") | [<img src="https://avatars3.githubusercontent.com/u/1088099?v=4" width="100px;"/><br /><sub><b>Jeremy Dagorn</b></sub>](http://www.jeremydagorn.com)<br />[📖](https://github.com/aakashns/react-native-dialogs/commits?author=jrm2k6 "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/13287601?v=4" width="100px;"/><br /><sub><b>jykun</b></sub>](https://github.com/jykun)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=jykun "Code") | [<img src="https://avatars2.githubusercontent.com/u/195925?v=4" width="100px;"/><br /><sub><b>Mattias Pfeiffer</b></sub>](http://pfeiffer.dk)<br />[📖](https://github.com/aakashns/react-native-dialogs/commits?author=pfeiffer "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/14799874?v=4" width="100px;"/><br /><sub><b>pureday</b></sub>](https://github.com/lakeoffaith)<br />[📖](https://github.com/aakashns/react-native-dialogs/commits?author=lakeoffaith "Documentation") |
| [<img src="https://avatars0.githubusercontent.com/u/7029942?v=4" width="100px;"/><br /><sub><b>Radek Czemerys</b></sub>](https://twitter.com/radko93)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=radko93 "Code") | [<img src="https://avatars3.githubusercontent.com/u/1160365?v=4" width="100px;"/><br /><sub><b>Ricardo Fuhrmann</b></sub>](https://github.com/Fuhrmann)<br />[📖](https://github.com/aakashns/react-native-dialogs/commits?author=Fuhrmann "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/22330398?v=4" width="100px;"/><br /><sub><b>Ross</b></sub>](https://thebhwgroup.com/)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=rdixonbhw "Code") | [<img src="https://avatars2.githubusercontent.com/u/5407363?v=4" width="100px;"/><br /><sub><b>Vinicius Zaramella</b></sub>](http://programei.com)<br />[💻](https://github.com/aakashns/react-native-dialogs/commits?author=vzaramel "Code") | | | |
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!

View File

@ -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'
}

View File

@ -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() {