SideBar.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import React from 'react';
  2. import {StyleSheet, View, Text} from 'react-native';
  3. import Library from 'trapilib/dist/lib';
  4. import { TextInput } from 'react-native';
  5. import TextEditor from '../Components/TextEditor';
  6. // import Numbers from '../Components/Numbers';
  7. // import ColorEditor from '../Components/ColorEditor';
  8. import TypeHandler from '../Components/TypeHandler.js';
  9. let {
  10. CoreSystem,
  11. ViewSystem,
  12. ViewNode,
  13. DataTypes
  14. } = Library;
  15. export default class SideBar{
  16. constructor(CoreSystem){
  17. this.CoreSystem = CoreSystem;
  18. }
  19. onUpdate(fn){
  20. this.__onUpdate = fn
  21. }
  22. forceUpdate(props){
  23. this.__onUpdate && this.__onUpdate(props);
  24. }
  25. switchTools(toolName){
  26. //will be a switch function
  27. }
  28. someFunction(){
  29. }
  30. getStyle(style) {
  31. if (typeof style === 'number') {
  32. return ReactNativePropRegistry.getByID(style);
  33. }
  34. return style;
  35. }
  36. editNode(text,key){
  37. this.viewNode.props[key] = text;
  38. this.forceUpdate();
  39. }
  40. render(){
  41. console.log("DO I EVER COME HEREEEEEEE")
  42. let tool = this.tool;
  43. let ModuleSystem = this.CoreSystem.ModuleSystem;
  44. let CurrentView = this.CoreSystem.getCurrentView();
  45. let Routing = this.CoreSystem.Routing;
  46. let Structure = {};
  47. if (tool) {
  48. console.log(tool)
  49. if (tool.selectedNode && tool.selectedNode.isCol && CurrentView.has(tool.selectedNode)) {
  50. this.ColNode = tool.selectedNode;
  51. this.RowNode = CurrentView.getParent(this.ColNode);
  52. if(tool.selectedNode.content && tool.selectedNode.content.value) {
  53. this.viewNode = tool.selectedNode.content;
  54. console.log("NEVERRRRRRRRRRRRRRRR")
  55. Structure = ModuleSystem.fromViewNode(this.viewNode).Inputs;
  56. }
  57. }
  58. }
  59. let data = Object.keys(Structure || {}).map((key) => {
  60. let Editor = TypeHandler(Structure[key]);
  61. let editorProps = {
  62. title: key,
  63. onChange: (value) => this.editNode(value, key)
  64. };
  65. console.log(DataTypes)
  66. switch(Structure[key].type){
  67. case DataTypes.Types.Integer:
  68. editorProps.number = this.viewNode.props[key];
  69. break;
  70. case DataTypes.Types.Text:
  71. editorProps.text = this.viewNode.props[key];
  72. break;
  73. default:
  74. //Must create a generic Vuiew Component
  75. return (<View></View>)
  76. }
  77. return <Editor {...editorProps}/>
  78. })
  79. return (
  80. <View>
  81. <Text style={SideBarStyle.title}>Side Bar</Text>
  82. <View>
  83. <Text>Container style</Text>
  84. {this.RowNode && <View>
  85. <Text>Row</Text>
  86. <TextEditor title="Inner Columns"
  87. text={this.RowNode && CurrentView.getColumns(this.RowNode).length +''}
  88. onChange={(cols) => {
  89. CurrentView.setColumns(this.RowNode, parseInt(cols))
  90. this.forceUpdate();
  91. }}/>
  92. </View>}
  93. <View>
  94. <Text>Col</Text>
  95. </View>
  96. </View>
  97. <View style={PropertiesContainer.container}>
  98. {data}
  99. </View>
  100. </View>
  101. )
  102. }
  103. }
  104. const SelectedStyle = StyleSheet.create({
  105. container:{
  106. padding:5,
  107. borderWidth:2,
  108. borderColor:'green'
  109. }
  110. })
  111. const PropertiesContainer = StyleSheet.create({
  112. container:{
  113. marginTop:20,
  114. borderTopWidth:0.8,
  115. borderColor:'#D0D0D0'
  116. },
  117. child:{
  118. padding:10
  119. }
  120. })
  121. const SideBarStyle = StyleSheet.create({
  122. container:{
  123. padding:1,
  124. flex:1,
  125. flexDirection:'row'
  126. },
  127. title:{
  128. fontSize:20,
  129. textAlign:'center',
  130. fontFamily:'halvetica',
  131. color:'black',
  132. borderBottomWidth:1,
  133. borderBottomColor:'black'
  134. },
  135. body:{
  136. paddingLeft:5,
  137. paddingRight:5
  138. }
  139. })