SideBar.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. let {
  7. CoreSystem,
  8. ViewSystem,
  9. ViewNode
  10. } = Library;
  11. export default class SideBar{
  12. constructor(CoreSystem){
  13. this.CoreSystem = CoreSystem;
  14. }
  15. onUpdate(fn){
  16. this.__onUpdate = fn
  17. }
  18. forceUpdate(props){
  19. this.__onUpdate && this.__onUpdate(props);
  20. }
  21. switchTools(toolName){
  22. //will be a switch function
  23. }
  24. someFunction(){
  25. }
  26. getStyle(style) {
  27. if (typeof style === 'number') {
  28. return ReactNativePropRegistry.getByID(style);
  29. }
  30. return style;
  31. }
  32. editNode(text,key){
  33. console.log(text,key);
  34. this.viewNode.props[key] = text;
  35. this.forceUpdate();
  36. }
  37. //TODO Change everything :P
  38. render(){
  39. let tool = this.tool;
  40. console.log("@@@@@@@@@@@@@")
  41. console.log(tool)
  42. let ModuleSystem = this.CoreSystem.ModuleSystem;
  43. let CurrentView = this.CoreSystem.getCurrentView();
  44. let Routing = this.CoreSystem.Routing;
  45. let Structure = {};
  46. if(tool){
  47. if(tool.selectedNode && tool.selectedNode.isCol)
  48. {
  49. this.ColNode = tool.selectedNode;
  50. this.RowNode = CurrentView.getParent(this.ColNode);
  51. console.log("ROWNODE" , this.RowNode);
  52. console.log("ColNode" , this.ColNode);
  53. console.log("viewNode" , this.viewNode);
  54. if(tool.selectedNode.content && tool.selectedNode.content.value){
  55. this.viewNode = tool.selectedNode.content;
  56. Structure = ModuleSystem.fromViewNode(this.viewNode).Inputs;
  57. }
  58. }
  59. }
  60. let data = Object.keys(Structure || {}).map((key) => {
  61. return(
  62. <View style={SideBarStyle.body}>
  63. <Text>{key}</Text>
  64. {key === 'text' ? (
  65. <TextInput
  66. style={{height: 40, borderColor: 'gray', borderWidth: 1}}
  67. onChangeText={(text) => this.editNode(text, key)}
  68. value={this.viewNode.props[key]}
  69. />
  70. ):(null)}
  71. </View>
  72. )
  73. })
  74. console.log("ROW NODE DATA DATA" , this.RowNode , this.RowNode && CurrentView.getColumns(this.RowNode).length);
  75. return (
  76. <View>
  77. <Text style={SideBarStyle.title}>Side Bar</Text>
  78. <View>
  79. <Text>Container style</Text>
  80. {this.RowNode && <View>
  81. <Text>Row</Text>
  82. <TextEditor title="Inner Columns"
  83. text={this.RowNode && CurrentView.getColumns(this.RowNode).length +''}
  84. onChange={(cols) => {
  85. console.log(cols, "COLS");
  86. CurrentView.setColumns(this.RowNode, parseInt(cols))
  87. this.forceUpdate();
  88. }}/>
  89. </View>}
  90. <View>
  91. <Text>Col</Text>
  92. </View>
  93. </View>
  94. {data}
  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 SideBarStyle = StyleSheet.create({
  107. container:{
  108. padding:1,
  109. flex:1,
  110. flexDirection:'row'
  111. },
  112. title:{
  113. fontSize:20,
  114. textAlign:'center',
  115. fontFamily:'halvetica',
  116. color:'black',
  117. borderBottomWidth:1,
  118. borderBottomColor:'black'
  119. },
  120. body:{
  121. paddingLeft:5,
  122. paddingRight:5
  123. }
  124. })