-
Notifications
You must be signed in to change notification settings - Fork 78
add style, to readme. and also added the properties i just added of h… #31
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
base: master
Are you sure you want to change the base?
Changes from all 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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
package im.shimo.react.prompt; | ||
|
||
import android.support.v7.app.AlertDialog; | ||
import android.os.Bundle; | ||
import android.content.Context; | ||
import android.app.Dialog; | ||
import android.app.DialogFragment; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AlertDialog; | ||
import android.view.inputmethod.EditorInfo; | ||
import android.widget.EditText; | ||
import android.view.inputmethod.InputMethodManager; | ||
import android.text.InputType; | ||
import android.view.KeyEvent; | ||
import android.view.LayoutInflater; | ||
import android.view.WindowManager; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
|
@@ -25,9 +28,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 Integer mButtonColor; | ||
|
||
public enum PromptTypes { | ||
TYPE_DEFAULT("default"), | ||
PLAIN_TEXT("plain-text"), | ||
|
@@ -95,7 +105,11 @@ public Dialog createDialog(Context activityContext, Bundle arguments) { | |
builder.setItems(arguments.getCharSequenceArray(ARG_ITEMS), this); | ||
} | ||
|
||
AlertDialog alertDialog = builder.create(); | ||
if (arguments.containsKey(ARG_BUTTON_COLOR)) { | ||
mButtonColor = arguments.getInt(ARG_BUTTON_COLOR); | ||
} | ||
|
||
final AlertDialog alertDialog = builder.create(); | ||
|
||
// input style | ||
LayoutInflater inflater = LayoutInflater.from(activityContext); | ||
|
@@ -104,10 +118,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 +153,18 @@ public Dialog createDialog(Context activityContext, Bundle arguments) { | |
} | ||
input.setInputType(type); | ||
|
||
if (arguments.containsKey(ARG_HIGHLIGHT_COLOR)) { | ||
input.setHighlightColor(arguments.getInt(ARG_HIGHLIGHT_COLOR)); | ||
} | ||
|
||
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,22 +174,62 @@ public Dialog createDialog(Context activityContext, Bundle arguments) { | |
} | ||
} | ||
|
||
|
||
if (arguments.containsKey(ARG_COLOR)) { | ||
input.setTextColor(arguments.getInt(ARG_COLOR)); | ||
} | ||
|
||
if (arguments.containsKey(ARG_PLACEHOLDER)) { | ||
input.setHint(arguments.getString(ARG_PLACEHOLDER)); | ||
if (arguments.containsKey(ARG_PLACEHOLDER_COLOR)) { | ||
input.setHintTextColor(arguments.getInt(ARG_PLACEHOLDER_COLOR)); | ||
} | ||
} | ||
alertDialog.setView(input, 50, 15, 50, 0); | ||
|
||
mInputText = input; | ||
|
||
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() | ||
{ | ||
@Override | ||
public void onShow(final DialogInterface dialog) | ||
{ | ||
input.requestFocus(); | ||
((InputMethodManager) alertDialog.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(input, 0); | ||
} | ||
}); | ||
|
||
|
||
input.setOnEditorActionListener(new TextView.OnEditorActionListener() { | ||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { | ||
if (actionId == EditorInfo.IME_ACTION_DONE) { | ||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick(); | ||
} | ||
return false; | ||
} | ||
}); | ||
|
||
return alertDialog; | ||
} | ||
|
||
@Override | ||
public Dialog onCreateDialog(Bundle savedInstanceState) { | ||
Dialog dialog = this.createDialog(getActivity(), getArguments()); | ||
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); | ||
return dialog; | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
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. why not put code after to line 113? 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 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 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: 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. @greedbell @wsong910 would you rather i make the change before accpeting PR? or would you like to find null cases and work around it? |
||
super.onStart(); | ||
|
||
if (mButtonColor != null) { | ||
AlertDialog d = (AlertDialog) getDialog(); | ||
d.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mButtonColor); | ||
d.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(mButtonColor); | ||
d.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(mButtonColor); | ||
} | ||
} | ||
|
||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
if (mListener != null) { | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<EditText xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:theme="@style/CustEditTextStyle"/> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="custUnderlineAndCursorAndHandleColor">#F34336</color> | ||
<color name="prompt_color">#41464b</color> | ||
</resources> |
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.
maybe below code behave better:
InputMethodManager imm = (InputMethodManager) alertDialog.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
input.requestFocus();
imm.showSoftInput(view, 0);
}
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.
Is there chance that
imm
is null? If it is, is there a way to wait for it to not be null? Because we always want to show keyboard.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.
@wsong910 - are you waiting on me to make this change before accepting this PR? Or are you researching when imm can be null so we can force get imm in that situation to ensure keyboard shows?