A cross-platform prompt component for React Native.
$ npm install react-native-modal-prompt --save
Basic | Prompt showCount |
---|---|
import Prompt from 'react-native-modal-prompt';
<Prompt
visible={this.state.promptVisible}
title="title"
placeholder="please write something"
defaultValue="prompt"
showCount={true}
operation={[
{
text: 'Cancel',
color: '#000',
onPress: () => {
ToastAndroid.showWithGravity('if return false, the modal will not close', 1000, ToastAndroid.CENTER);
return false;
}},
{
text: 'Ok',
onPress: (value) =>
new Promise((resolve) => {
console.log(`the prompt value is ${value}`);
// ajax....
ToastAndroid.showWithGravity('ajax request sucess', 1000, ToastAndroid.CENTER);
setTimeout(resolve, 2000);
}),
},
]}
/>
full examples here.
Props:
visible
(boolean) -- Control display or hidingtitle
(string, required) -- The title text of the promptplaceholder
(string) -- The placeholder text of the promptdefaultValue
(string) -- The default value of the promptoperation
(array, required) -- Multiple control buttons can be customized, and the 'onPress' function is callback of the button after click that can await something like ajax, if the return value is false, the prompt will not closemaxLength
(string) -- The maxLength can be input of the promptshowCount
(boolean) -- If this is true, the prompt will display word length of input