ContainerEditor.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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>
  52. );
  53. }
  54. }
  55. const styles = StyleSheet.create({
  56. container:{
  57. padding:15,
  58. flexDirection: 'column',
  59. justifyContent: 'space-around',
  60. borderBottomColor: '#B4B4B4',
  61. borderBottomWidth: 1
  62. },
  63. row: {
  64. flexDirection: 'row',
  65. justifyContent: 'space-around'
  66. },
  67. defaultInput: {
  68. marginTop:6,
  69. borderWidth:1,
  70. width:200
  71. },
  72. title: {
  73. },
  74. iconStyle: {
  75. fontSize: 18,
  76. opacity: 0.6,
  77. cursor: 'pointer'
  78. }
  79. })