Skip to content
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

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
97f27bf
add style, to readme. and also added the properties i just added of h…
Noitidart Feb 22, 2018
5d68e7f
Update RNPromptFragment.java
Noitidart Feb 22, 2018
4d870b7
Update RNPromptModule.java
Noitidart Feb 22, 2018
9b16846
RNPromptFragment.java updated for buttonColor and cust style name
Noitidart Mar 9, 2018
f9ab93b
RNPromptModule.java update for buttonColor
Noitidart Mar 9, 2018
cddf659
index.android.js for buttonColor
Noitidart Mar 9, 2018
8d4b760
Delete prompt_color.xml
Noitidart Mar 9, 2018
97f5166
Create colors.xml
Noitidart Mar 9, 2018
51a4b24
Update style.xml
Noitidart Mar 9, 2018
1dd31e5
Create cust_edit_text.xml
Noitidart Mar 9, 2018
7ee8ae5
how to use cust and also added buttonColor
Noitidart Mar 9, 2018
1293f23
Update index.android.js
Noitidart Mar 9, 2018
0a6c21b
Update index.android.js
Noitidart Mar 9, 2018
9b13e6c
Update RNPromptFragment.java
Noitidart Mar 9, 2018
8a3b945
added manual linking instructions to readme
Noitidart Mar 9, 2018
37f3e0c
Update README.md
Noitidart Mar 9, 2018
aa95548
Update README.md
Noitidart Mar 9, 2018
e8092ab
Update README.md
Noitidart Mar 9, 2018
a08841b
Fixes https://github.com/shimohq/react-native-prompt-android/issues/24
Noitidart Mar 9, 2018
dd428a8
Fixes https://github.com/shimohq/react-native-prompt-android/issues/26
Noitidart Mar 10, 2018
1aac796
fix typo disableFullscreenUI
Noitidart Mar 13, 2018
37ceddd
allow null buttonColor
Noitidart Mar 13, 2018
a3c1199
add screenshot with android options
Noitidart Mar 13, 2018
a1ab4db
add screenshot to readme
Noitidart Mar 13, 2018
3e2e89f
readme
Noitidart Mar 13, 2018
47c5cba
support the full color format (named, rgba, etc) thanks @jeanregisser!
Noitidart Mar 13, 2018
dcc7a0b
remove Color.parseColor as we do processColor now
Noitidart Mar 13, 2018
515e307
swithced to Integer type for colors - tested and it compiles
Noitidart Mar 13, 2018
e724872
better readme
Noitidart Mar 13, 2018
88ea270
added android options of onDismiss and onAny - closes https://github.…
Noitidart Mar 23, 2018
2f428e6
fixed readme typo highlightColor AARRGGBB to rgba
Noitidart Mar 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@ prompt(

## Props

name | description | type | default
:-------------------- |:------------------------------------------- | --------:|:------------------
type | Text input type: `'numeric', 'secure-text', 'phone-pad', 'email-address'` | String | 'default'
cancelable | | Boolean |
defaultValue | Default input value | String | ''
placeholder | | String | ''


| name | description | type | default |
|---------------------|---------------------------------------------------------------------------|---------|--------------------------------------|
| type | Text input type: `'numeric', 'secure-text', 'phone-pad', 'email-address'` | String | 'default' |
| cancelable | | Boolean | true |
| defaultValue | Default input value | String | |
| placeholder | | String | |
| style | `'default', 'shimo'` | String | 'default' |
| disableFullScreenUI | When in landscape mode, don't use fullscreen | Boolean | false |
| highlightColor | Color of text selection | String | colorString or #RRGGBB or ##AARRGGBB |
| placeholderColor | Color of the placeholder | String | colorString or#RRGGBB or ##AARRGGBB |
| color | Color of the text | String | colorString or#RRGGBB or ##AARRGGBB |

Valid `colorString`: `'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuchsia', 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', and 'teal'`

![Android Screen Shoot](./Example/android.png)

Expand Down
62 changes: 62 additions & 0 deletions android/src/main/java/im/shimo/react/prompt/RNPromptFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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"),
Expand Down Expand Up @@ -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
Expand All @@ -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)) {
Expand All @@ -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) {
Expand All @@ -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;
}
Expand All @@ -159,6 +210,17 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
return dialog;
}

@Override
public void onStart() {

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?

Copy link
Author

@Noitidart Noitidart Mar 12, 2018

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:

You will need to set this in the onResume() method because getButton() will return null until after the dialog has been shown! This should cause your custom action method to only be called once, and the dialog won’t be dismissed by default.

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

Copy link
Author

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?

super.onStart();

if (!mButtonColor.isEmpty()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this and it crashes as mButtonColor is null when not specifying this prop or when passed an empty string.

In JS buttonColor: options.buttonColor || null will set buttonColor to null if not specified or if it's an empty string.

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you now use processColor on the JS side, you need to remove all Color.parseColor and just take the Int value from the arguments.

Copy link
Author

Choose a reason for hiding this comment

The 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) {
Expand Down
16 changes: 16 additions & 0 deletions android/src/main/java/im/shimo/react/prompt/RNPromptModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public class RNPromptModule extends ReactContextBaseJavaModule implements Lifecy
/* package */ static final String KEY_STYLE = "style";
/* package */ static final String KEY_DEFAULT_VALUE = "defaultValue";
/* package */ static final String KEY_PLACEHOLDER = "placeholder";
/* package */ static final String KEY_PLACEHOLDER_COLOR = "placeholderColor";
/* package */ static final String KEY_DISABLE_FULL_SCREEN_UI = "disableFullscreenUI";
/* package */ static final String KEY_HIGHLIGHT_COLOR = "highlightColor";
/* package */ static final String KEY_COLOR = "color";

/* package */ static final Map<String, Object> CONSTANTS = MapBuilder.<String, Object>of(
ACTION_BUTTON_CLICKED, ACTION_BUTTON_CLICKED,
Expand Down Expand Up @@ -127,6 +131,15 @@ public void promptWithArgs(ReadableMap options, final Callback callback) {
if (options.hasKey(KEY_CANCELABLE)) {
args.putBoolean(KEY_CANCELABLE, options.getBoolean(KEY_CANCELABLE));
}
if (options.hasKey(KEY_DISABLE_FULL_SCREEN_UI)) {
args.putBoolean(KEY_DISABLE_FULL_SCREEN_UI, options.getBoolean(KEY_DISABLE_FULL_SCREEN_UI));
}
if (options.hasKey(KEY_HIGHLIGHT_COLOR)) {
args.putString(KEY_HIGHLIGHT_COLOR, options.getString(KEY_HIGHLIGHT_COLOR));
}
if (options.hasKey(KEY_COLOR)) {
args.putString(KEY_COLOR, options.getString(KEY_COLOR));
}
if (options.hasKey(KEY_TYPE)) {
args.putString(KEY_TYPE, options.getString(KEY_TYPE));
}
Expand All @@ -139,6 +152,9 @@ public void promptWithArgs(ReadableMap options, final Callback callback) {
if (options.hasKey(KEY_PLACEHOLDER)) {
args.putString(KEY_PLACEHOLDER, options.getString(KEY_PLACEHOLDER));
}
if (options.hasKey(KEY_PLACEHOLDER_COLOR)) {
args.putString(KEY_PLACEHOLDER_COLOR, options.getString(KEY_PLACEHOLDER_COLOR));
}
fragmentManagerHelper.showNewAlert(mIsInForeground, args, callback);
}

Expand Down