Numbers.js 859 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React, { useState } from 'react';
  2. import {View , Text, TextInput, Button,StyleSheet} from 'react-native';
  3. import { Icon } from 'react-native-elements'
  4. export default function Numbers(props) {
  5. let [number , setNumber] = useState(props.number || '')
  6. let title = props.title || "Input";
  7. return(
  8. <View style={styles.container}>
  9. <Text style={styles.title}>{title}</Text>
  10. <TextInput style={styles.defaultInput}
  11. onChangeText={(number) => {
  12. try{
  13. number = parseInt(number);
  14. } catch(e) {
  15. return;
  16. }
  17. props.onChange && props.onChange(number);
  18. setNumber(number);
  19. }}
  20. keyboardType={'numeric'}
  21. value={number.toString()}/>
  22. </View>
  23. )
  24. }
  25. const styles = StyleSheet.create({
  26. container:{
  27. padding:10
  28. },
  29. defaultInput: {
  30. marginTop:6,
  31. borderWidth:1,
  32. width:100
  33. },
  34. title: {
  35. }
  36. })