Code Monkey home page Code Monkey logo

react-native-prompt's Introduction

react-native-prompt

A cross-platform prompt component for React Native.

Installation

$ npm install react-native-prompt --save

Demo

iOS Android

Basic Usage

import Prompt from 'react-native-prompt';

// Inside render()
<Prompt
    title="Say something"
    placeholder="Start typing"
    defaultValue="Hello"
    visible={ this.state.promptVisible }
    onCancel={ () => this.setState({
      promptVisible: false,
      message: "You cancelled"
    }) }
    onSubmit={ (value) => this.setState({
      promptVisible: false,
      message: `You said "${value}"`
    }) }/>

Please refer to the full working example here.

API

Props:

  • visible (boolean) -- When true, the prompt is displayed, closes otherwise
  • title (string, required) -- The title text of the prompt
  • placeholder (string) -- The placeholder text of the prompt
  • defaultValue (string) -- The default value of the prompt
  • onCancel (function, required) -- Function that is called when user cancels prompt
  • onSubmit (function, required) -- Function that is called with user's value when they submit
  • submitText (string) -- The string that is displayed on the submit button (defaults to "OK")
  • cancelText (string) -- The string that is displayed on the cancel button (defaults to "Cancel")
  • onChangeText (function) -- Function that is called with user input when it changes.
  • textInputProps (Object) -- Additional props on the input element

Testing

Install dev modules:

npm install

Run tests

npm test

Changelog

1.0.0

0.18.6

  • Adds textInputProps to allow additional props to be passed to the input element. Thanks @yueshuaijie!

0.18.5

react-native-prompt's People

Contributors

jaysoo avatar sibelius avatar stevehollaar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-prompt's Issues

setState problem!!!!

When I try to modify the state appear this worning:
screen shot 2017-12-06 at 09 04 28

this.setState({display: aggiungi})

PLEASE HELP!

React Native setState Issue and Warning

First:

Is a prompt unmounted when "visible" parameter is set to false?

if for sure NO

Ignore this issue and close it

If so or maybe

when you setState for the "visible" parameter ("promptVisible") it will cause a:
Warning: Can only update a mounted or mounting component
This setState Warning will happen after opened "promptVisible" to true and you have closed "promptVisible" to false

Example Code:

<Prompt
     title="Enter Amount"
     placeholder=""
     /*defaultValue={this.state.amount}*/
     visible={ this.state.promptVisible } //this is where the warning will happen
     onCancel={ () => this.closePrompt() } //this method contains, console.warn() and this.setState
     onSubmit={
            (value) => this.submitAmount(value) //this method contains, console.warn and this.setState
     } />

Note: submitAmount method setState for state.amount and state.promptVisible

It will check this.state.promptVisible

or check for a change in value

when the prompt is unmounted!

causing the warning.

After major testing and checking all of my other components for setState and state for unmounted and mounted component I drew the conclusion to this react-native-prompts as it's the only component not displayed when "visible" is false.

propTypes

It's not working, propType is a issue.

keyboardtype

do you have keyboardtype?
numeric, email, etc

[Feature] Prompt for confirmation

Great component! I just have one suggestion: Would it be possible to add the ability to show just a confirmation prompt (Ok/Cancel or Yes/No) using this component? It'd be handy, because I'd be able to keep the same props and styling by using this component to ask Yes/No questions without text input.

If this is out of scope in your opinion, please close.

Class version?

Is there (or could there be) a class-based version of this that is called OUTSIDE of render()? Such as how Alert works?

react-native 0.49.3 Compatibility Issue

It looks like a change broke something in Prompt.js

prompt js

I noticed that if we change the PropTypes import statement to the following, then the error goes away:

import PropTypes from 'prop-types';

TypeError: nodeHandle.getHostNode is not a function

I receive this error but everything works great, I guess is something with focus.

/node_modules/react-native/Libraries/Renderer/src/renderers/native/ReactNativeStack.js:44
return nodeHandle.getHostNode();
^
TypeError: nodeHandle.getHostNode is not a function
at Object.findNodeHandle (/home/julioe/react-native/fotoapp/node_modules/react-native/Libraries/Renderer/src/renderers/native/ReactNativeStack.js:44:19)
at Component.focus (/home/julioe/react-native/fotoapp/node_modules/react-native/Libraries/Renderer/src/renderers/native/NativeMethodsMixin.js:145:43)
at Component. (/home/julioe/react-native/fotoapp/node_modules/react-timer-mixin/TimerMixin.js:18:16)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
error Command failed with exit code 1.

Your component's very useful, thanks, greetings

Support custom props to the TextInput

There should be a way to customize more behaviour of text input, like keyboard type, whether password, max characters count, and so on.

We can introduce a new prop: textInputProps, which will apply to the text input.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.