From 4b3d255a2a0a2f60ae1fcc67876036ef4e58659c Mon Sep 17 00:00:00 2001 From: isaaclem Date: Sun, 3 Mar 2019 11:16:13 +0800 Subject: [PATCH] implemented isTransparent props to override modal transparency, implemented textInputProps to support all base textinput props --- README.md | 62 +++++++------- src/Prompt.js | 229 ++++++++++++++++++++++++-------------------------- 2 files changed, 143 insertions(+), 148 deletions(-) diff --git a/README.md b/README.md index 876719c..91ca433 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ A cross-platform input prompt component for React Native. ```sh $ npm install --save react-native-input-prompt ``` -## Demo +## Demo | iOS | Android | | ---------------------- | ----------------------- | @@ -18,21 +18,23 @@ $ npm install --save react-native-input-prompt ```js - this.setState({ - text: "User Cancelled!", - visible: !this.state.visible - }) - } - onSubmit={text => - this.setState({ - text: "User submitted: " + text, - visible: !this.state.visible - }) - } + visible={this.state.visible} + title="Say Something" + placeholder="Type Something" + onCancel={() => + this.setState({ + text: 'User Cancelled!', + visible: !this.state.visible + }) + } + onSubmit={text => + this.setState({ + text: 'User submitted: ' + text, + visible: !this.state.visible + }) + } + textInputProps={{ autoCapitalize: 'none', autoCorrect: false }} + isTransparent={false} /> ``` @@ -40,19 +42,21 @@ $ npm install --save react-native-input-prompt Props: -* `title` (string, required): The title to be displayed on the prompt. -* `visible` (boolean, required): When `true`, the prompt is displayed, closes otherwise. -* `placeholder` (string, required): The placeholder text of the prompt. -* `cancelText` (string): The string that is displayed on the cancel button (defaults to "Cancel"). -* `submitText` (string): The string that is displayed on the submit button (defaults to "Submit"). -* `cancelButtonStyle` (object): To change the style of "Cancel button". -* `submitButtonStyle` (object): To change the style of "Submit button". -* `cancelButtonTextStyle`(object): To change the style of text displayed inside "Cancel button". -* `submitButtonTextStyle` (object): To change the style of text displayed inside "Submit button". -* `titleStyle` (object): To change the style of title text. -* `onChangeText` (function): Function that is called with user input when it changes. -* `onSubmit` (function, required): Function that is called when user presses on "Submit button". -* `onCancel` (function, required): Function that is called when user presses on "Cancel button". +- `title` (string, required): The title to be displayed on the prompt. +- `visible` (boolean, required): When `true`, the prompt is displayed, closes otherwise. +- `placeholder` (string, required): The placeholder text of the prompt. +- `cancelText` (string): The string that is displayed on the cancel button (defaults to "Cancel"). +- `submitText` (string): The string that is displayed on the submit button (defaults to "Submit"). +- `cancelButtonStyle` (object): To change the style of "Cancel button". +- `submitButtonStyle` (object): To change the style of "Submit button". +- `cancelButtonTextStyle`(object): To change the style of text displayed inside "Cancel button". +- `submitButtonTextStyle` (object): To change the style of text displayed inside "Submit button". +- `titleStyle` (object): To change the style of title text. +- `onChangeText` (function): Function that is called with user input when it changes. +- `onSubmit` (function, required): Function that is called when user presses on "Submit button". +- `onCancel` (function, required): Function that is called when user presses on "Cancel button". +- `textInputProps` (object): To map override TextInput props +- `isTransparent` (bool): To make prompt input background not transparent (defaults to true) ## Contributing diff --git a/src/Prompt.js b/src/Prompt.js index 1f9353d..124fb96 100644 --- a/src/Prompt.js +++ b/src/Prompt.js @@ -1,125 +1,116 @@ -import React, { Component } from "react"; -import { - View, - Text, - Button, - TextInput, - Dimensions, - Modal, - TouchableOpacity -} from "react-native"; -import styles from "./styles"; -import PropTypes from "prop-types"; +import React, { Component } from 'react'; +import { View, Text, TextInput, Modal, TouchableOpacity } from 'react-native'; +import styles from './styles'; +import PropTypes from 'prop-types'; export default class Prompt extends Component { - static propTypes = { - title: PropTypes.string.isRequired, - visible: PropTypes.bool.isRequired, - placeholder: PropTypes.string.isRequired, - cancelText: PropTypes.string, - submitText: PropTypes.string, - cancelButtonStyle: PropTypes.object, - submitButtonStyle: PropTypes.object, - cancelButtonTextStyle: PropTypes.object, - submitButtonTextStyle: PropTypes.object, - titleStyle: PropTypes.object, - onChangeText: PropTypes.func, - onSubmit: PropTypes.func.isRequired, - onCancel: PropTypes.func.isRequired - }; + static propTypes = { + title: PropTypes.string.isRequired, + visible: PropTypes.bool.isRequired, + placeholder: PropTypes.string.isRequired, + cancelText: PropTypes.string, + submitText: PropTypes.string, + isTransparent: PropTypes.bool, + cancelButtonStyle: PropTypes.object, + submitButtonStyle: PropTypes.object, + cancelButtonTextStyle: PropTypes.object, + submitButtonTextStyle: PropTypes.object, + titleStyle: PropTypes.object, + onChangeText: PropTypes.func, + onSubmit: PropTypes.func.isRequired, + onCancel: PropTypes.func.isRequired, + textInputProps: PropTypes.object + }; - static defaultProps = { - title: "Title", - visible: false, - placeholder: "Placeholder", - cancelText: "Cancel", - submitText: "Submit", - cancelButtonStyle: {}, - cancelButtonTextStyle: {}, - submitButtonStyle: {}, - submitButtonTextStyle: {}, - titleStyle: {}, - onChangeText: () => {}, - onSubmit: () => {}, - onCancel: () => {} - }; - constructor() { - super(); - this.state = { - value: "" - }; - } - _onChangeText(value) { - this.setState({ - value: value - }); - this.props.onChangeText(value); - } + static defaultProps = { + title: 'Title', + visible: false, + placeholder: 'Placeholder', + cancelText: 'Cancel', + submitText: 'Submit', + textInputProps: {}, + cancelButtonStyle: {}, + cancelButtonTextStyle: {}, + submitButtonStyle: {}, + submitButtonTextStyle: {}, + titleStyle: {}, + isTransparent: true, + onChangeText: () => {}, + onSubmit: () => {}, + onCancel: () => {} + }; - _onSubmit() { - this.props.onSubmit(this.state.value); - this.setState({ value: "" }); - } + state = { value: '' }; - _onCancel() { - this.props.onCancel(); - this.setState({ value: "" }); - } - render() { - return ( - - - - - {this.props.title} - - - - - - - {this.props.cancelText} - - - - - - {this.props.submitText} - - - - - - - - ); - } + _onChangeText = value => { + this.setState({ value }); + this.props.onChangeText(value); + }; + + _onSubmit = () => { + this.props.onSubmit(this.state.value); + this.setState({ value: '' }); + }; + + _onCancel = () => { + this.props.onCancel(); + this.setState({ value: '' }); + }; + render() { + return ( + + + + + {this.props.title} + + + + + + + {this.props.cancelText} + + + + + + {this.props.submitText} + + + + + + + + ); + } }