SideBar.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. let {
  6. CoreSystem,
  7. ViewSystem,
  8. ViewNode
  9. } = Library;
  10. export default class SideBar{
  11. constructor(CoreSystem){
  12. this.CoreSystem = CoreSystem;
  13. }
  14. onUpdate(fn){
  15. this.__onUpdate = fn
  16. }
  17. forceUpdate(props){
  18. this.__onUpdate && this.__onUpdate(props);
  19. }
  20. switchTools(toolName){
  21. //will be a switch function
  22. }
  23. someFunction(){
  24. }
  25. getStyle(style) {
  26. if (typeof style === 'number') {
  27. return ReactNativePropRegistry.getByID(style);
  28. }
  29. return style;
  30. }
  31. editNode(text,key){
  32. console.log(text,key);
  33. this.viewNode.props[key] = text;
  34. this.forceUpdate();
  35. }
  36. //TODO Change everything :P
  37. render(){
  38. let tool = this.tool;
  39. console.log("@@@@@@@@@@@@@")
  40. console.log(tool)
  41. let ModuleSystem = this.CoreSystem.ModuleSystem;
  42. let Structure = {};
  43. if(tool){
  44. if(tool.selectedNode && tool.selectedNode.content && tool.selectedNode.content.value){
  45. this.viewNode = tool.selectedNode.content;
  46. // give ViewNode
  47. Structure = ModuleSystem.fromViewNode(this.viewNode).Inputs;
  48. console.log(Structure);
  49. }
  50. }
  51. let data = Object.keys(Structure || {}).map((key) => {
  52. return(
  53. <View style={SideBarStyle.body}>
  54. <Text>{key}</Text>
  55. {key === 'text' ? (
  56. <TextInput
  57. style={{height: 40, borderColor: 'gray', borderWidth: 1}}
  58. onChangeText={(text) => this.editNode(text, key)}
  59. value={this.viewNode.props[key]}
  60. />
  61. ):(null)}
  62. </View>
  63. )
  64. })
  65. return (
  66. <View style={SideBarStyle}>
  67. <Text style={SideBarStyle.title}>Side Bar</Text>
  68. {data}
  69. </View>
  70. )
  71. }
  72. }
  73. const SelectedStyle = StyleSheet.create({
  74. container:{
  75. padding:5,
  76. borderWidth:2,
  77. borderColor:'green'
  78. }
  79. })
  80. const SideBarStyle = StyleSheet.create({
  81. container:{
  82. padding:1,
  83. flex:1,
  84. flexDirection:'row'
  85. },
  86. title:{
  87. fontSize:20,
  88. textAlign:'center',
  89. fontFamily:'halvetica',
  90. color:'black',
  91. borderBottomWidth:1,
  92. borderBottomColor:'black'
  93. },
  94. body:{
  95. paddingLeft:5,
  96. paddingRight:5
  97. }
  98. })