SideBar.js 3.4 KB

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