Environment.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import React from 'react';
  2. import { Button , View, Text, StyleSheet } from 'react-native';
  3. import {Icon} from 'react-native-elements';
  4. import BaseSystem from './System';
  5. import {Node} from 'trapilib/dist/lib/systems/ViewSystem'
  6. export default class Environment extends BaseSystem {
  7. constructor(CS, ToolBox, phoneRef) {
  8. super()
  9. this.phoneRef = phoneRef;
  10. this.CoreSystem = CS;
  11. this.ToolBox = ToolBox;
  12. }
  13. addRow(){
  14. let View = this.CoreSystem.getCurrentView();
  15. let container = View.getDefaultContainer();
  16. let node = new Node(Math.random()+ Math.random(), {selected: true})
  17. console.log(node)
  18. View.addViewNode(node, container);
  19. this.forceUpdate();
  20. }
  21. selectRow(row) {
  22. this.ToolBox.selectNode(row);
  23. this.forceUpdate();
  24. }
  25. selectCol(col) {
  26. this.ToolBox.selectNode(col);
  27. this.forceUpdate();
  28. }
  29. rowHolders(Rows) {
  30. return Rows.map((row, index) => {
  31. let dom = '',
  32. ref = null;
  33. try {
  34. ref = this.CoreSystem.ModuleSystem.getRef(row.id);
  35. dom = ref.current._reactInternalFiber.child.child.stateNode;
  36. } catch(e) {}
  37. console.log("DOM", ref, dom,dom.clientHeight);
  38. return <View
  39. style={[{height: dom.clientHeight}, styles.rowHolderContainer]}
  40. onClick={(e) => this.selectRow(row)}>
  41. <View style={styles.rowHolder}>
  42. <Text style={styles.rowButton}>{index}</Text>
  43. </View>
  44. </View>;
  45. })
  46. }
  47. colHolders(Cols) {
  48. return Cols.map((col, index) => {
  49. let dom = '',
  50. ref = null;
  51. try {
  52. ref = this.CoreSystem.ModuleSystem.getRef(col.id);
  53. dom = ref.current._reactInternalFiber.child.child.stateNode;
  54. } catch(e) {}
  55. console.log("DOM", ref, dom,dom.clientHeight);
  56. return <View
  57. style={[{width: dom.clientWidth}, styles.colHolderContainer]}
  58. onClick={(e) => this.selectCol(col)}>
  59. <View style={styles.colHolder}>
  60. <Text style={styles.colButton}>{index}</Text>
  61. </View>
  62. </View>;
  63. })
  64. }
  65. render() {
  66. let CurrentView = this.CoreSystem.getCurrentView();
  67. let defaultContainer = CurrentView.getDefaultContainer();
  68. let Rows = []; //CurrentView.getRows(defaultContainer);
  69. let Cols = [];
  70. // Check if selection is Row or Col and find ROW to getColumns
  71. if(this.ToolBox.selectedNode){
  72. // let selectedRowNode = this.ToolBox.selectedNode.isRow ?
  73. // this.ToolBox.selectedNode :
  74. // CurrentView.getParent(this.ToolBox.selectedNode);
  75. // Cols = CurrentView.getColumns(selectedRowNode);
  76. }
  77. return <View style={styles.container}>
  78. <View style={styles.row}>
  79. </View>
  80. <View style={[styles.row, styles.colHolders]}>
  81. {
  82. //this.colHolders(Cols)
  83. }
  84. </View>
  85. <View style={styles.row}>
  86. <View style={[styles.col, styles.rowHolders]}>
  87. {
  88. //this.rowHolders(Rows)
  89. }
  90. </View>
  91. <div ref={this.phoneRef} style={{margin: 'auto'}}>
  92. <View style={[styles.mobileView]}>
  93. {this.CoreSystem.render()}
  94. </View>
  95. </div>
  96. </View>
  97. <View style={[styles.row,styles.button]}>
  98. <View style={{width:150,height:38,backgroundColor: "#F9F9F9",borderRadius:8,alignItems:'center',justifyContent:'center',marginTop:10 }}>
  99. <Icon name='add'
  100. color="#FFFFFF"
  101. containerStyle={{height:27,width:30,backgroundColor:'#36BBAD',borderRadius:22}}
  102. onPress={() => this.addRow()}
  103. />
  104. </View>
  105. </View>
  106. </View>
  107. }
  108. }
  109. const styles = StyleSheet.create({
  110. container: {
  111. flex: 1,
  112. flexDirection: "column"
  113. },
  114. mobileView: {
  115. backgroundColor: 'white',
  116. flex:1,
  117. alignSelf: 'stretch'
  118. },
  119. row: {
  120. flexDirection: "row",
  121. //borderWidth: 1
  122. },
  123. col: {
  124. flexDirection: "column",
  125. //borderWidth: 1
  126. },
  127. button:{
  128. flex:1,
  129. justifyContent:'center',
  130. },
  131. rowHolders: {
  132. padding:4
  133. },
  134. colHolders: {
  135. padding:4,
  136. justifyContent: 'flex-end'
  137. },
  138. rowHolderContainer: {
  139. justifyContent: 'center'
  140. },
  141. colHolderContainer: {
  142. justifyContent: 'center'
  143. },
  144. rowHolder: {
  145. height: 50,
  146. width:100,
  147. backgroundColor: 'green',
  148. textAlign: 'center'
  149. },
  150. colHolder: {
  151. width:100,
  152. height: 50,
  153. backgroundColor: 'purple',
  154. textAlign: 'center'
  155. }
  156. });