-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add style, to readme. and also added the properties i just added of h… #31
base: master
Are you sure you want to change the base?
Changes from 4 commits
97f27bf
5d68e7f
4d870b7
9b16846
f9ab93b
cddf659
8d4b760
97f5166
51a4b24
1dd31e5
7ee8ae5
1293f23
0a6c21b
9b13e6c
8a3b945
37f3e0c
aa95548
e8092ab
a08841b
dd428a8
1aac796
37ceddd
a3c1199
a1ab4db
3e2e89f
47c5cba
dcc7a0b
515e307
e724872
88ea270
2f428e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
import android.view.LayoutInflater; | ||
import android.view.WindowManager; | ||
import android.widget.EditText; | ||
import android.view.inputmethod.EditorInfo; | ||
import android.graphics.Color; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
|
@@ -25,9 +27,16 @@ public class RNPromptFragment extends DialogFragment implements DialogInterface. | |
/* package */ static final String ARG_STYLE = "style"; | ||
/* package */ static final String ARG_DEFAULT_VALUE = "defaultValue"; | ||
/* package */ static final String ARG_PLACEHOLDER = "placeholder"; | ||
/* package */ static final String ARG_PLACEHOLDER_COLOR = "placeholderColor"; | ||
/* package */ static final String ARG_DISABLE_FULL_SCREEN_UI = "disableFullscreenUI"; | ||
/* package */ static final String ARG_HIGHLIGHT_COLOR = "highlightColor"; | ||
/* package */ static final String ARG_COLOR = "color"; | ||
/* package */ static final String ARG_BUTTON_COLOR = "buttonColor"; | ||
|
||
private EditText mInputText; | ||
|
||
private String mButtonColor; | ||
|
||
public enum PromptTypes { | ||
TYPE_DEFAULT("default"), | ||
PLAIN_TEXT("plain-text"), | ||
|
@@ -95,6 +104,12 @@ public Dialog createDialog(Context activityContext, Bundle arguments) { | |
builder.setItems(arguments.getCharSequenceArray(ARG_ITEMS), this); | ||
} | ||
|
||
if (arguments.containsKey(ARG_BUTTON_COLOR)) { | ||
mButtonColor = arguments.getString(ARG_BUTTON_COLOR); | ||
} else { | ||
mButtonColor = ""; | ||
} | ||
|
||
AlertDialog alertDialog = builder.create(); | ||
|
||
// input style | ||
|
@@ -104,10 +119,15 @@ public Dialog createDialog(Context activityContext, Bundle arguments) { | |
case "shimo": | ||
input = (EditText) inflater.inflate(R.layout.edit_text, null); | ||
break; | ||
case "cust": | ||
input = (EditText) inflater.inflate(R.layout.cust_edit_text, null); | ||
break; | ||
default: | ||
input = new EditText(activityContext); | ||
} | ||
|
||
|
||
|
||
// input type | ||
int type = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; | ||
if (arguments.containsKey(ARG_TYPE)) { | ||
|
@@ -134,6 +154,21 @@ public Dialog createDialog(Context activityContext, Bundle arguments) { | |
} | ||
input.setInputType(type); | ||
|
||
if (arguments.containsKey(ARG_HIGHLIGHT_COLOR)) { | ||
String highlightColor = arguments.getString(ARG_HIGHLIGHT_COLOR); | ||
if (highlightColor != null) { | ||
input.setHighlightColor(Color.parseColor(highlightColor)); | ||
} | ||
} | ||
|
||
if (arguments.containsKey(ARG_DISABLE_FULL_SCREEN_UI)) { | ||
boolean disableFullscreenUI = arguments.getBoolean(ARG_DISABLE_FULL_SCREEN_UI); | ||
if (disableFullscreenUI) { | ||
int imeOptions = input.getImeOptions(); | ||
input.setImeOptions(imeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI); | ||
} | ||
} | ||
|
||
if (arguments.containsKey(ARG_DEFAULT_VALUE)) { | ||
String defaultValue = arguments.getString(ARG_DEFAULT_VALUE); | ||
if (defaultValue != null) { | ||
|
@@ -143,11 +178,27 @@ public Dialog createDialog(Context activityContext, Bundle arguments) { | |
} | ||
} | ||
|
||
|
||
if (arguments.containsKey(ARG_COLOR)) { | ||
String color = arguments.getString(ARG_COLOR); | ||
if (color != null) { | ||
input.setTextColor(Color.parseColor(color)); | ||
} | ||
} | ||
|
||
if (arguments.containsKey(ARG_PLACEHOLDER)) { | ||
input.setHint(arguments.getString(ARG_PLACEHOLDER)); | ||
if (arguments.containsKey(ARG_PLACEHOLDER_COLOR)) { | ||
String placeholderColor = arguments.getString(ARG_PLACEHOLDER_COLOR); | ||
if (placeholderColor != null) { | ||
input.setHintTextColor(Color.parseColor(arguments.getString(ARG_PLACEHOLDER_COLOR))); | ||
} | ||
} | ||
} | ||
alertDialog.setView(input, 50, 15, 50, 0); | ||
|
||
// input.setLinkTextColor(Color.parseColor("green")); | ||
|
||
mInputText = input; | ||
return alertDialog; | ||
} | ||
|
@@ -159,6 +210,17 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { | |
return dialog; | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
super.onStart(); | ||
|
||
if (!mButtonColor.isEmpty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just tested this and it crashes as In JS There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh shoot i forgot to test for null. Thanks so much on this right away. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed thanks @jeanregisser! |
||
AlertDialog d = (AlertDialog) getDialog(); | ||
d.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.parseColor(mButtonColor)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you now use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
d.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.parseColor(mButtonColor)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
if (mListener != null) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not put code after to line 113?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to. I actually tried to put it on line 91 - https://github.com/Noitidart/react-native-prompt-android/blob/dd428a864880209114ff9708f76e21e9d1937aa5/android/src/main/java/im/shimo/react/prompt/RNPromptFragment.java#L91 - where we initially work with postive button. However
d.getButton
returns null until after dialog shows. :(This person here also encountered same issue - https://tassioauad.com/2016/06/02/dialogfragmentalertdialog-dismiss-automatically-on-click-button/
He says:
I also tried to ask on Stackoverflow, and other people have the same issue:
https://stackoverflow.com/questions/27520967/how-to-change-the-colour-of-positive-and-negative-button-in-custom-alert-dialog/27521470#comment85378535_27521470
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greedbell @wsong910 would you rather i make the change before accpeting PR? or would you like to find null cases and work around it?