Environment.js 4.6 KB

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