Compare commits
7 Commits
feature/up
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed168d66fe | ||
|
|
2073b07f64 | ||
|
|
957e99cd4e | ||
|
|
7eae9e24cd | ||
|
|
12ec414163 | ||
|
|
b9b9b93acf | ||
|
|
83d23015c9 |
@ -1,2 +1 @@
|
||||
node_modules/
|
||||
Example/
|
||||
|
||||
@ -30,7 +30,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "com.android.support:appcompat-v7:27.1.1"
|
||||
implementation 'androidx.appcompat:appcompat:1.0.0'
|
||||
implementation 'com.facebook.react:react-native:+'
|
||||
implementation fileTree( dir: "libs", includes: ['*.jar'] )
|
||||
}
|
||||
|
||||
@ -5,12 +5,13 @@ 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 {
|
||||
|
||||
@ -4,7 +4,8 @@
|
||||
<item name="colorAccent">@color/prompt_color</item>
|
||||
</style>
|
||||
|
||||
<style name="ShimoEditTextStyle" parent="Widget.AppCompat.EditText">
|
||||
<style name="ShimoEditTextStyle">
|
||||
<item name="android:textColor">@color/prompt_color</item>
|
||||
<item name="colorControlNormal">@color/prompt_color</item>
|
||||
<item name="colorControlActivated">@color/prompt_color</item>
|
||||
<item name="colorControlHighlight">@color/prompt_color</item>
|
||||
|
||||
@ -3,75 +3,7 @@ import {
|
||||
} from 'react-native';
|
||||
const PromptAndroid = NativeModules.PromptAndroid;
|
||||
|
||||
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,
|
||||
}>;
|
||||
|
||||
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 {
|
||||
export default function prompt(title, message, callbackOrButtons, options) {
|
||||
const defaultButtons = [
|
||||
{
|
||||
text: 'Cancel',
|
||||
@ -103,7 +35,7 @@ export default function prompt(
|
||||
}
|
||||
// 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 ? buttons.slice(0, 3) : [{text: 'OK'}];
|
||||
const validButtons = buttons ? buttons.slice(0, 3) : [{text: 'OK'}];
|
||||
const buttonPositive = validButtons.pop();
|
||||
const buttonNegative = validButtons.pop();
|
||||
const buttonNeutral = validButtons.pop();
|
||||
|
||||
12
index.ios.js
12
index.ios.js
@ -1,12 +0,0 @@
|
||||
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, options.keyboardType);
|
||||
};
|
||||
5
index.js
Normal file
5
index.js
Normal file
@ -0,0 +1,5 @@
|
||||
import { Alert } from 'react-native';
|
||||
|
||||
export default function prompt(title, message, callbackOrButtons, options) {
|
||||
Alert.prompt(title, message, callbackOrButtons, options.type, options.defaultValue, options.keyboardType);
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-prompt-android",
|
||||
"version": "0.3.5",
|
||||
"version": "1.0.0",
|
||||
"description": "Polyfill for Alert.prompt on Android",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user