SideBar.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. let ModuleSystem = this.CoreSystem.ModuleSystem;
  40. let Structure = {};
  41. if(tool){
  42. if(tool.selectedNode && tool.selectedNode.content && tool.selectedNode.content.value){
  43. this.viewNode = tool.selectedNode.content;
  44. // give ViewNode
  45. Structure = ModuleSystem.fromViewNode(this.viewNode).Inputs;
  46. console.log(Structure);
  47. }
  48. }
  49. let data = Object.keys(Structure || {}).map((key) => {
  50. return(
  51. <View style={SideBarStyle.body}>
  52. <Text>{key}</Text>
  53. {key === 'text' ? (
  54. <TextInput
  55. style={{height: 40, borderColor: 'gray', borderWidth: 1}}
  56. onChangeText={(text) => this.editNode(text, key)}
  57. value={this.viewNode.props[key]}
  58. />
  59. ):(null)}
  60. </View>
  61. )
  62. })
  63. return (
  64. <View style={SideBarStyle}>
  65. <Text style={SideBarStyle.title}>Side Bar</Text>
  66. {data}
  67. </View>
  68. )
  69. }
  70. }
  71. const SelectedStyle = StyleSheet.create({
  72. container:{
  73. padding:5,
  74. borderWidth:2,
  75. borderColor:'green'
  76. }
  77. })
  78. const SideBarStyle = StyleSheet.create({
  79. container:{
  80. padding:1,
  81. flex:1,
  82. flexDirection:'row'
  83. },
  84. title:{
  85. fontSize:20,
  86. textAlign:'center',
  87. fontFamily:'halvetica',
  88. color:'black',
  89. borderBottomWidth:1,
  90. borderBottomColor:'black'
  91. },
  92. body:{
  93. paddingLeft:5,
  94. paddingRight:5
  95. }
  96. })