ContainerEditor.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.value = viewNodeProps[key];
  27. break;
  28. case DataTypes.Types.Text:
  29. editorProps.value = 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. <View style={styles.col}>
  49. {this.createHandler(structure, nodeProps, 'width', (val) => this.update('width', val), 'W')}
  50. </View>
  51. <View style={styles.col}>
  52. {this.createHandler(structure, nodeProps, 'height', (val) => this.update('height', val), 'H')}
  53. </View>
  54. </View>
  55. <View style={styles.row}>
  56. <View style={styles.col}>
  57. {this.createHandler(structure, nodeProps, 'paddingTop', (val) => this.update('paddingTop', val), 'Top')}
  58. </View>
  59. <View style={styles.col}>
  60. {this.createHandler(structure, nodeProps, 'paddingBottom', (val) => this.update('paddingBottom', val), 'Bottom')}
  61. </View>
  62. </View>
  63. <View style={styles.row}>
  64. <View style={styles.col}>
  65. {this.createHandler(structure, nodeProps, 'marginLeft', (val) => this.update('marginLeft', val), 'Left')}
  66. </View>
  67. <View style={styles.col}>
  68. {this.createHandler(structure, nodeProps, 'marginRight', (val) => this.update('marginRight', val), 'Right')}
  69. </View>
  70. </View>
  71. </View>
  72. );
  73. }
  74. }
  75. const styles = StyleSheet.create({
  76. container:{
  77. padding:15,
  78. flexDirection: 'column',
  79. justifyContent: 'space-around',
  80. borderBottomColor: '#B4B4B4',
  81. borderBottomWidth: 1
  82. },
  83. col: {
  84. padding: 4,
  85. paddingTop: 0,
  86. width: '50%'
  87. },
  88. row: {
  89. flexDirection: 'row',
  90. justifyContent: 'space-around'
  91. },
  92. iconStyle: {
  93. fontSize: 18,
  94. opacity: 0.6,
  95. cursor: 'pointer'
  96. }
  97. })