Environment.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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}>
  92. <View style={[styles.mobileView]}>
  93. {this.CoreSystem.render()}
  94. </View>
  95. </div>
  96. </View>
  97. <View style={[styles.row,styles.button]}>
  98. <Button
  99. color="#D2691E"
  100. onPress={() => this.addRow()}
  101. title={
  102. <Icon name='add'
  103. color="#606060"
  104. containerStyle={{height:10}}
  105. />}
  106. />
  107. </View>
  108. </View>
  109. }
  110. }
  111. const styles = StyleSheet.create({
  112. container: {
  113. flex: 1,
  114. flexDirection: "column"
  115. },
  116. mobileView: {
  117. backgroundColor: 'white',
  118. flex:1,
  119. alignSelf: 'stretch',
  120. width:375,
  121. height: 667
  122. },
  123. row: {
  124. flexDirection: "row",
  125. //borderWidth: 1
  126. },
  127. col: {
  128. flexDirection: "column",
  129. //borderWidth: 1
  130. },
  131. button:{
  132. flex:1,
  133. justifyContent:'center',
  134. },
  135. rowHolders: {
  136. padding:4
  137. },
  138. colHolders: {
  139. padding:4,
  140. justifyContent: 'flex-end'
  141. },
  142. rowHolderContainer: {
  143. justifyContent: 'center'
  144. },
  145. colHolderContainer: {
  146. justifyContent: 'center'
  147. },
  148. rowHolder: {
  149. height: 50,
  150. width:100,
  151. backgroundColor: 'green',
  152. textAlign: 'center'
  153. },
  154. colHolder: {
  155. width:100,
  156. height: 50,
  157. backgroundColor: 'purple',
  158. textAlign: 'center'
  159. }
  160. });