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. 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. borderWidth: 4,
  127. borderColor: 'orange',
  128. flex:1,
  129. alignSelf: 'stretch',
  130. // iphone X
  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. });