import React, { Component } from 'react'; import { Platform } from 'react-native'; import { AppRegistry, StyleSheet, Text, View, TouchableHighlight } from 'react-native'; import prompt from 'react-native-prompt-android'; export default class PromptAndroid extends Component { constructor() { super(...arguments); this.state = { password: '', age: '', phone: '', email: '', }; } _prompt = (params) => { console.log(params); if (Platform.OS === 'android') { prompt( params.title, params.description, [ { text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel' }, { text: 'OK', onPress: value => { this.setState({ [params.name]: value }); console.log(`OK Pressed, ${params.name}: ${value}`); } }, ], { type: params.type, cancelable: false, defaultValue: params.defaultValue, placeholder: 'placeholder', style: 'shimo' } ); } else { prompt( params.title, params.description, [ { text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel' }, { text: 'OK', onPress: value => { this.setState({ [params.name]: value }); console.log(`OK Pressed, ${params.name}: ${value}`); } }, ], { type: params.type, cancelable: false, defaultValue: params.defaultValue, placeholder: 'placeholder' } ); } }; render() { const password = { name: 'password', title: 'Enter password', description: 'Enter your password to claim your $1.5B in lottery winnings', type: 'secure-text', defaultValue: 'test', }; const age = { name: 'age', title: 'Enter age', description: 'Enter your age', type: 'numeric', defaultValue: '20', }; const phone = { name: 'phone', title: 'Enter phone', description: 'Enter your phone', type: 'phone-pad', defaultValue: '16051233223', }; const email = { name: 'email', title: 'Enter email', description: 'Enter your email', type: 'email-address', defaultValue: 'test@test.com', }; return ( this._prompt(password)} underlayColor="#ccc" > SET PASSWORD Your password {this.state.password} this._prompt(age)} underlayColor="#ccc" > SET AGE Your age {this.state.age} this._prompt(phone)} underlayColor="#ccc" > SET PHONE Your phone {this.state.phone} this._prompt(email)} underlayColor="#ccc" > SET EMAIL Your email {this.state.email} ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, buttonContainer: { marginBottom: 10, }, button: { borderRadius: 5, backgroundColor: '#aaa', paddingVertical: 5, paddingHorizontal: 10, height: 30 }, buttonContent: { alignItems: 'center', justifyContent: 'center' }, buttonText: { textAlign: 'center', color: '#eee', marginBottom: 5, }, title: { marginTop: 20, fontSize: 20, fontWeight: 'bold', color: '#333', textAlign: 'center' }, input: { paddingHorizontal: 5, marginBottom: 10 } }); AppRegistry.registerComponent('PromptAndroid', () => PromptAndroid);