ContainerEditor.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React, { useState } from 'react';
  2. import {View , Text, TextInput, Button,StyleSheet} from 'react-native';
  3. import { Icon } from 'react-native-elements'
  4. import TypeHandler from './TypeHandler.js';
  5. import Library from 'trapilib/dist/lib';
  6. let { DataTypes } = Library;
  7. export default class ContainerEditor extends React.Component {
  8. constructor(props) {
  9. super(props);
  10. }
  11. createHandler(Structure, viewNodeProps, key, onChange, title) {
  12. let Editor = TypeHandler(Structure);
  13. let editorProps = {
  14. title: title || key,
  15. onChange: (value) => {
  16. onChange && onChange(value, key)
  17. }
  18. };
  19. switch(Structure.type){
  20. case DataTypes.Types.Array:
  21. editorProps.value = viewNodeProps[key];
  22. break;
  23. case DataTypes.Types.Integer:
  24. case DataTypes.Types.Real:
  25. case DataTypes.Types.Bool:
  26. editorProps.number = viewNodeProps[key];
  27. break;
  28. case DataTypes.Types.Text:
  29. editorProps.text = viewNodeProps[key];
  30. break;
  31. default:
  32. //Must create a generic Vuiew Component
  33. return (<View></View>)
  34. }
  35. return <Editor {...editorProps} key={key}/>
  36. }
  37. update(key, val) {
  38. this.props.onChange && this.props.onChange(key, val);
  39. }
  40. render() {
  41. let {
  42. structure,
  43. nodeProps
  44. } = this.props;
  45. return (
  46. <View style={styles.container}>
  47. <View style={styles.row}>
  48. {this.createHandler(structure, nodeProps, 'width', (val) => this.update('width', val), 'W')}
  49. {this.createHandler(structure, nodeProps, 'height', (val) => this.update('height', val), 'H')}
  50. </View>
  51. <View style={styles.row}>
  52. {this.createHandler(structure, nodeProps, 'paddingTop', (val) => this.update('paddingTop', val), 'Top')}
  53. {this.createHandler(structure, nodeProps, 'paddingBottom', (val) => this.update('paddingBottom', val), 'Bottom')}
  54. </View>
  55. <View style={styles.row}>
  56. {this.createHandler(structure, nodeProps, 'marginLeft', (val) => this.update('marginLeft', val), 'Left')}
  57. {this.createHandler(structure, nodeProps, 'marginRight', (val) => this.update('marginRight', val), 'Right')}
  58. </View>
  59. </View>
  60. );
  61. }
  62. }
  63. const styles = StyleSheet.create({
  64. container:{
  65. padding:15,
  66. flexDirection: 'column',
  67. justifyContent: 'space-around',
  68. borderBottomColor: '#B4B4B4',
  69. borderBottomWidth: 1
  70. },
  71. row: {
  72. flexDirection: 'row',
  73. justifyContent: 'space-around'
  74. },
  75. defaultInput: {
  76. marginTop:6,
  77. borderWidth:1,
  78. width:200
  79. },
  80. title: {
  81. },
  82. iconStyle: {
  83. fontSize: 18,
  84. opacity: 0.6,
  85. cursor: 'pointer'
  86. }
  87. })