index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import React from 'react';
  2. import Module from '../../lib/Module';
  3. import {StyleSheet ,TextInput, View, Button , Text } from 'react-native';
  4. import Types from '../../lib/Types';
  5. const Inp = [
  6. {
  7. textContentType :"username",
  8. placeholder:"username"
  9. },
  10. {
  11. textContentType :"password",
  12. placeholder:"password"
  13. }]
  14. export default class FormComp extends Module {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. }
  19. this.submit = this.submit.bind(this)
  20. }
  21. submit(e){
  22. e.preventDefault()
  23. return this.state
  24. }
  25. display() {
  26. let {
  27. inputs, // number of inputs this must be Object
  28. inputsMargin,
  29. ButtonText,
  30. ButtonColor,
  31. backgroundColor,
  32. Formtitle
  33. } = this.props
  34. //Init
  35. if(!inputsMargin) inputsMargin = 7
  36. console.log("@@@@@")
  37. console.log(this.props)
  38. let Inputs = (inputs || []).map((item,indx) => {
  39. let state = {}
  40. return (<TextInput key={indx}
  41. style={[{height: 20, borderColor: 'gray', borderWidth: 1 , marginBottom:inputsMargin},StaticRules.text]}
  42. onChangeText={(text) => {
  43. state[indx] = text;
  44. this.setState(state)}}
  45. value={this.state.key}
  46. placeholder={item.placeholder}
  47. textContentType={item.textContentType}
  48. secureTextEntry={ item.textContentType === "password" ? true :false}
  49. />)
  50. })
  51. let fn = this.props.submit || this.submit
  52. return (
  53. <View style={[{backgroundColor:backgroundColor},StaticRules.container]}>
  54. {this.props.Formtitle ? (
  55. <Text>{this.props.Formtitle}</Text>
  56. ):(null)}
  57. {Inputs}
  58. <Button
  59. onPress = {(e) => fn(e)}
  60. title={this.props.ButtonText }
  61. color={this.props.ButtonColor}
  62. accessibilityLabel="Learn more about this purple button"
  63. />
  64. </View>)
  65. }
  66. }
  67. //Predefined Rules that the User cant change
  68. let StaticRules = StyleSheet.create({
  69. container:{
  70. padding:10
  71. },
  72. text:{
  73. fontSize:7
  74. }
  75. })
  76. FormComp.Inputs = {
  77. //inputsNum: new Types.Integer().require().default(2),
  78. /*inputs:[
  79. {
  80. textContentType :"username",
  81. placeholder:"username"
  82. },
  83. {
  84. textContentType :"password",
  85. placeholder:"password"
  86. },
  87. ],*/
  88. inputs:new Types.Array().require().default(Inp),
  89. ButtonText:new Types.Text().require().default('Submit'),
  90. ButtonColor: new Types.Text().require().color().default('rgba(3, 218, 198, 1)'),
  91. backgroundColor: new Types.Text().require().color().default('rgba(0, 140, 186, 1)'),
  92. Formtitle: new Types.Text().require()
  93. }
  94. /*
  95. inputs, // number of inputs this must be Object
  96. inputsMargin,
  97. ButtonText,
  98. ButtonColor,
  99. backgroundColor,
  100. Formtitle
  101. */