Environment.js 4.6 KB

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