Added maxNumberOfItems property (#102)
* DialogAndroid.js - Adding max number of items in a list property * DialogAndroid.java - Added maxNumOfItems in a list dialog property, and handling so we control the dialog's size.
This commit is contained in:
parent
b2fa7cc6cd
commit
86341a5bfc
|
@ -32,7 +32,8 @@ type OptionsCommon = {|
|
|||
neutralColor?: ColorValue,
|
||||
cancelable?: boolean,
|
||||
linkColor?: ColorValue, // applies if contentIsHtml is true, and there are <a> elements in content string
|
||||
forceStacking?: boolean
|
||||
forceStacking?: boolean,
|
||||
maxNumberOfItems?: int
|
||||
|}
|
||||
|
||||
type ListItemJustLabel = { label:string };
|
||||
|
@ -41,10 +42,12 @@ type ListItemFull = { label:string, id:any };
|
|||
type ListItemBare = {};
|
||||
|
||||
type OptionsRadio = {|
|
||||
maxNumberOfItems?: int,
|
||||
type: typeof ListType.listRadio,
|
||||
widgetColor?: ColorValue // radio color
|
||||
|}
|
||||
type OptionsCheckbox = {|
|
||||
maxNumberOfItems?: int,
|
||||
type: typeof ListType.listCheckbox,
|
||||
neutralIsClear?: boolean,
|
||||
widgetColor?: ColorValue // checkbox color
|
||||
|
@ -53,10 +56,12 @@ type OptionsCheckbox = {|
|
|||
type OptionsPicker = {|
|
||||
...OptionsCommon,
|
||||
type?: typeof ListType.listPlain,
|
||||
maxNumberOfItems?: int,
|
||||
items: ListItemJustLabel[],
|
||||
|} | {|
|
||||
...OptionsCommon,
|
||||
type?: typeof ListType.listPlain,
|
||||
maxNumberOfItems?: int,
|
||||
items: ListItemBare[],
|
||||
labelKey: string
|
||||
|} | {|
|
||||
|
|
|
@ -353,7 +353,7 @@ Shows a progress dialog. By default no buttons are shown, and hardware back butt
|
|||
> content?: string,
|
||||
> contentColor?: string,
|
||||
> contentIsHtml?: boolean,
|
||||
> forceStacking?: boolean
|
||||
> forceStacking?: boolean,
|
||||
> linkColor?: ColorValue,
|
||||
> negativeColor?: ColorValue,
|
||||
> negativeText?: string,
|
||||
|
@ -363,6 +363,7 @@ Shows a progress dialog. By default no buttons are shown, and hardware back butt
|
|||
> positiveText?: string, // default "OK"
|
||||
> title?: string,
|
||||
> titleColor?: ColorValue,
|
||||
> maxNumberOfItems?: boolean,
|
||||
> }
|
||||
|
||||
| Key | Type | Default | Required | Description |
|
||||
|
@ -381,6 +382,7 @@ Shows a progress dialog. By default no buttons are shown, and hardware back butt
|
|||
| 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 |
|
||||
| maxNumberOfItems | `int` | | | If you want to set a max amount of visible items in a list |
|
||||
|
||||
##### `type OptionsProgress`
|
||||
|
||||
|
|
|
@ -3,9 +3,12 @@ package com.aakashns.reactnativedialogs.modules;
|
|||
import android.content.DialogInterface;
|
||||
import android.graphics.Color;
|
||||
import android.text.Html;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.os.Build;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.aakashns.reactnativedialogs.R;
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.GravityEnum;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
|
@ -384,11 +387,37 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
final int numberOfItems;
|
||||
if (options.hasKey("maxNumberOfItems")) {
|
||||
numberOfItems = options.getInt("maxNumberOfItems");
|
||||
}else{
|
||||
numberOfItems = -1;
|
||||
}
|
||||
|
||||
UiThreadUtil.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (mDialog != null)
|
||||
mDialog.dismiss();
|
||||
mDialog = mBuilder.build();
|
||||
|
||||
if(numberOfItems > 0) {
|
||||
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
|
||||
lp.copyFrom(mDialog.getWindow().getAttributes());
|
||||
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
|
||||
int dp = (int) (getReactApplicationContext().getResources().getDimension(R.dimen.md_listitem_height)
|
||||
/ getReactApplicationContext().getResources().getDisplayMetrics().density);
|
||||
|
||||
|
||||
float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp * (numberOfItems +3), getReactApplicationContext().getResources().getDisplayMetrics());
|
||||
|
||||
|
||||
lp.height = (int) pixels;
|
||||
mDialog.getWindow().setAttributes(lp);
|
||||
}
|
||||
|
||||
|
||||
mDialog.show();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue