Compare commits

..

No commits in common. "master" and "fix/ValidFragment" have entirely different histories.

12 changed files with 115 additions and 105 deletions

View File

@ -1 +1,2 @@
node_modules/
Example/

View File

@ -49,7 +49,6 @@ prompt(
type | Text input type: `'numeric', 'secure-text', 'phone-pad', 'email-address'` | String | 'default'
cancelable | | Boolean |
defaultValue | Default input value | String | ''
keyboardType | The keyboard type of first text field(if exists). One of `'default'`, `'email-address'`, `'numeric'`, `'phone-pad'`, `'ascii-capable'`, `'numbers-and-punctuation'`, `'url'`, `'number-pad'`, `'name-phone-pad'`, `'decimal-pad'`, `'twitter'` or `'web-search'`. | String | 'default'
placeholder | | String | ''

View File

@ -1,19 +1,24 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
apply plugin: 'com.android.library'
def DEFAULT_COMPILE_SDK_VERSION = 27
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 27
android {
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : DEFAULT_MIN_SDK_VERSION
targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.1"
versionName "1.0"
}
lintOptions {
abortOnError false
@ -30,8 +35,7 @@ repositories {
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.facebook.react:react-native:+'
implementation fileTree( dir: "libs", includes: ['*.jar'] )
compile "com.android.support:appcompat-v7:23.0.1"
compile 'com.facebook.react:react-native:+'
compile fileTree( dir: "libs", includes: ['*.jar'] )
}

View File

@ -5,13 +5,12 @@ import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.WindowManager;
import android.widget.EditText;
import androidx.appcompat.app.AlertDialog;
import javax.annotation.Nullable;
public class RNPromptFragment extends DialogFragment implements DialogInterface.OnClickListener {
@ -156,9 +155,7 @@ public class RNPromptFragment extends DialogFragment implements DialogInterface.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = this.createDialog(getActivity(), getArguments());
if (mInputText.requestFocus()) {
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
return dialog;
}

View File

@ -183,7 +183,7 @@ public class RNPromptModule extends ReactContextBaseJavaModule implements Lifecy
PromptFragmentListener actionListener =
actionCallback != null ? new PromptFragmentListener(actionCallback) : null;
final RNPromptFragment promptFragment = new RNPromptFragment();
final RNPromptFragment promptFragment = new RNPromptFragment(actionListener, arguments);
promptFragment.setListener(actionListener);
promptFragment.setArguments(arguments);

View File

@ -4,5 +4,5 @@
android:layout_height="match_parent"
android:textCursorDrawable="@drawable/edit_text_cursor"
style="@style/ShimoEditTextStyle"
android:imeOptions="actionDone"
android:theme="@style/ShimoEditTextStyle"/>
android:theme="@style/ShimoEditTextStyle">
</EditText>

View File

@ -4,8 +4,7 @@
<item name="colorAccent">@color/prompt_color</item>
</style>
<style name="ShimoEditTextStyle">
<item name="android:textColor">@color/prompt_color</item>
<style name="ShimoEditTextStyle" parent="Widget.AppCompat.EditText">
<item name="colorControlNormal">@color/prompt_color</item>
<item name="colorControlActivated">@color/prompt_color</item>
<item name="colorControlHighlight">@color/prompt_color</item>

View File

@ -3,26 +3,88 @@ import {
} from 'react-native';
const PromptAndroid = NativeModules.PromptAndroid;
export default function prompt(title, message, callbackOrButtons, options) {
const defaultButtons = [
{
text: 'Cancel',
},
{
text: 'OK',
onPress: callbackOrButtons
}
];
export type PromptType = $Enum<{
/**
* Default alert with no inputs
*/
'default': string,
/**
* Plain text input alert
*/
'plain-text': string,
/**
* Secure text input alert
*/
'secure-text': string,
/**
* Numeric input alert
*/
'numeric': string,
/**
* Email address input alert
*/
'email-address': string,
/**
* Phone pad input alert
*/
'phone-pad': string,
}>;
let buttons = typeof callbackOrButtons === 'function'
? defaultButtons
: callbackOrButtons;
export type PromptStyle = $Enum<{
/**
* Default alert dialog style
*/
'default': string,
/**
* Shimo alert dialog style
*/
'shimo': string,
}>;
type Options = {
cancelable?: ?boolean;
type?: ?PromptType;
defaultValue?: ?String;
placeholder?: ?String;
style?: ?PromptStyle;
};
/**
* Array or buttons
* @typedef {Array} ButtonsArray
* @property {string=} text Button label
* @property {Function=} onPress Callback function when button pressed
*/
type ButtonsArray = Array<{
/**
* Button label
*/
text?: string,
/**
* Callback function when button pressed
*/
onPress?: ?Function,
}>;
export default function prompt(
title: ?string,
message?: ?string,
callbackOrButtons?: ?((text: string) => void) | ButtonsArray,
options?: Options
): void {
let buttons = callbackOrButtons;
let config = {
title: title || '',
message: message || '',
};
if (typeof callbackOrButtons === 'function') {
buttons.push({
text: 'OK',
onPress: callbackOrButtons
});
}
if (options) {
config = {
...config,
@ -35,7 +97,7 @@ export default function prompt(title, message, callbackOrButtons, options) {
}
// At most three buttons (neutral, negative, positive). Ignore rest.
// The text 'OK' should be probably localized. iOS Alert does that in native.
const validButtons = buttons ? buttons.slice(0, 3) : [{text: 'OK'}];
const validButtons: Buttons = buttons ? buttons.slice(0, 3) : [{text: 'OK'}];
const buttonPositive = validButtons.pop();
const buttonNegative = validButtons.pop();
const buttonNeutral = validButtons.pop();

59
index.d.ts vendored
View File

@ -1,59 +0,0 @@
// Type definitions for react-native-prompt-android 0.3.1
// Project: https://github.com/shimohq/react-native-prompt-android
// Definitions by: Krystof Celba <https://github.com/krystofcelba>
// TypeScript Version: 2.6.1
type PromptButton = {
text?: string;
onPress?: (message: string) => void;
/** @platform ios */
style?: 'default' | 'cancel' | 'destructive';
};
type PromptType = 'default' | 'plain-text' | 'secure-text';
type PromptTypeIOS = 'login-password';
type PromptTypeAndroid = 'numeric' | 'email-address' | 'phone-pad';
type PromptStyleAndroid = 'default' | 'shimo';
export interface PromptOptions {
/**
* * Cross platform:
*
* - `'default'`
* - `'plain-text'`
* - `'secure-text'`
*
* * iOS only:
*
* - `'login-password'`
*
* * Android only:
*
* - `'numeric'`
* - `'email-address'`
* - `'phone-pad'`
*/
type?: PromptType | PromptTypeIOS | PromptTypeAndroid;
defaultValue?: string;
/** @platform android */
placeholder?: string;
/** @platform android */
cancelable?: boolean;
/** @platform android */
style?: PromptStyleAndroid;
}
declare function prompt(
title?: string,
message?: string,
callbackOrButtons?: ((value: string) => void) | Array<PromptButton>,
options?: PromptOptions,
): void;
export default prompt;

12
index.ios.js Normal file
View File

@ -0,0 +1,12 @@
import {
AlertIOS
} from 'react-native';
export default function prompt(
title: ?string,
message?: ?string,
callbackOrButtons?: ?((text: string) => void) | Object,
options?: Object
): void {
AlertIOS.prompt(title, message, callbackOrButtons, options.type, options.defaultValue);
};

View File

@ -1,5 +0,0 @@
import { Alert } from 'react-native';
export default function prompt(title, message, callbackOrButtons, options) {
Alert.prompt(title, message, callbackOrButtons, options.type, options.defaultValue, options.keyboardType);
}

View File

@ -1,6 +1,6 @@
{
"name": "react-native-prompt-android",
"version": "1.0.0",
"version": "0.3.0",
"description": "Polyfill for Alert.prompt on Android",
"repository": {
"type": "git",