-
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 25 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,19 @@ | ||
package im.shimo.react.prompt; | ||
|
||
import android.support.v7.app.AlertDialog; | ||
import android.os.Bundle; | ||
import android.graphics.Color; | ||
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 +29,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,7 +106,16 @@ 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.getString(ARG_BUTTON_COLOR); | ||
if (mButtonColor == null) { | ||
mButtonColor = ""; | ||
} | ||
} else { | ||
mButtonColor = ""; | ||
} | ||
|
||
final AlertDialog alertDialog = builder.create(); | ||
|
||
// input style | ||
LayoutInflater inflater = LayoutInflater.from(activityContext); | ||
|
@@ -104,10 +124,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 +159,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,22 +183,68 @@ 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); | ||
|
||
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); | ||
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. maybe below code behave better: 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. Is there chance that 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. @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? |
||
} | ||
}); | ||
|
||
|
||
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 && !mButtonColor.isEmpty()) { | ||
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)); | ||
d.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(Color.parseColor(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.
You could actually support the full color format (named, rgb, rgba, hsl, etc) available in React Native by processing the color passed to the components like this:
Then just don't call
Color.parseColor
in Java but just take the Int value.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.
Oh sweet! Is it possible to process color on native side? Like RCTConvert in ios?
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.
No,
RCTConvert
on iOS just transforms the int to a UIColor, so it can be conveniently used.But Android native views can directly deal with Int.
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.
Update to support full color format! Super awesome!! would be awesome to learn how to do this on native side too.